News for hackers. Stuff that matters.
Re:We have C++14 by PopsiclePete on Monday August 18, 2014 @07:38PM (#8195280)
Too bad it's a mirage. No, really. "Modern C++" doesn't exist outside of blog posts, books, and tutorials.

Real-world C++ is an array of sometimes mututally-exclusive dialects, patterns, rules, sub-dialects.

Reading MFC is nothing like reading Qt which is nothing like WxWidgets which is nothing like Boost which is something (but not quite like) the STL which is way different from Apache C++ libs which is way different from what Google's C++ libraries are...

This is what happens when a language is "un-opinionated", throws everything including the kitchen sink at the language, tries to compile C and legacy C++ while introducing new features oh and also can't break existing code.

It's on its way out, no doubt about it. And we'll be better off as an industry for it, I'm sure of it.

Rust, Go, and others will be there to fill in the gap in a much better, saner, safer, maintainable way.

Re:We have C++14 by jonstewart on Monday August 18, 2014 @08:12PM (#8195385)
As a counterpoint, I write "Modern C++" for my job. I know several others who do, too. I'm overjoyed at how much the C++11 features have improved my code (and I'm still learning how to deploy them effectively), as well as how good the compiler support is.

MFC was the vilest, most horrible abuse of C++ from the day it was released. Anything that involves MFC should just be rewritten with C# or turned into a webapp. I wouldn't take a job that involved programming MFC.

Re:We have C++14 by _pmf_ on Tuesday August 19, 2014 @04:42AM (#8196458)
> MFC was the vilest, most horrible abuse of C++ from the day it was released.

MFC's greatest benefit was that it made returning to plain win32 C programming without MFC a pleasurable experience.

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @12:32PM (#8198245)
Funny thing is that MFC iw like that because of Win16/Win32 C developers.

Microsoft team made a prototype OO framework even more OO that what OWL and others offered. MFC was the result from the feedback over the said framework.

Re:We have C++14 by dicroce on Monday August 18, 2014 @08:29PM (#8195442)
Me too. RAII ftw!
Re:We have C++14 by sillysaurus3 on Monday August 18, 2014 @08:42PM (#8195486)
Good luck making your RAII class exception safe. It's extremely difficult, to the point that writing a simple class becomes an hours-long exercise in reasoning about exceptions.

And of course, if you admit that exceptions aren't worth worrying about, then you'll start to question the entire "C++ way," which usually ends in disillusionment.

Alternatively, instead of disillusionment, you may still kind of enjoy C++. But suddenly you find that it's been three years since you've worked with C++, and on reflection, you haven't really been missing out on much of anything at all by not using C++.

It doesn't seem like C++ solves the right problems, even with the new dialects. Programming languages should be convenient to think in. By immersing yourself in the C++ mental model, it becomes difficult to keep a large-scale architecture entirely in your head.

Re:We have C++14 by eropple on Monday August 18, 2014 @11:00PM (#8195864)
> Good luck making your RAII class exception safe. It's extremely difficult, to the point that writing a simple class becomes an hours-long exercise in reasoning about exceptions.

In my experience, this is literally backwards. RAII is the only way to make exception-safe classes that aren't a gigantic mess.

> It doesn't seem like C++ solves the right problems, even with the new dialects. Programming languages should be convenient to think in.

No, some progrmaming languages should be convenient to think in. Some need to be uncompromisingly fast. C++ is in the latter set and nothing more convenient to think in is faster.

Re:We have C++14 by halfcat on Monday August 18, 2014 @11:32PM (#8195932)
>Some need to be uncompromisingly fast. C++ is in the latter set and nothing more convenient to think in is faster.

Yes, and C++11/14 make significant strides toward being more convenient to think in as well, without compromising speed. In fact some improvements also improve speed in some cases.

Re:We have C++14 by sillysaurus3 on Tuesday August 19, 2014 @12:18AM (#8196001)
Yes, RAII is the only way to make an exception-safe class. Good luck doing it. It's not easy. I know; I've tried. There are all kinds of corner cases and special considerations that you have to take into account. People have written huge tomes about that exact topic detailing exactly why it's a hard problem and why you're probably not going to solve it correctly by accident. You're far more likely to introduce a memory leak than to make your class exception safe on the first try. That's my point. That's why C++ is overly cumbersome unless you ignore most of its capabilities, like exceptions. And that's why you can simply ignore C++ and not miss out on much. If performance is your only reason for rigorously sticking to a mental model, it's likely that your mental model is a premature optimization.
Re:We have C++14 by chetanahuja on Tuesday August 19, 2014 @04:02AM (#8196364)
"Good luck doing it. It's not easy. I know; I've tried" Completely unsupported assertion (no pun) without evidence. Other people have tried it, and have succeeded. I could start listing all the software written in C++ that you use in your everyday life, perhaps 100's of times a day... but that'll quickly exhaust my word limit for this post.

"That's why C++ is overly cumbersome unless you ignore most of its capabilities, like exceptions."

Complete non sequitur. Exceptions are not "most of C++ capabilities". In fact, you can refuse to catch or throw exceptions for 99% of your (millions of lines) of code and still end up with a very large, stable code base running a large portion of the internet. Ask Google.

Today, there's pretty much no viable alternative to C++ for writing large scale, high performance systems with reliable performance guarantees. You could do it in C if you have a religious anti-C++ agenda but that would be like cutting off your nose to spite your face, and you'll end up in a horrible mish-mash of macros and generated code all over the place for a project with any level of complexity. Rust or D might get there some day if they manage to attract a solid community and big corporate backing. But they are certainly not there yet.

Re:We have C++14 by vog on Tuesday August 19, 2014 @08:33AM (#8196954)
> Exceptions are not "most of C++ capabilities".

To add to this point: There are C++ frameworks such as Qt who don't use exceptions at all! And what impressed most: When writing a Qt application, you don't even miss exceptions. You don't have to resort to C-style return value checking all over your code. How is that? It took me some time to figure this out, but I believe it is because Qt applies the "Null Object" pattern consequently - down to the deepest depth of their framework,

Re:We have C++14 by wfunction on Tuesday August 19, 2014 @01:44PM (#8198706)
Actually that statement has a point. Have you ever tried implementing std::vector and java.util.ArrayList and comparing the two implementations? One of them is trivial, the other one is most certainly not. One of the reasons is exception-safety guarantees. I'll leave it for you to figure out which is which.
Re:We have C++14 by lmm on Tuesday August 19, 2014 @07:51AM (#8196839)
> you can refuse to catch or throw exceptions for 99% of your (millions of lines) of code and still end up with a very large, stable code base running a large portion of the internet.

The point is that these features are infectious. If you don't want to throw exceptions, how do you handle a failure in a constructor? And then if you abandon constructors, other C++ features are unusable without them. And so on.

Re:We have C++14 by rozim on Wednesday August 20, 2014 @01:37AM (#8201211)
Googler here. We avoid doing "work" in constructors as per the style guide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.x...
Re:We have C++14 by lmm on Wednesday August 20, 2014 @04:39AM (#8201543)
Yeah, that's pretty much what you have to do, and go back to a C-style init method. But then you've lost the benefits of RAII, and you can't necessarily use those types with templates (which won't know about your init method).
Re:We have C++14 by sillysaurus3 on Tuesday August 19, 2014 @10:10AM (#8197339)
You could do it in C if you have a religious anti-C++ agenda but that would be like cutting off your nose to spite your face, and you'll end up in a horrible mish-mash of macros and generated code all over the place for a project with any level of complexity.

Have a look at Tarsnap's source code.

Re:We have C++14 by jonstewart on Tuesday August 19, 2014 @02:18AM (#8196195)
What were these corner cases and special considerations you ran into?

I wouldn't call Herb Sutter's _Exceptional C++_ a huge tome and it seems to be the standard treatment of exception safety.

Re:We have C++14 by sillysaurus3 on Tuesday August 19, 2014 @11:55AM (#8198002)
It's 240 pages of knowledge that you can completely do without, and it's a book called "47 engineering puzzles." The puzzles, of course, are entirely exception-related.

I'm not saying it's impossible to write exception safe code. I'm saying that you can write code without exceptions without being worse off for it.

Re:We have C++14 by jonstewart on Tuesday August 19, 2014 @09:21PM (#8200704)
We're talking about the same book, _Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions_, by Herb Sutter. The takeaway I had from reading that book (a long time ago) was just to use RAII religiously, which also tends to make other things easier.

So I'm curious about why you think RAII makes writing exception-safe code difficult?

Re:We have C++14 by sillysaurus3 on Tuesday August 19, 2014 @10:36PM (#8200862)
Sorry for the confusion. I meant that writing exception-safe code is difficult, not that RAII makes it difficult to write exception-safe code. I should have been clearer about that.

The book is excellent. For anyone who wants to use C++ exceptions, it should be required reading. But as someone who has gone through that gauntlet, I feel that I probably would've been better served by spending my time on something other than mastering the finer points of exceptions.

The reason I started talking about C++ exceptions in the first place is because, in my experience, when someone is very pro-RAII (like the original commenter I responded to), they also tend to be pro-exceptions. This isn't always true, but on average, it seems like either people prefer both or prefer neither.

Writing exception-safe code is certainly one of the hardest challenges available in C++, so if you enjoy a good challenge, then it's hard to do better. But if you're just looking to design large-scale systems, it seems like exceptions are unnecessary, as Google has demonstrated by banning the use of exceptions in their codebases.

In my experience, by refraining from using exceptions, it's possible to design large codebases more quickly, with fewer bugs, and without losing any safety or extensibility. However, this is simply my personal experience, and it may be mistaken to generalize this into a claim that all codebases among all C++ teams should refrain from using exceptions.

So, that's all I meant. I was also in excruciating pain yesterday due to a certain tooth that decided to segfault in my mouth, which may have contributed to the adversarial nature of my writing style. I feel bad about how I came across, and I sincerely apologize for it. No excuses, though: I should've done better.

Re:We have C++14 by cubbimew on Wednesday August 20, 2014 @09:08AM (#8202158)
> either people prefer both or prefer neither.

exceptions (specifically, exceptions from constructors) are part of what RAII is, so it's only natural that people "prefer both".

As another personal anecdote, in my experience working with a large (175MLoC at last count) mostly-C++ codebase, I can't imagine how painful it would have been if the code didn't use exceptions.

Re:We have C++14 by prodigal_erik on Thursday August 21, 2014 @05:44AM (#8206572)
Their style guide http://google-styleguide.googlecode.com/svn/trunk/cppguide.x... is sheepish about it. The authors seem to believe using exceptions would have been better, except they found themselves beyond a critical mass of bad code that would fail or leak on a throw, and now they can't fix it all or throw it away.

I can't understand how a correct init method could be easier to write than a ctor, given that the compiler is required to generate code that knows which of your base classes and fields are already initialized at any point they could fail, which you would have to do yourself after moving to an init method, as well as losing the guarantee you can't silently ignore an error by forgetting to check for it.

Re:We have C++14 by jonstewart on Monday August 18, 2014 @09:48PM (#8195684)
Huh? RAII is basically the only way to write exception-safe code in C++.
Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @03:14AM (#8196283)
> But suddenly you find that it's been three years since you've worked with C++, and on reflection, you haven't really been missing out on much of anything at all by not using C++.

True on my case, now using the language mainly on hobby projects, although we are very good friends since 1993.

Personally I would like safer systems programming languages from Mesa branch of languages had more use in the industry, but OS vendors decided to embrace C instead, and we ended up in the exploits everywhere that we enjoy nowadays.

C++ is not perfect, but it surely is way better than C in terms of safety.

Until a big OS vendor decides to push another systems programming language, we won't see any major adoption from the alternatives.

Re:We have C++14 by eps on Tuesday August 19, 2014 @03:55AM (#8196351)
RAII is hardly a trait of modern C++.
Re:We have C++14 by leoc on Tuesday August 19, 2014 @08:47AM (#8197000)
Is your meaning that it's not a distinctive trait of modern C++?
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @04:15AM (#8196392)
Eh? How do you mean that?
Re:We have C++14 by vidarh on Tuesday August 19, 2014 @04:25AM (#8196415)
Presumably that it's nothing new. The term RAII dates to the mid to late 80's sometime, and you could hardly find any book about C++ from the 90's onwards that wouldn't be espousing RAII as the One True Way.

RAII has been with C++ almost from the beginning.

Re:We have C++14 by deong on Tuesday August 19, 2014 @09:26AM (#8197112)
Yes, but "modern" doesn't imply that no feature is older than Twitter. "Modern C++" refers to the way that C++ is written today, and some of that is new additions to the language, some has been there for ages.
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @04:18AM (#8196399)
I have furniture at home made of wood. Oddly, my table looks nothing like my broom handle, so does this mean that wood is a terrible choice for both items? "The industry would be better off without wood!!"

Surely libraries in other languages have the same problem? They don't look anything like each other.

wxWidgets and Qt look nothing like each other but it isn't a problem at all. The signalling mechanism / event handling between the two just hides function pointers, so it isn't a headache. In fact, MFC looks like wxWidgets to me. Not sure what the problem is?

EDIT: Not sure why the downvote(s)? Do people get downvoted here because someone points something out that is true on a subject/language that they like/dislike? Or was it the tone or supposed tone that the person read the comment in? Please let me know!

Re:We have C++14 by kelvin0 on Tuesday August 19, 2014 @08:13AM (#8196897)
It`s the down vote pigeon, hitting randomly and savagely.
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @08:43AM (#8196988)
Sure is a vicious beast! Must have got into a bit of a flap. Pigeons have tiny brains don't they?
Re:We have C++14 by abdulhaq on Tuesday August 19, 2014 @01:48PM (#8198740)
Forget about the downvotes, if you're not trolling then know they are a red herring.
Re:We have C++14 by Iftheshoefits on Monday August 18, 2014 @08:32PM (#8195454)
People have been saying this about C and C++ for decades. Not to say C++ will always be "on top", or even that it currently is, but your comment isn't really substantive or persuasive that "it's on its way out."

I'm also not convinced that Rust or Go are better or saner.

Re:We have C++14 by beefsack on Monday August 18, 2014 @09:06PM (#8195568)
I can understand the few controversial design choices in Go which limit it's use cases, but would be interested to hear why you claim Rust isn't saner than C++.
Re:We have C++14 by Pacabel on Monday August 18, 2014 @10:08PM (#8195715)
When it comes to Rust, there's no stable version of the language at this point. There's no stable version of the standard libraries. There's no reliable production-grade compiler available. As the Rust home page itself states, "Rust is a work-in-progress and may do anything it likes up to and including eating your laundry."

Maybe Rust will offer such stability in the future. But that's of no use to people and organizations who need to develop software today, and who need to be able to trust that the code they write now will compile and work tomorrow, a month from now, a year from now, and perhaps even decades from now.

C++ does offer stable, standardized, well-supported versions of the language. C++ does offer stable, standardized, well-supported standard libraries. There are numerous high-quality free and commercial C++ implementations available, for just about every platform imaginable. It provides a robust and predictable platform that serious and massive software systems can be built upon.

The theoretical benefits that Rust may bring are pretty much irrelevant as long as it isn't a production-ready language in the way that C++ is.

Re:We have C++14 by zxcdw on Monday August 18, 2014 @11:41PM (#8195949)
But now you aren't talking about Rust the Language but Rust the Ecosystem.

Not that I am disagreeing with your points, I am not. However, when people talk about C++'s problems, I immediately assume they talk about C++'s problems as a language rather than it's ecosysem.

Rust isn't out there to tackle C++'s ecosystem, tooling, legacy code or professional workforce, but rather Rust aims somewhere near C++ and fixes many of the language flaws which are inherent in C and C++, while still being competitive in performance and low-level control.

Re:We have C++14 by CountSessine on Tuesday August 19, 2014 @12:50AM (#8196060)
Ecosystem really is the whole problem, though. You can never make it big without having lots of friends.

Rust is a pretty cool language, but I can't help being reminded about another very well-designed but ultimately unsuccessful C++ challenger, D. The parallels are really hard to ignore.

D, like Rust, had great syntax and was a breath of fresh air after coding with C++98. Neither Rust not D has a sponsor with really deep pockets to encourage adoption. Neither came out of a standards process. Both have had compiler and standard library issues. The big difference between the two at this point seems to be momentum and where the two are in their parabolic trajectories.

Re:We have C++14 by danieldk on Tuesday August 19, 2014 @01:23AM (#8196115)
There are important differences: D threw away one of the most important features of C/C++ (for the target audience): usability of the language without a garbage collector.

Also, Mozilla has much deeper pockets than Digital Mars.

Still I agree with you that it is very likely that Rust will follow a parabolic trajectory. The advantages as perceived by the industry compared with C++11/14 will be too few. At the same time it does not have the ecosystem.

Go succeeded because of Google's deep pockets and, perhaps more importantly, because it filled a large niche that even the authors did not anticipate: a faster language for Python and Ruby aficionados.

Re:We have C++14 by pcwalton on Tuesday August 19, 2014 @02:45AM (#8196238)
> Still I agree with you that it is very likely that Rust will follow a parabolic trajectory. The advantages as perceived by the industry compared with C++11/14 will be too few.

Rust is memory- and type-safe (as in: the compiler will not let you write a dangling reference, invalidate an iterator, or write exception-unsafe code without opting into an unsafe dialect). The security benefits alone of that are enough to justify the language for our use cases, and, from what we've seen, for many others. Safe zero-cost abstractions are a niche to its own.

Re:We have C++14 by eco on Tuesday August 19, 2014 @01:30PM (#8198628)
Could you be specific about what in D isn't useable without the GC? You can use manual memory management in D. It has Unique (unique_ptr) and RefCounted (shared_ptr). It has Array. It has malloc and free. None of these use the GC.

People complain about the GC being available to use while simultaneously complaining that to avoid it you have to manage your memory yourself. You can't have it both ways. There is no memory allocation strategy that works best in every situation. Sometimes ref counting is best, sometimes stack allocation, sometimes RAII, sometimes memory pools, sometimes its the GC.

Rust has done some cool work with memory but even it doesn't free the programmer from having to consider and choose which memory allocation/ownership option is going to deliver the best performance on a case-by-case basis.

You're right about Rust and Go having much deeper pockets. D isn't backed by any corporation. It's 100% a community project. Maybe it won't ever gain a significant market share because of this. I don't know.

Re:We have C++14 by infinite8s on Wednesday August 20, 2014 @06:26AM (#8201760)
It took python (which also doesn't have a deep-pocketed company backing it) about 15-20 years before it saw widespread adoption.
Re:We have C++14 by deong on Tuesday August 19, 2014 @09:43AM (#8197191)
I would also say that D did itself irreparable harm with the whole v1-v2 standard library debacle. Right when it was receiving the most attention, it came right out and said to anyone who might have considered it, "we have two incompatible versions of the standard library: one which we don't support anymore and one you can't use yet."
Re:We have C++14 by eco on Tuesday August 19, 2014 @01:48PM (#8198735)
Yeah, that certainly hurt D's reputation. People still bring it up even though it's been resolved for years.
Re:We have C++14 by abdulhaq on Tuesday August 19, 2014 @01:47PM (#8198729)
That was then and this is now, there is one standard library and the language has come on leaps and bounds. D is a great language.
Re:We have C++14 by deong on Tuesday August 19, 2014 @09:48PM (#8200764)
I'm not arguing otherwise. But as the saying goes, you only get one chance to make a first impression, and D's first impression was of a train wreck.
Re:We have C++14 by jnbiche on Tuesday August 19, 2014 @07:37AM (#8196806)
>At the same time it [Rust] does not have the ecosystem

Try watching new projects pop up at Rust CI [0] for a few days. With the possible exception of Node (which is not even a PL), I've never seen a language ecosystem grow this vast, and I'm a PL afficionado.

I think in a year's time, the question of Rust's stability and ecosystem will be entirely moot. It's a tough wait meanwhile, but I'm still investing the time in learning Rust (and it's a significant investment).

0. http://www.rust-ci.org/projects/

Re:We have C++14 by Pacabel on Tuesday August 19, 2014 @08:06AM (#8196874)
Is Rust CI really the best evidence to use in this case?

When I last looked at it, probably 40% to 50% of the projects listed had builds that were in the "failing" or "error" statuses.

That indicates that one or more of at least a few things are happening:

1. The Rust language and its standard libraries are changing at a pace that results in previously-compiling code needing to be modified before it will compile again with a newer version of the language/implementation, perhaps a very short time after the code was initially written.

2. The Rust compiler or other tooling is crashing or failing in some way while compiling these projects.

3. The projects themselves aren't being maintained on an ongoing basis.

4. The projects themselves were never building properly in the first place.

5. The projects' developers are targeting different versions of Rust (which probably means there will be interoperability problems for anyone trying to use them in a larger projects, especially when it comes to libraries).

And while there may be a lot of these projects, I've never found the quality to be very good. Many of them are extremely limited or incomplete. Many of them are little more than casual experimentation. Many of them are only developed by a single person, who often has appeared to have lost interest.

Those factors are disconcerting, especially for somebody who wants to use Rust for serious product development. It does no good if there are hundreds of libraries available for use, but half of them don't even build, and the ones that do are very incomplete.

Re:We have C++14 by jnbiche on Tuesday August 19, 2014 @09:09AM (#8197059)
>Many of them are extremely limited or incomplete. Many of them are little more than casual experimentation. Many of them are only developed by a single person, who often has appeared to have lost interest.

Yes, I completely agree, and this is an entirely normal part of the language ecosystem development cycle. Rust is at the tail end of the experimentation stage, and as it converges on 1.0, more people will undertake serious projects.

I'm not at all worried about the quality of Rust projects. I'm just happy to see so much enthusiasm. I have no doubt that all this enthusiasm will transfer into some powerful libraries as Rust continues to stabilize and reaches 1.0.

But yes, it's still to early to use Rust for production unless you're willing and able to write your own libraries.

Then again, the "batteries included" approach of Rust's standard library leaves not much to be desired outside of domain-specific libraries.

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @02:37AM (#8196229)
Given the Mesa/Cedar system a Xerox PARC, Oberon at Swiss Federal Institute of Technology and Modula-3/SPIN at Olivetti, doing OS work in GC enabled systems programming languages is quite possible.

The problem is how to move OS vendors away from C's influence.

Re:We have C++14 by fithisux on Tuesday August 19, 2014 @09:07AM (#8197055)
Use micro-kernels.
Re:We have C++14 by loup-vaillant on Tuesday August 19, 2014 @09:53AM (#8197238)
Exo-kernels might be a better alternative.

https://en.wikipedia.org/wiki/Exokernel

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @10:13AM (#8197351)
It is a matter of willingness, not technology.
Re:We have C++14 by Zardoz84 on Tuesday August 19, 2014 @06:45AM (#8196694)
Facebook have deep pockets ... Yep, Facebook is using D for some stuff.
Re:We have C++14 by Pacabel on Tuesday August 19, 2014 @08:19AM (#8196919)
A large or well-known company merely using a programming language, and maybe even contributing back to it and its community, isn't the same as the company truly supporting or championing it.

What you describe is very different from, say, how Sun pushed Java, or Microsoft pushed C#, or how Apple will likely push Swift, or how a huge portion of the entire software industry pushed C and C++.

Facebook's Hack language is probably a much better example than D is of a language that they're actively supporting. It's a creation of theirs, rather than just a creation of somebody else's that they find useful in some limited cases.

Re:We have C++14 by pcwalton on Tuesday August 19, 2014 @02:49AM (#8196247)
> Both have had compiler and standard library issues.

What are the compiler/standard library issues with Rust? Sure, it's taken time to get to a high level of quality, but no language compiler and library is going to spring out of thin air fully complete. In particular, I'm confident that the Rust compiler is of high quality for its age, especially in the quality of the generated code.

Re:We have C++14 by LeonidasXIV on Tuesday August 19, 2014 @07:25AM (#8196775)
> In particular, I'm confident that the Rust compiler is of high quality for its age

I'd like to concur. I've used the Rust 0.10 compiler and the only bug I encountered was that generating debug binaries was somehow broken. Apart from that, it was one of the smoothest experiences ever and the error messages are amazing.

Re:We have C++14 by jnbiche on Tuesday August 19, 2014 @07:40AM (#8196812)
Rust error messages are perhaps the best thing about the compiler. For me, it's a new experience altogether. Instead of having to Google obscure error messages, Rust error messages actually tell me how to solve the problem!
Re:We have C++14 by EpicEng on Tuesday August 19, 2014 @12:50AM (#8196061)
I don't think that the two can be separated in any meaningful way. Of course they're different things, and we can discuss each on their own, but when it comes to which language to use as a business decision then the line becomes blurred if not completely transparent.
Re:We have C++14 by stormbrew on Tuesday August 19, 2014 @03:04AM (#8196268)
Rust is really the only language that's actually targeting the same niche as C++ primarily occupies, system level programming where reasoning about memory management and performance is part of the actual work being done. Go, let alone others, simply do not allow you to do this.

It shows a distinct lack of understanding of why people still use C or C++ to raise languages/environments like Go as viable alternatives.

Re:We have C++14 by PaulFreund on Tuesday August 19, 2014 @04:37AM (#8196450)
Don't forget D
Re:We have C++14 by jnbiche on Tuesday August 19, 2014 @07:32AM (#8196793)
D is fine language and a pleasure to program in, but with it's required garbage collector, it's not really in the same niche as C/C++/Rust. I think the hallmark of this niche is the ability to run without a garbage collector penalty and the accompanying lack of determinism.
Re:We have C++14 by fithisux on Tuesday August 19, 2014 @09:06AM (#8197048)
Oh not again the GC argument.

D is the one true C++ without pretending being a superset of C. Rust is more modern than C++ and better in programming in the large. But D is really for low level programming and a good target for code generation. For me it is a good replacement for C++ and Delphi. It is even a good fit for areas touched by Java and C# like desktop and scientific apps. But it is not there yet because of lack of serious tooling and lack of bytecode but for the second disadvantage you earn performance. Nimrod for example could address this (with D as a code generation target).

Re:We have C++14 by eco on Tuesday August 19, 2014 @12:58PM (#8198417)
You can use D without using the GC. I'm not sure why this myth keeps coming up. It's always supported manual memory management. You have to sacrifice some language features that aren't even available in C++ and some parts of the standard library use the GC but that is easy to avoid with yesterday's 2.066 release and the @nogc attribute. 2.067 should also have a lot of the standard library switched to using lazy algorithms where possible which means the caller gets to determine the allocation strategy (and can often avoid allocation entirely).

void main() @nogc { /* ... */ } // this program doesn't use the GC

Re:We have C++14 by loup-vaillant on Tuesday August 19, 2014 @09:45AM (#8197199)
Ordinary C++ with good old RAII do use something akin to garbage collection: many classes, when constructed, allocate memory on the heap, then free that memory when they fall out of scope.

Malloc() and free() aren't exactly predictable. If you really want guarantees, you need to write your own custom allocator, and if you don't need those guarantees, garbage collection is probably enough for your purposes.

Basically, if you're using C++ without real manual management, with custom allocators, pools, and all, you probably didn't need C++ in the first place.

Re:We have C++14 by stormbrew on Thursday August 21, 2014 @02:12AM (#8206105)
RAII is a form of automatic resource management, it's true. It is, however, a deterministic form of automatic resource management.

This is not to say that the underlying allocator is necessarily deterministic, but you're making a false dilemma here by putting it in opposition to making decisions about custom allocators and pool allocators. You can use RAII with custom allocators. You can use RAII with memory pools.

And that's where C++ really does shine. It's a niche that hasn't even really been attempted much, let alone that it's been surpassed in.

Re:We have C++14 by Cyther606 on Tuesday August 19, 2014 @09:56AM (#8197255)
With Nimrod, you can manage your own memory, or use the Boehm GC. It compiles to C/C++ with native code generation not dependent on a VM, and the Pythonic syntax makes writing such code as easy as common scripting languages [1].

1: https://github.com/def-/nimrod-unsorted

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @12:35PM (#8198277)
You mean like Mesa/Cedar at Xerox PARC, Oberon at ETHZ, Modula-3 at Olivetti...
Re:We have C++14 by davvid on Monday August 18, 2014 @10:48PM (#8195819)
Too bad it's a mirage

I hate to spoil your worldview, but modern C++ is very alive and well in the scientific computing communities. Disney Animation implemented a new renderer using it, and our next movie is currently being rendered using the new renderer, so I highly doubt it's on its way out in the these areas.

Re:We have C++14 by rootbear on Tuesday August 19, 2014 @12:11PM (#8198097)
Is this a replacement for RenderMan? Interesting...
Re:We have C++14 by fithisux on Tuesday August 19, 2014 @09:13AM (#8197069)
How much time/money did it take to be implemented? What is the maintenance cost? Which version of C++? What percentage was written from scratch? Does it run in a networked environment? These are the real questions.

Pharao Inc. built pyramids in ancient Egypt. It cost many lives of slaves but it was cheap them. Nowadays we make big buildings without slaves.

Re:We have C++14 by Tloewald on Tuesday August 19, 2014 @10:03AM (#8197299)
It's not like C++ programmers are poorly paid.

And hey, don't knock the Pharaohs!

First off, it's been known for some time that the Pyramids were built by paid workers:

http://www.boston.com/news/world/middleeast/articles/2010/01...

(Literate too, since they left graffiti)

http://www.bbc.co.uk/history/ancient/egyptians/pyramid_build...

The conditions that migrant workers endure building World Cup facilities in Qatar seem to be worse than those endured by Egyptian construction workers:

http://www.theguardian.com/world/2014/may/14/qatar-admits-de...

Re:We have C++14 by enraged_camel on Monday August 18, 2014 @11:47PM (#8195962)
I don't see how that refutes the parent's comment. The areas you listed are very small niches. Frankly, very few people care about scientific computing or even animation rendering. Generally speaking, using C++ is like wearing jeans and white sneakers: popular in the 90s, but definitely out of fashion now.
Re:We have C++14 by EpicEng on Tuesday August 19, 2014 @12:52AM (#8196065)
Exactly. It is out of fashion, but fashion is fleeting. Fashion is a twenty year old wearing skinny jeans; style is James Bond in a Tuxedo, and it's timeless. What's in fashion today may very well be out of fashion tomorrow. I will likely still be writing C++ to get shit done.
Re:We have C++14 by CountSessine on Tuesday August 19, 2014 @12:42AM (#8196048)
Oh goodness - C++ is out of fashion? But I was so productive! And my code ran so fast! Well, I guess I should go read up on node.lang or er-rust, or whatever it is those kids are into...
Re:We have C++14 by bstamour on Tuesday August 19, 2014 @09:27AM (#8197115)
Very few people care about any kind of computing - they care about the end result. Between embedded systems, servers and systems programs, and infrastructure, the modern world basically runs on C and C++.
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @04:19AM (#8196400)
Why do you need to be fashionable to be productive? Do people really ask what your finished software product is written in?
Re:We have C++14 by sumsumne on Wednesday August 20, 2014 @06:07AM (#8201734)
Whats your problem?
Re:We have C++14 by EpicEng on Monday August 18, 2014 @11:53PM (#8195975)
So "Modern C++" is a mirage, but Rust and Go are the surefire winners? Do you have any substance to add to your post?

I don't know, I've been writing C++ for about a decade and the code I write is "modern" as far as I can tell. I just started a new project. It is C++, it is "modern", and Rust and Go simply aren't options.

Rust is an infant and not yet ready for prime time, and Go simply wouldn't be considered by management. Not because they're ignorant, out of date curmudgeons, but because they want a larger pool of talent to draw upon and a language that is well known, well understood, and has decades of work invested around tooling. I can't say that I blame them.

Re:We have C++14 by loup-vaillant on Tuesday August 19, 2014 @10:07AM (#8197316)
Why do people keep assuming that they need an X programmer, or a Y programmer? Go is a garbage collected imperative and OO language, right? It's not like Java and C++ programmers wouldn't be able to learn the basics in 3 days, and be proficient in a couple weeks.

Why does the "pool of talent" even matters?

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @12:38PM (#8198292)
Companies don't want to pay for training.
Re:We have C++14 by yohanatan on Wednesday August 20, 2014 @03:41AM (#8201432)
So don't publicize the fact that you are 'learning' while you 'practice'. Just show the end result and it will likely be better than their language 'experts' could have done in any comparable [or infinite] time frame.
Re:We have C++14 by loup-vaillant on Tuesday August 19, 2014 @12:49PM (#8198362)
Not even 4 weeks worth of semi-productive self-learning? That sounds quite pathetic.

There must be something else, like fear of the unknown, risk aversion, "nobody got fired for choosing IBM"…

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @12:56PM (#8198411)
I know consulting companies that bill the customer the hours developers spend getting up to speed with a given technology.

In the cases the customer is not willing to pay, developers get asked to learn off work hours, if they want to stay on the project.

Re:We have C++14 by loup-vaillant on Tuesday August 19, 2014 @06:30PM (#8200176)
Now this is just abusive. I understand that as an individual I have to live with this, but collectively, it looks like we should rise up.
Re:We have C++14 by Mister_Snuggles on Monday August 18, 2014 @10:48PM (#8195817)
I think you could say the same thing about any language where there are big frameworks and libraries that handle a lot for you.

In the Java world, a Java EE CRUD application is a LOT different than a Swing application that does the same thing. Likewise, a Python Django application is a completely different beast than a console application.

Re:We have C++14 by danieldk on Tuesday August 19, 2014 @01:31AM (#8196121)
But there is less variation: Java provides only one paradigm (OO) and frameworks use different flavors of that: beans, POJOs, heavy classes, etc.

In C++ you can have such variations, plus all the other paradigms, including:

* C with classes (people programming in this style often still use C strings, do deletes and frees in destructors).

* C++ as the full-blown OOP language, with extensive multiple inheritance hierarchies.

* Nearly functional, STL-driven C++. In this code you see nearly no loops at all, <algorithm> is the control structure.

* Template-driven programming, with policy classes, dozens of specializations, only header files.

Etc. Java does not have the legacy to 'embed' another language. Java does not do multiple inheritance, avoiding heavy-inheritance-based projects, Java does not claim to be a semi-functional language (though Java 8 brings Java closer in that direction), and Java does not provide a turing-complete template language that is a world on its own.

Re:We have C++14 by Vaskivo on Tuesday August 19, 2014 @07:15AM (#8196750)
That's the problem I have with C++. It is a mish-mash of paradigms, features and techniques. It is not consistent in use-cases and philosophy (unless you count "all and everything" as use cases and philosophy).

As much as I try to find "my" general purpose language of choice, and forr all of my inertia in learning yet another programming language, I believe languages should have narrower scopes. And there should be more languages. Specialized for specific use-cases.

And, as a pythonista, the "you can do/use it in many different ways" just irks me.

Re:We have C++14 by jonstewart on Tuesday August 19, 2014 @08:32AM (#8196951)
One core part of C++'s philosophy where it's very consistent is that you only pay for what you use and the performance guarantees (e.g., STL) are explicit.

Another consistent part of C++ is that it gives you absolute control over memory, both allocation and layout. It's really this control that makes C++ unbeatable in performance. The good VMs can JIT their languages to match CPU performance on small routines, but they can't match C++ when it comes to manipulating big, complicated data structures.

Re:We have C++14 by lmm on Tuesday August 19, 2014 @07:56AM (#8196847)
I thought much like that (and was a huge Python fan) until I found Scala. There are cases people cite as "more than one way to do it", but they're usually superficial syntax differences. You do have to choose between passing around objects and passing around functions, but that's a choice you make in Python as well. It can handle high-performance calculation or high-level scripting, but it never feels like these are separate languages; it has a bunch of orthogonal features but any two of them combine in exactly the way you would expect (and often that combination forms something very useful).
Re:We have C++14 by danieldk on Tuesday August 19, 2014 @02:11PM (#8198863)
Scala is different than C++ in the sense that Scala at its core is a simple language compared to C++ and most abstractions are built from that. That said, there are different Scalas to, Scala the 'a better Java' is a very different language from scalaz/shapeless Scala.

This seems to be the curse of any powerful core language (Scala, Haskell, ...) - on the one hand they allow you to make all kinds of useful abstractions that you can't make with e.g. Java. On the other hand, their abstractions are so powerful that they create seemingly different languages.

One could apply the same rule as C++ - stick to a subset of the language/abstractions. However, if you look at e.g. Haskell, a large number of libraries now depend on a library such as lens [1], so often it's not that much of a choice.

Re:We have C++14 by lmm on Wednesday August 20, 2014 @11:31AM (#8202738)
I think it's good that a library can become sort-of "standard" without having to be part of the language standard library (where, as the python folk say, modules go to die). We're starting to see this come together in Scala-land - if you want a Monad typeclass you use the Scalaz one, if you want a HList you use the Shapeless one, and if you want HTTP you build on top of the spray-http abstractions (I'm particularly pleased that Play intends to port to run on top of Spray). That's something that you don't really get in C++, with the possible exception of boost; there are still multiple ways to do threading, multiple ways to do event-driven, all with their own conventions.
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @04:20AM (#8196403)
That's a pity. My code appears to be a mix of the first three.....

any recommended reading?

Re:We have C++14 by eropple on Monday August 18, 2014 @11:01PM (#8195870)
> "Modern C++" doesn't exist outside of blog posts, books, and tutorials.

That you aren't used to doing greenfield development doesn't mean others are likewise impaired.

Re:We have C++14 by stinos on Tuesday August 19, 2014 @03:02AM (#8196265)
While a bit harsh sounding, this is actually spot on. What I write nowadays vs 5 years ago: hard to believe it is the same laguage.
Re:We have C++14 by eropple on Tuesday August 19, 2014 @09:32AM (#8197150)
Exactly. I only write greenfield C++ and I dig it a whole bunch.
Re:We have C++14 by p0nce on Tuesday August 19, 2014 @10:05AM (#8197312)
Good for you. It would be harder to dig if you had to do some maintenance like less lucky lifeforms.
Re:We have C++14 by gurkendoktor on Tuesday August 19, 2014 @03:26PM (#8199261)
I have only worked on one legacy C++ code base, and it was a student job, but I've enjoyed it a lot. Most of "modern C++" can be applied to an old code base step by step, all the way up from C with classes. As long as nobody decides to introduce the project's first "const" somewhere in a core class... :)
Re:We have C++14 by eropple on Tuesday August 19, 2014 @11:54AM (#8197994)
I hope you didn't take that to mean that I don't maintain my own code. But I can choose when to refactor and when to put up with it. C++ isn't a tool to use when you can't own the project.
Re:We have C++14 by shmerl on Monday August 18, 2014 @09:33PM (#8195650)
My recent project uses standard C++11. No dialects, no restrictions. Gcc 4.8.x. It's not a mirage, it's all up to those who want to use it or not.
Re:We have C++14 by eps on Tuesday August 19, 2014 @04:04AM (#8196368)
You are missing the point. No project uses all features of C++ at once, only a subset, and this forms a dialect. It's not that infrequent to see the dialect change when going from one team to another even in the same organization. Some use multiple inheritance and exceptions, some don't. Some swear by STL, some won't touch it with a long pole. That's why internal coding guidelines exist and that's why they are particularly detailed and thick for C++ shops.
Re:We have C++14 by shmerl on Tuesday August 19, 2014 @11:54AM (#8197993)
The commenter above claimed that "modern C++ doesn't exist" because normally only a subset of the language is used. I disputed that, and I got his point clearly. No one is using all features of the language just for the sake of it. That doesn't make used C++ not modern.
Re:We have C++14 by humanrebar on Tuesday August 19, 2014 @11:27AM (#8197820)
> No project uses all features of C++ at once, only a subset

Many features of C++ are targeted at library authors. Even if a given project won't allow template metaprogramming, it probably uses vector, which certainly does. And for good reason.

Re:We have C++14 by mariodiana on Monday August 18, 2014 @09:03PM (#8195559)
Could you name a book that focuses on Modern C++, that isn't one of these 1200 page tomes? I ask because sooner or later at my job I will probably have to code in C++. It will undoubtedly be a greenfield project, so I don't have to worry about anyone else's horror show (only my own).
Re:We have C++14 by helmut_hed on Monday August 18, 2014 @09:59PM (#8195701)
There's no better place to start than Alexandrescu's eponymous Modern C++ Design http://www.amazon.com/Modern-Design-Generic-Programming-Patt.... Scott Meyers will soon come out with "Effective C++11" which from the table of contents looks like it will do a great job of covering the new language features.

As for coding standards, I suggest a book by the same author plus the current chair of the standard committee: http://www.amazon.com/Coding-Standards-Rules-Guidelines-Prac.... Another commenter has suggested the Google C++ Coding Standards, but despite their popularity they do not conform very well to "Modern C++" as I understand it.

Re:We have C++14 by octopus on Tuesday August 19, 2014 @12:21AM (#8196007)
Try "A Tour of C++" by Bjarne Stroustroup it has less than 200 pages.
Re:We have C++14 by 72deluxe on Tuesday August 19, 2014 @04:21AM (#8196406)
Or just get Stroustrup's "The C++ Programming Language" and read the intro bit - it covers the language in fleeting detail but then you still have the rest of the book to look at if you are having a hard time understanding the section at the beginning.
Re:We have C++14 by octopus on Tuesday August 19, 2014 @07:21AM (#8196765)
I have both, "The C++ Programming Language" as a physical book and "A Tour of C++" as an ebook. "A Tour of C++" is self contained.
Re:We have C++14 by colin_mccabe on Monday August 18, 2014 @09:06PM (#8195569)
I would use the Google Coding standard. The best book to read is Effective C++ (get the latest edition, since they have changed a lot.)
Re:We have C++14 by panzi on Monday August 18, 2014 @09:16PM (#8195599)
Doesn't the Google coding standard use uppercase function names (like Microsoft)? Brrr. Classes are nouns -> uppercase, functions are verbs -> lowercase. Well, alt least if you speak German that is the logical choice.
Re:We have C++14 by MereInterest on Monday August 18, 2014 @09:57PM (#8195696)
It also completely forbids the use of exceptions. I can understand that for their stated purpose of working with non-exception-safe legacy code, but it shouldn't be extended to other circumstances.
Re:We have C++14 by millstone on Monday August 18, 2014 @10:04PM (#8195708)
Exceptions have a significant performance impact, and making code exception safe distorts your interfaces. Insisting on no exceptions is reasonable for these and other reasons, even for new code.
Re:We have C++14 by bodyfour on Monday August 18, 2014 @10:14PM (#8195729)
Depends on if you need to gracefully handle malloc failures or not. Otherwise any write operation on an STL type (like appending to a string) will potentially throw an exception that you need to care about.

In the C world this is extremely arduous since need to bubble the allocation-failure down through every level of code, adding cleanup to just about every function call. If you're using C++ and RAII you can just catch std::exception in one place to cover a huge number of places that an allocation can fail.

Re:We have C++14 by millstone on Monday August 18, 2014 @10:35PM (#8195782)
Do you work on systems that handle this? I'd like to know if any still exist.

In modern systems I'm familiar with, malloc only reports failure on bogus inputs like -1, or address space exhaustion. Your process is likely to be killed before exhausting your address space (think iOS OOM handling, or Linux overcommit), especially on 64 bit. So checking for allocation success just isn't that useful any more.

Re:We have C++14 by jjnoakes on Monday August 18, 2014 @10:47PM (#8195809)
Two examples come to mind.

The first is process limits.

The second is exhausting kernel data structure space for things like page mappings. I've seen this recently in AIX when allocating lots of memory that alternates mprotect permissions.

Re:We have C++14 by nanidin on Tuesday August 19, 2014 @12:24AM (#8196018)
I worked on an embedded system that aggressively cached images in memory dedicated to the GPU. It wasn't uncommon for gl texture allocation errors to occur - and in addition to that, we needed to decompress images packed in various formats into whatever format the GPU supported (typically from png to rgba32). In low memory situations, it also wasn't uncommon to not have enough contiguous memory to perform that decompression - in which case malloc would fail.

Gotta love putting forth every effort in software to keep the BOM down :)

Re:We have C++14 by bodyfour on Monday August 18, 2014 @11:18PM (#8195912)
As @jjnoakes points out, you'll get malloc()==NULL if your ulimits are set. For a long-running program you definitely want to have a ulimit that will kick in before the OOM killer does.

Even in the absence of the OOM killer (i.e. the old days) you had to do this -- otherwise the machine might be swapping itself unresponsive for ages before you ever get malloc()==NULL

Re:We have C++14 by wfunction on Tuesday August 19, 2014 @12:42AM (#8196049)
> Exceptions have a significant performance impact

Are you talking about enabling exceptions, or throwing them?

Re:We have C++14 by helmut_hed on Tuesday August 19, 2014 @12:48AM (#8196056)
Can you elaborate on the "significant performance impact"? If used properly, they should have no runtime overhead - they are predicted "not taken" in modern compilers.
Re:We have C++14 by yaantc on Tuesday August 19, 2014 @04:50AM (#8196474)
Early C++ implementations used setjmp/longjmp to support exceptions, and then each try block would lead to settting the setjmp context. So there definitely was a runtime overhead, even with no exceptions thrown.

I don't think it's very popular today. Modern implementation don't use this anymore and do not incur run-time overhead when no exception are thrown. However, they do incur some space overhead: the implementation need to maintain pretty large tables to know what needs to be unwound (which destructors to call, in which order) when an exception is thrown. In most environment this space overhead shouldn't be a problem (PC, server). But for embedded development it may be a problem. And then disabling exception to save space brings back the issues with error checking (or the lack of it...).

For more details, search for C++ exception implementation and you should find all the info you need. Or look into G++ documentation for example, this topic is covered somewhere.

Re:We have C++14 by pjmlp on Tuesday August 19, 2014 @02:40AM (#8196231)
> Rust, Go, and others will be there to fill in the gap in a much better, saner, safer, maintainable

For business applications? Sure.

For system programming?

Only if they get an OS vendor godfather that pushes the language into their SDK, like any other systems programming language that got widespread use.

Re:We have C++14 by DSingularity on Tuesday August 19, 2014 @12:18AM (#8196002)
And what exactly does that mean? So what if the libraries are all written differently? I hardly see how thats a negative thing. The language is flexible. I was very impressed with c++11 features and I am looking forward to c++14.
Re:We have C++14 by PeterisP on Tuesday August 19, 2014 @11:30AM (#8197845)
It means that the language as such - the codebases written in it - have a readability problem. If every project is written differently with opposing coding standards and practices, then it adds a significant switching cost when moving to a different project, debugging systems that includes libraries from various sources or reusing code.

For ecosystems where there is a "one way to do it", then picking up a random project or library from github and using or changing it is easy, as it is understandable in the same way as my own code; for C++ it is, well, different.

And this is directly caused by the language - the technical details of the language significantly influence the code ecosystem that grows around it. Lisps are another example of this - because it's simple to define commonly used stuff yourself, it results in every project doing the same things differently, adding a serious cost in readability and maintenance for anyone that's not the original author.

Re:We have C++14 by banachtarski on Tuesday August 19, 2014 @03:36AM (#8196320)
What experience are you speaking from?