News for hackers. Stuff that matters.
Re:Why C++ Sails When the Vasa Sank [pdf] by rayiner on Monday June 23, 2014 @05:45PM (#7934912)
> The complexity is there. Trying to understand the whole language at a language-lawyer level is mind-boggling.

It makes me uncomfortable not to have that level of understanding for a language that's so low-level and doesn't have the "Do What I Mean" bent of say Python. I'm "meh" on C++ going forward. I invested a lot of time into my copy of "The C++ Programming Language" (3d Ed.), for C++ 98, but I can't motivate myself to get the new edition and learn in the ins-and-outs of C++ 11. It doesn't seem worth it to me. I'm really hoping Rust catches on. It's a complex language in the same vein as C++, but the bang-for-buck in terms of expressiveness relative to complexity is better, I think.

Re:Why C++ Sails When the Vasa Sank [pdf] by tptacek on Tuesday June 24, 2014 @05:55AM (#7936881)
I'm a former C++ programmer (and a current C programmer) and my go-to language is currently Golang; here's why I'd virtually always choose Golang before C++:

* Streamlined language with carefully-chosen syntax and keywords (there aren't 10 different meanings for "static", for instance); entire concepts have been eliminated to no apparent ill effect in building real systems. Fewer cycles allocated to the language, more cycles allocated to problem domain.

* The 95% case for associative and sequential containers is built into the language, with (for me) enormous benefits to programming efficiency.

* A streamlined and carefully orthogonalized standard library optimized for systems programming. Golang has the best-designed standard library I've ever used.

* A ruthlessly pragmatic packaging and modularity system; unlike C++, packaging is not left up to the build system.

* Build-world compilation times measured in 100s of milliseconds rather than 10s of minutes.

If I was writing, say, a generic trie library that I was hoping to get hundreds of different programmers to use, C++ would be a tempting target because of generics. But it turns out, most of the time I build projects like that, I'm really just wanking. Another benefit of Golang is that it's so stripped down and pragmatic that it subtly discourages wanking.

A lot of people would add Golang's concurrency model (share by communicating instead of communicating by sharing) and lightweight threads to this list. I like Golang concurrency too but my sense of it is that among languages designed from the jump for concurrency, this isn't that much of a unique benefit.

Re:Why C++ Sails When the Vasa Sank [pdf] by maxlybbert on Tuesday June 24, 2014 @09:23AM (#7937533)
> Streamlined language with carefully-chosen syntax and keywords (there aren't 10 different meanings for "static", for instance);

I'll concede this point. I can't imagine learning modern C++ as a complete beginner, even if I know why the Committee overloaded keywords like this (or worse, at least to me, overloaded symbols): the general assumption that any good new keyword has already been used as a function or variable name in somebody's code, so that changing the meaning of that word would break their code.

We'll have to see whether the Golang designers follow in the C++ Committee's footsteps on this. I remember when Java was described as a clean and simple language. I would laugh at anyone who claimed modern Java was clean or simple: adding features to the language without breaking old code is a very difficult dance.

Re:Why C++ Sails When the Vasa Sank [pdf] by koffiezet on Wednesday June 25, 2014 @01:27PM (#7945440)
Absolutely agree on golang.

I started out as a C programmer, mostly coded embedded stuff, and have a decent knowledge of other programming languages (Java, Python, Perl, ...), but always avoided C++ for this reason.

When I made the move to C++, it was very painful to me. In C, I understood every aspect of the language, and going to C++ if felt like 'magic' happening all the time, and trying to understand every single aspect of the language was daunting. Every weird error was another tiring expedition into the language's core, the what and why. Fun is the last word I'd use to describe it, and I always ended up limiting myself to a very narrow subset of C++ because of this. At a certain point however you will be confronted with hairy ugly details of the language. Telling me that 'protected abstract virtual base pure virtual private destructor' is perfectly clear is living in your own small little world.

I enjoy coding in C, it feels like I'm in control, although you really have to do everything yourself, so it's a bit tedious. But C++? No, I absolutely don't enjoy 10-page error messages involving templates that have absolutely nothing to do with the actual error (although you have to give clang some credit here for providing a lot more helpful and compact error messages). It feels like you spend a lot of the time fighting the language and the compiler. Figuring out what a compiler error message exactly means can take a lot of time. And don't say this is the compiler's problem, it's the overly complicated language problem, parsing C++ is an absolute hell - which is the root of those amazingly bad error messages.

I said C++ goodbye about a year ago, and never looked back. My pretty recent discovery of golang was a breath of fresh air. Yes it's not suitable for embedded systems, yes it produces gigantic binaries due to debug symbols always being included and full static compilation (which also has advantages), yes there are no generics (...). It's not perfect, but the language is simple, using it is plain fun, you get a big standard library that even includes a real-world hardened web-server (Google uses it for it's download servers), and there is an amazing amount of 3rd party libraries available for such a young language. It feels a bit like a mix between a scripting and a compiled language - which is nice.

Re:Why C++ Sails When the Vasa Sank [pdf] by lttlrck on Tuesday June 24, 2014 @09:23AM (#7937530)
Is go really suitable for system programming as defined in TFA?
Re:Why C++ Sails When the Vasa Sank [pdf] by tiedemann on Tuesday June 24, 2014 @12:50PM (#7938761)
Go can link to assembler and C routines so yes, I would think Go could be a good language for mid/top-level stuff.
Re:Why C++ Sails When the Vasa Sank [pdf] by blub on Monday June 23, 2014 @06:15PM (#7935081)
How will learning a new language help you? I guess it depends on what you're trying to achieve in the end, but when that something is building software, learning how to use a new kind of hammer isn't the breakthrough one needs most of the time.

In fact I find the premise of all the Go/Rust/D advocates a bit strange. It makes sense to learn a tool that does something you can't do with your existing ones, but learning 5 tools that are mostly the same is a waste of time unless one is not into collecting tools as a hobby.

Re:Why C++ Sails When the Vasa Sank [pdf] by AnimalMuppet on Monday June 23, 2014 @07:18PM (#7935370)
Well, if one is frustrated with the limitations of a particular tool, learning other tools that are like it may in fact help - if the other tools work around some of the frustrations. If not, then it's a waste of time.
Re:Why C++ Sails When the Vasa Sank [pdf] by Dewie on Monday June 23, 2014 @07:18PM (#7935368)
The value proposition of Rust is unique, at least when compared to the languages that you've brought up (and C++).

And how are Rust and Go "mostly the same"?

Re:Why C++ Sails When the Vasa Sank [pdf] by steveklabnik on Monday June 23, 2014 @07:21PM (#7935377)
Well, it depends on how you weight the alternatives. Rust's advantage over C++ is its memory safety. Go is similar (I'm not sure if its safety guarantees are as strong as Rust, I should read up on that...), and it's advantage over Rust is that its type system is easier to get started with, but its disadvantage is requiring garbage collection. D is closer to C++ than Rust is, but has amazing metaprogramming, and defaults to GC, though it's not mandatory.

If none of these things matter to you, then they do seem similar. But if they do matter, then the difference is much larger.

Re:Why C++ Sails When the Vasa Sank [pdf] by tptacek on Tuesday June 24, 2014 @05:46AM (#7936865)
I wish language advocates would break themselves of the urge to sum up languages they don't use.
Re:Why C++ Sails When the Vasa Sank [pdf] by steveklabnik on Tuesday June 24, 2014 @12:42PM (#7938705)
I did use D a lot, though it was very long ago. I don't like Go, but I respect quite a bit of it.

I consider myself more of a PLT enthusiast than a language advocate. Is there anything about my summation that's incorrect?

Re:Why C++ Sails When the Vasa Sank [pdf] by tptacek on Tuesday June 24, 2014 @12:59PM (#7938807)
Yes, I think so. Let's not debate it though.
Re:Why C++ Sails When the Vasa Sank [pdf] by steveklabnik on Tuesday June 24, 2014 @01:02PM (#7938824)
Yes, let's not. I just highly respect your opinion, and know you have a lot to say about Go.
Re:Why C++ Sails When the Vasa Sank [pdf] by tptacek on Tuesday June 24, 2014 @05:33PM (#7940805)
Likewise, hence avoiding the subject. :)
Re:Why C++ Sails When the Vasa Sank [pdf] by pmelendez on Monday June 23, 2014 @05:54PM (#7934961)
>"for C++ 98, but I can't motivate myself to get the new edition and learn in the ins-and-outs of C++ 11"

I can understand that but keep in mind that C++11 is a completely different language to what it is C++98.

Re:Why C++ Sails When the Vasa Sank [pdf] by angersock on Monday June 23, 2014 @06:00PM (#7934998)
This is a bug, not a feature.

There is a lot of good stuff in the new versions of C++, but the language really could've used a bifurcation years ago.

That said, it's still the best tool in the toolbox for certain problems.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Monday June 23, 2014 @06:13PM (#7935069)
Which problems? That's a genuine question: the way I see it, C++'s niche is shrinking by the year, as new languages and more powerful computers arise. So, what's left?
Re:Why C++ Sails When the Vasa Sank [pdf] by zenbowman on Monday June 23, 2014 @10:29PM (#7935909)
How so?

It is still the dominant language for large-scale low-level systems. Critical software driving submarines, power plants, financial exchanges and medical devices is likely written in C++. The code on most of SpaceX's spacecrafts is in C++. Most of Google's infrastructure is written in C++.

With the constant increase of low powered computing devices we are likely to see that "niche" increase.

I think it is rather embarrassing that most code written in modern languages performs worse on today's computers than native code running on 1980s machines.

Performance is what makes computing magical.

"In established engineering disciplines a 12% improvement, easily obtained, is never considered marginal and I believe the same viewpoint should prevail in software engineering" - Donald Knuth

Sadly, people only cite his other quote about premature optimization being evil, leading to a generation of computer programs written with no consideration of speed and user experience.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @04:38AM (#7936714)
Funny how "critical" software often uses wildly unsafe languages. They should take advantage of paranoid type systems instead, that would prevent the occasional crash upon integer overflow, or SI/imperial incompatibility…

In established engineering disciplines, specification is a relatively small part of the work. In software, specification is everything (compilers and interpreters do the heavy duty for you). In established engineering discipline, a 12% improvement in a meaningful dimension (such as construction costs, or interior volume, or…) is easily worth doubling the specification effort. In software, a 12% cut in specification effort is easily worth a 50% worsening of another dimension, such as runtime speed or compilation speed (though of course we must not overdo it http://xkcd.com/303/ ).

Re:Why C++ Sails When the Vasa Sank [pdf] by zenbowman on Tuesday June 24, 2014 @09:10AM (#7937461)
This very much depends on what you care about. If you are running a 100,000 machine datacenter, a 12% efficiency improvement may save you millions of dollars in computing and energy costs a year. That is certainly worth a doubling of specification effort.
Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @11:41AM (#7938350)
Of course. But cases like this takes a tiny, tiny fraction of all programming effort. Very few programmers get to work under such tight constraints.
Re:Why C++ Sails When the Vasa Sank [pdf] by zenbowman on Tuesday June 24, 2014 @12:08PM (#7938509)
I don't think so. In established fields of engineering, optimization takes up as much, if not more time, than design.

Computing is a new enough field that so far that hasn't been the case, but I think with the increase of media processing and large scale data processing, a 10000 machine computer will be the new norm. And just like most other fields of engineering, optimization will be a major concern, if not the primary concern.

http://www.cs.berkeley.edu/~rxin/db-papers/WarehouseScaleCom...

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @05:41PM (#7940842)
You are glossing over a fundamental difference between computing and other fields of engineering: copy & paste.

You don't get to just copy a bridge. You have to build another. With software, it is harder to justify building something anew, even if it's a bit different: you could re-purpose the old thing at very little cost (provided the old thing was well written and close to your mark to begin with, which is often not the case…).

Then there's the systematic automation of everything we understand sufficiently deeply. Garbage collection. Compiler optimizations. Libraries, some of which are freakishly fast. Databases.

When faced with a new project, you will increasingly not care about performance, because you will just reuse the incredibly fast infrastructure the system folks wrote for you. Don't get me wrong, performance is likely to become more and more important over time (as you said). It will just take less and less programming effort, as everything will increasingly be put in common —well, as long as we have the internet and Free Software.

More and more, the path to freakishly good performance will be simple, elegant, and obvious code. Algorithms will still matter, but you will hide most of them behind libraries. And you certainly won't do micro-optimizations.

If the compiler is not enough, you can have a team rewrite your hot spots using computer assisted semantic preserving transformations, in a tiny fraction of the effort it took you to write elegant code in the first place. Should you need to modify this code, no problem: just re-run the special set of optimization they devised in the first place. Worst case, the compiler just tells you it can no longer run the specialized optimization on your new code, leaving you with slow code until the optimization team amends its optimization.

Re:Why C++ Sails When the Vasa Sank [pdf] by zenbowman on Wednesday June 25, 2014 @09:43AM (#7943782)
Sure, but none of this points to high-performance languages being a shrinking niche. They will continue to dominate low-level code and library code.

Less low-level code will be written each year than high-level code, but it'll still be tremendously important. And as machines change, the underlying libraries will keep changing.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Wednesday June 25, 2014 @12:02PM (#7944778)
Careful with the metrics.

On the one hand, we have required effort. On the other hand, we have impact. To take an extreme example, Web browsers are a tiny niche in terms of development effort. Their impact however is something else entirely.

This is what I predict with low-level stuff. It will grow in terms of impact, but shrink in terms of development effort (at least in relative terms).

> as machines change, the underlying libraries will keep changing.

Increasingly, no they won't. What will change will be the optimization technique that we will need to operate on otherwise clean, elegant, obvious, and slow code.

Take a C library for instance. If it is written in a portable fashion, you only need to write a new C back-end to port that library to another machine. The same goes for semi-manually optimized code. You don't need to change the specification (I mean, the source code) to port the thing to another platform. You only need to change the optimization strategy. It's still an effort, but that's much less effort than a complete rewrite.

Re:Why C++ Sails When the Vasa Sank [pdf] by koffiezet on Thursday June 26, 2014 @05:41AM (#7948752)
> I think it is rather embarrassing that most code written in modern languages performs worse on today's computers than native code running on 1980s machines.

Ok, let's play ball.

> After the Cray-1, the Cray Corporation developed another giant named Cray-2. It remained the world’s fastest Supercomputer between the years 1985 to 1989, capable of performing 1.9 gigaflops. ( Source: http://infotology.blogspot.be/2012/04/super-computer-timelin... )

So that's tha fastest of the fast in the '80's. According to Intel, a i7-3770k consumer CPU gets 112 gflops and a Q6600 quad core, which was released in Q1 2007, has 38.40 GFlops. That's a factor 58+ faster on the i7, or a factor 20 for the Q6600.

Now let's take the Q6600 to make it easy to compare languages in a very bad way: http://benchmarksgame.alioth.debian.org/u32q/benchmark.php?t...

I picked the bench config x86 quad core because this had the highest peak. Also, if you take these languages, which are more commonly used: * C#/Mono: Worst 9x, median 2x * Go: Worst 7x, median 3x * Haskell: Worst 3x, median 2x * Java: Worst 3x, median 2x * PHP: Worst 109x, median 36x * Python 3: Worst 129x, median 37x * Ruby: Worst 239x, median 53x * JRuby: Worst 115x, median 34x

But keep in mind that: * Current CPU integer performance, cache speeds, memory bandwidth and general i/o would completely destroy the Cray-2 * GFlops are a real bad indicator of how fast a computer is. Current computers are even faster. Current GPU's are floating point optimized and run circles around any general purpose CPU when it comes to GFlops. * These are CPU-bound artificial language comparison benchmarks. * Native code means nothing. Bad slow code will always be slow, whatever language you use. Some of the languages included do compile to 'native code' (Go and Haskell), and a lot of the interpreted/byte code compiled languages use a JIT to generate 'native code' too. * We don't take into account the Cray-2's bottlenecks (mainly I/O) * All GFlop numbers are according to the manufacturer. * Most applications hit i/o limits before hitting CPU limits (yes there are exceptions) * this is comparing with the fastest of the fast you could get at the end of the '80s

So in worst theoretical cases, sure. In the real world? Not even close.

Re:Why C++ Sails When the Vasa Sank [pdf] by 59nadir on Tuesday June 24, 2014 @03:40AM (#7936594)
> It is still the dominant language for large-scale low-level systems.

He didn't say it wasn't the least dominant. He asked why it was to be considered the best. Dominance is a thing of legacy and you have to take into account a bunch of reasons that have nothing to do with how good a language is to assess why that's so.

Being the best tool is something completely different. I think the commenter has a good point and I think it's clear that a lot of the areas C++ has been used for have been taken over by better languages that offer more without conceding much. In that regard, he is spot on in saying that C++'s niche is indeed shrinking.

C++, like most other languages, is the best tool for some problems and areas, but those are growing smaller and smaller as we identify exactly what we need and create new languages to escape the rest of C++.

Re:Why C++ Sails When the Vasa Sank [pdf] by NAFV_P on Tuesday June 24, 2014 @11:35AM (#7938297)
> The code on most of SpaceX's spacecrafts is in C++.

A few weeks ago I found out that the B-2 Spirit now flys on olde C.

http://en.wikipedia.org/wiki/Northrop_Grumman_B-2_Spirit#Fur...

> I think it is rather embarrassing that most code written in modern languages performs worse on today's computers than native code running on 1980s machines.

Are there any sources to support this statement, or are you drawing on personal experience?

Re:Why C++ Sails When the Vasa Sank [pdf] by lostcolony on Tuesday June 24, 2014 @08:46AM (#7937358)
'Easily obtained'

I don't consider an improvement obtained switching from/avoiding a high level language that allows me useful abstractions and to avoid bookkeeping, to C++, an easy thing.

Yes, if the thing is just -slow-, optimize it. But never start out "We can't have this thing be slow; let's write it in C++!" unless you already have some metrics showing that it's -too- slow in a safer language.

Re:Why C++ Sails When the Vasa Sank [pdf] by nine_k on Tuesday June 24, 2014 @07:19AM (#7937085)
I very much hope submarines' software use more Ada and less C++.
Re:Why C++ Sails When the Vasa Sank [pdf] by captainmuon on Tuesday June 24, 2014 @03:26AM (#7936562)
Scientific computing. For my work (in particle physics) I need something that is fast, has interoperability with decades worth of C, C++ and Fortran code, runs preferable close-to-metal, and has minimal overhead. Also, it has to be something physicists (not computer scientists) can/want to work with.

There are a lot of great libraries for Python, and it's much nicer and more productive. I use it whenever possible, esp. for making graphics, or when I can use optimized stuff like in numpy. However, most of the programs I write are of the type "loop over 10 million entries, perform a simple calculation, return a number". These are mostly IO bound, and one would think that this is a case where you could use a dynamic or interpreted language. But whenever I tried, the overhead for the large loop and the variable access in tight loops was too high, and the problem became CPU bound. So, in my experience, it has to be a compiled language (or at least something more performant then Python).

I'd love to be able to use something like Haskell, as a lot of my problems are functional in nature, and it'd be able to catch a lot of stupid bugs. But it is too esoteric to be realistically adopted by the community.

The ideal language for me would be "C+". A C++ lite, where you would ban most of the complications. You would still be able to write C++ libraries, but then use them from simple C+. A C+ user, as opposed to a library writer, would not have to know about the "safe bool idiom", traits, private destructors, default methods (which are utter maddness in C++11) and template metaprogramming.

I'd then augment this simplified C+ with a powerful static invariant checker. You could say something like "guarantee x < 10; x = f()" and it could complain "you demanded x be < 10, but f() only guarantees x < 100".

Re:Why C++ Sails When the Vasa Sank [pdf] by jerf on Tuesday June 24, 2014 @10:46AM (#7938028)
"I'd love to be able to use something like Haskell, as a lot of my problems are functional in nature, and it'd be able to catch a lot of stupid bugs. But it is too esoteric to be realistically adopted by the community."

The esoteric, and what you need to do what you said, are nearly entirely partitioned from each other. Reading in a list of things, running some code over it, and spewing the results out is not that hard and will not involve anything you can't understand.

That said, even after some relatively extensive use of Haskell I still have poor intuition about how well it performs on such tasks... no, not because of "laziness", but because "naively" written Haskell still involves things getting boxed and other such performance killers that can take you halfway back to Python. I can say writing Haskell to do your described tasks isn't hard... I have a harder time promising you can write performant Haskell just by doing the obvious things. There's some promising work on doing fast numerical calculations, but it still seems like it's very easy to be doing something very fast, then change a bit of code, which silently breaks optimizations and suddenly it's slow for no obvious reason. (Note this is NOT unique to Haskell... all compiler optimizations can have this problem. It's just particularly acute in Haskell, but I've encountered it elsewhere. I've often wished for more transparent optimization feedback in many languages, or the ability to assert that I'm triggering certain optimizations so that if I do break them in the future, I find out at compile time. Alas, I've never seen such a thing.)

Re:Why C++ Sails When the Vasa Sank [pdf] by mmaldacker on Tuesday June 24, 2014 @04:27AM (#7936684)
With C++11 you don't need the safe bool idiom anymore, you can simply define a "explicit operator bool() const". Since the conversion needs to be explicit, you won't have nasty surprises but it can still be used in an if (or while) normally as in this case the explicit conversion will be used implicitly. In other words, it works exactly like the safe bool idiom but is much easier to write.
Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @03:50AM (#7936605)
> I need something that […] has interoperability with decades worth of C, C++ and Fortran code.

Assuming you meant more than having a good FFI…

When I judge the suitability of a language for a task in the abstract, I systematically ignore 2 very important factors: legacy code, and skill availability. I do as if everyone know every language, and we start from a mostly blank slate.

If I didn't ignore those factors, I wouldn't be judging the languages, I would be judging whole ecosystems, introducing a huge status-quo bias in the process.

---

The C+ you look for is probably possible. I bet it could be implemented a la CFront.

Re:Why C++ Sails When the Vasa Sank [pdf] by cageface on Monday June 23, 2014 @08:48PM (#7935648)
I write music-making software, which is one domain where C++ is utterly dominant and likely to remain so for a long time. In this world you need a language that's fast, gives you fine-grained control of memory, and allows you to operate without ever allocating or taking a lock of any kind. You could also use C for this, and some people do, but I find that the more powerful abstractions C++ provides are very very helpful here.

I think it's unlikely we'll see anything like Chrome, Ableton Live, or Photoshop written in anything but C++ any time soon.

Re:Why C++ Sails When the Vasa Sank [pdf] by pcwalton on Monday June 23, 2014 @09:07PM (#7935707)
> I think it's unlikely we'll see anything like Chrome, Ableton Live, or Photoshop written in anything but C++ any time soon.

We are working to change that in Servo :)

Re:Why C++ Sails When the Vasa Sank [pdf] by cageface on Monday June 23, 2014 @10:05PM (#7935858)
I'm rooting heavily for you guys. I use C++ not because I love it but because it's my only reasonable option. If Rust becomes viable for the work I do I'll be on it in a flash.
Re:Why C++ Sails When the Vasa Sank [pdf] by seth1010 on Tuesday June 24, 2014 @12:49AM (#7936246)
There was a guy at the last Rust Seattle meetup that was doing procedural music generation in Rust and said he was having a blast.
Re:Why C++ Sails When the Vasa Sank [pdf] by justincormack on Tuesday June 24, 2014 @08:33AM (#7937308)
Well Lightroom is not exactly like Photoshop but it is mostly written in Lua. Parts are in C or C++ still it is true.
Re:Why C++ Sails When the Vasa Sank [pdf] by vinkelhake on Monday June 23, 2014 @06:27PM (#7935139)
It's not about specific problems, but rather when you can't compromise on performance and still want to raise the abstraction level from C.

There are up and coming languages that can claim to compete in that area, but they're still rather immature and/or lack developer support.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Monday June 23, 2014 @07:35PM (#7935416)
I'm afraid I must insist on specificity: no specific problem means no justification. I understand the abstract reasoning if we had to plan that we might need C++ in the future. But when you're choosing a language now, you always work on a specific problem.

So, which specific problems requires you to both optimize the hell out of your CPU and memory, and mostly work at a higher level of abstraction than C?

I'll go even further: C + <high-level language of choice> already competes on that front (abstraction + performance). On which specific problems are they not enough, and C++ is required?

I'll go even further: there has been a number of C pre-processors spouting up recently. One of them does Lisp-like macros. Another does lambdas. Yet another might address templates. I predict a modern version of "C with classes", which learned from the mistakes of the past (like trying to be compatible at the syntax level).

At that point, do you think there will be any specific problem where C++ is still the best choice?

Re:Why C++ Sails When the Vasa Sank [pdf] by vinkelhake on Monday June 23, 2014 @08:28PM (#7935587)
> So, which specific problems requires you to both optimize the hell out of your CPU and memory, and mostly work at a higher level of abstraction than C?

My sibling here already mentioned AAA game development. Finance is another area where top performance is often required.

Performance is the requirement. Being able to work at an abstraction level higher than C is highly desirable. C++ gives you both of those.

> I'll go even further: C + <high-level language of choice> already competes on that front (abstraction + performance). On which specific problems are they not enough, and C++ is required?

You get a boundary between the "high level" and "performance oriented" parts of the code that is arbitrary and only exists because the high level language performs poorly. There are definite costs to that approach.

> I'll go even further: there has been a number of C pre-processors spouting up recently.

Cute hacks that are probably not suitable for production use.

Let's be honest here. You're asking for problems that require the use of C++ now. The situation is surely going to be different in, say, five years from now - though I don't think it'll be a "C with classes".

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Monday June 23, 2014 @09:04PM (#7935692)
I believe Jane Street does High Frequency trading with OCaml. The other examples sound valid, though I have my doubts about batch processing (compression, crypto…).

I intend to work an a serious C pre-processor this summer, after I'm finished with my Earley parser. This won't remotely resemble "C with classes". I won't aim for any syntactic compatibility, that was a silly requirement. Heck, I'll probably have Python-like mandatory indentation, reworked operator precedence, an overhauled type syntax, switches that don't fall through… But I will keep semantic compatibility, and a relatively obvious mapping to underlying C code. Coffe-C, not Clojure-C.

But even that won't satisfy me. Eventually, I want to make a source-to-source transformation framework that can turn any language into any other. With that, languages become less of a programming interface, and more of an implementation concern.

Re:Why C++ Sails When the Vasa Sank [pdf] by jerf on Tuesday June 24, 2014 @10:54AM (#7938084)
"Eventually, I want to make a source-to-source transformation framework that can turn any language into any other."

Beware. That's a pretty common programmer tarpit. I've witnessed two take this on myself. If you never hear about it online, it's because it makes "general puprose visual programming language" look easy; people at least get to the "show something off" stage with that.

It may help to observe that we technically already have an intermediate language that works with all languages, which we call machine language. If it sounds infeasible to read all machine language and convert between various programming representations especially in light of things like VMs and such... well... yeah. That's a fairly direct and accurate reflection of the difficulty in question.

In some sense, this is the absolute purest "inner platform effect" project you could ever hope to undertake. http://en.wikipedia.org/wiki/Inner-platform_effect

Re:Why C++ Sails When the Vasa Sank [pdf] by cgh on Monday June 23, 2014 @10:16PM (#7935878)
Jane Street is not the only HFT firm out there, though you'd think so from reading the comments here. Most use C++ and Java.

C++ is everywhere, from embedded to application software to games to the server side (Google has a gigantic C++ codebase).

I worked on a camera that had its logic written in C++ and it wasn't some unusual thing.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @04:22AM (#7936674)
My point was, HFT is possible to do with something other than C++. Jane Street does OCaml, and you have just cited Java (garbage collection and virtual machine!). Since C++ is such a Chtuloid horror, the mere fact that it is possible to use other language, let alone garbage collected languages, is extremely strong evidence that C++ simply isn't the best choice. You haven't refuted my point, you have supported it.

(Of course, I don't take legacy code nor talent availability into account. They are crucial in any real-world decision, but they don't influence the virtues of the language itself.)

Re:Why C++ Sails When the Vasa Sank [pdf] by vinkelhake on Tuesday June 24, 2014 @11:25AM (#7938251)
> Since C++ is such a Chtuloid horror, the mere fact that it is possible to use other language, let alone garbage collected languages, is extremely strong evidence that C++ simply isn't the best choice.

Yeah, well, that's just, like, your opinion, man.

Seriously though, don't mistake your personal opinion for some objective truth. There are plenty of programmers out there who enjoy C++ and don't see it as a Chtuloid horror. What you have isn't strong evidence of anything, really.

> (Of course, I don't take legacy code nor talent availability into account. They are crucial in any real-world decision, but they don't influence the virtues of the language itself.)

And there are even more "external" factors to consider, but if you allow yourself to cherry-pick criteria then you can make any language be the optimal choice. Languages don't exist in a void.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @12:02PM (#7938469)
It's not just my opinion. Do I have to resort to the nuclear option? http://www.yosefk.com/c++fqa/ Well, there you have it. C++11 and 14 made some things better, but they also have their problems.

My opinions have different strengths. This one has accumulated enough evidence that I no longer consider the possibility of its falsehood. C++ sucks, and that's the end of it. I know of the gazillion eminently reasonable reasons why C++ is what it is, but it still sucks. I know that if Stroustrup made cleaner choices for the language, it wouldn't be so popular, but it still sucks. I know that a better language that nobody use is… well… useless, but C++ still sucks. In my opinion, C++ is one of our greatest shame as a community.

> If you allow yourself to cherry-pick criteria then you can make any language be the optimal choice.

I don't cherry pick. I'm just comparing languages. Not external tools. Not backward compatibility. Not programmer availability. Just languages. The other criteria are short term considerations, and greatly increase status-quo bias. They're only interesting when I must do a small project now, with whoever happen to work with me at the moment.

For bigger projects however, the language is increasingly important. The bigger the project, the more reasonable it is to switch to use a better language, instead of a better known language.

Re:Why C++ Sails When the Vasa Sank [pdf] by hft_throwaway on Tuesday June 24, 2014 @03:53PM (#7940127)
Guys who write HFT systems in Java are basically programming them like one would in C or C++. They pre-allocate byte buffers for everything and never run the GC. If you write C-style code in Java, it's going to run pretty quickly. They aren't doing architecture astronaut AbstractMetaClassFactory stuff or using much of the provided libraries for latency-sensitive code.

FWIW, I don't think Jane Street is a competitor in the "ultra HFT" space where every nanosecond counts. AFAIK they are more of a statistical and quantitative trading group, so they may have less need for things like talking directly to hardware, keeping tight control over memory layout, deterministic latency w/o GC pauses, etc.

Almost everything that is popular has evolved over time, and making these changes once you have established users results in compromises that can be sort of ugly. C++ has patina.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Wednesday June 25, 2014 @04:30AM (#7942808)
> Almost everything that is popular has evolved over time, and making these changes once you have established users results in compromises that can be sort of ugly. C++ has patina.

You will note that C++ made that sort of ugly compromises from the start. Keeping a C-like syntax really wasn't necessary. (Keeping a C-like semantics, that's a different story.)

Re:Why C++ Sails When the Vasa Sank [pdf] by hft_throwaway on Wednesday June 25, 2014 @12:39PM (#7945081)
But isn't that because C++ itself evolved from C? The original "C With Classes" wasn't much more than a convenient syntactic sugar for using structs and function pointers as a poor man's object system, something that was and is common in large, abstract C programs (e.g. Linux's VFS layer, Gtk+).

I think you may be confusing is with ought here. Everybody sane knows C++ has flaws; I think Meyers even feels this way in his presentation. C++ is popular because it evolved and thus contains a lot of compromises. To draw an analogy, the Mormon Church is immensely popular in the US for similar reason--they basically said, "Hey the New and Old Testaments you spent your formative years learning are all good, but we've got some swell new stuff here too!" I'm sure Zen Buddhism is more theologically pure, but people like what's familiar to them.

Programming languages are a network effect problem first and foremost. Just like it's hard to unseat Craigslist despite its crappy UI, it's difficult to get users for a new language that may be only marginally better in terms of features, productivity, safety or convenience. Even if it's a significant improvement existing code bases, library availability, programmer availability with domain knowledge and so on matter much more for serious projects. There's a reason why Facebook took the time to write a PHP VM instead of rewriting their code.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Wednesday June 25, 2014 @07:41PM (#7947380)
> Programming languages are a network effect problem first and foremost.

If only reality wasn't like this. Yes, network effects are ridiculously important. And so is status-quo bias in general. I know C++ wouldn't be nearly as popular if it adopted a different syntax. I know that the ability to compile most existing C code out of the box was a big help in the adoption of the language, even though it technically doesn't matter. This is why I said erlier¹ that C++ is one of the greatest shame of our community. Stroustrup was well aware of our insanities, and he exploited them on purpose, supposedly for our own good. We as a community were simply incapable of accepting anything better. It would have been too different.

[1]: https://news.ycombinator.com/item?id=7938469

> But isn't that because C++ itself evolved from C?

It didn't. C++ did not evolve from C, it was implemented on top of C. Stroustrup didn't started by modifying the front-end of GCC, he started by writing CFront. From there, it would have been real easy to fix some of the most glaring flaws of C: switches that fall through, overly general (and verbose) for loops, the insane syntax of type declarations (ML existed at the time, and could have been an inspiration), the priority of the operators (15 levels are too much, some priorities are backwards), and maybe some operators themselves (the star for instance serves two unrelated purposes, which may be confusing). While we're at it, Stroustrup could have thrown the headers away, replacing them with a proper module system. Nothing fancy, just a nice way to package compilation units.

That was the "fixing C" part. These flaws were known at the time, it would have been easy to fix them. (Except maybe the module system. You still want an easy way to talk to existing C code.)

Then we can move on to building C++: a language with a stellar C FFI, semantics that are identical to C (except for advanced syntax sugar such as classes), but with a much cleaner, easier, and more flexible syntax. This language would have been much better than the current C++ on every possible measure, except one.

Adoption.

It seems we just can't change our syntax. No, scrap that, we just can't change, period. People love "change", but they hate change. There are few circumstances where people are willing to accept change (like this anecdote about introducing OpenOffice as "the new version of Word"). One of C++'s greatest strength (and our community's greatest weakness), was it's apparent similarity with C. It's the same, except with more features! A better syntax for C however, while more useful than a mere C-with-classes², would never have caught on.

[2]: Templates are C++'s killer feature, not classes. (OO as done with C++ and Java classes is mostly a mistake³. But that's another debate.)

[3]: http://loup-vaillant.fr/articles/classes-suck

(I'm not kidding about C's syntax being terrible. Experiments have shown that beginners fare no better with C than they do with a randomly generated syntax. It is that bad.)

Re:Why C++ Sails When the Vasa Sank [pdf] by furyofantares on Monday June 23, 2014 @08:31PM (#7935598)
I think C++ is a fine choice right now for a whole lot of things, though in most cases I think C is also a reasonable choice and there are tradeoffs between the two depending on the goals of the specific project (rather than the type of project).

So here's my list: A compression library, a crypto library, a numerical library, a video game, high frequency trading system, a high performance application server, a webserver, a database, a storage or caching system, an operating system, device drivers, a web browser, a VM, a programming language.

Re:Why C++ Sails When the Vasa Sank [pdf] by falcolas on Monday June 23, 2014 @08:09PM (#7935523)
Game programming. AAA level games require high level performance which can typically not support interpreted languages. They also are complex enough that trying to program them in C would create more problems than they would solve.

Granted, many indy games can work by using an embedded interpreter for much of the game logic, but it doesn't take much to run out of computing power at that level and still maintain reasonable (and consistent) frame rates.

Re:Why C++ Sails When the Vasa Sank [pdf] by thwest on Monday June 23, 2014 @09:10PM (#7935712)
In C++ I can write a generic vector math routine that operates on any scalar type and still simd specialize it for particular scalar types.
Re:Why C++ Sails When the Vasa Sank [pdf] by maaku on Tuesday June 24, 2014 @01:33AM (#7936320)
You can do that in many languages...
Re:Why C++ Sails When the Vasa Sank [pdf] by thwest on Tuesday June 24, 2014 @01:51PM (#7939200)
Statically typed i.e. without a inner loop dispatch penalty? Which others? I've considered an implementation in Fortran and OCaml as well. OCaml is attractive but doesn't cross compile to ARM officially. With C++ we can target x64, ARM and TI DSP with the same core processing module.
Re:Why C++ Sails When the Vasa Sank [pdf] by maaku on Tuesday June 24, 2014 @06:39PM (#7941129)
Have you tried Haskell?
Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @04:41AM (#7936722)
You're not describing a problem. You're describing a solution, that C++ can implement.
Re:Why C++ Sails When the Vasa Sank [pdf] by 72deluxe on Tuesday June 24, 2014 @09:17AM (#7937502)
Cross platform applications? I know that C# apparently has cross platform support but I met with limited success on Mac OSX (perhaps I didn't try hard enough). It is fairly easy to get a cross-platform library and use C++ to write for the main OSes (Mac OSX, Windows, Linux, in no particular order) and then you can also take the same code and compile and run it on your Raspberry Pi and ARM systems.

I know you could probably do the same with Python but I think small systems would suffer a speed penalty (I even find desktop Python applications slow so I dread to think of GUIs on an ARM written in Python). I reality I have not ever come across a piece of paid software that included a runtime of Python or some scripting language other than Perl, and that clearly wasn't for a GUI app.

What else would you write for all three platforms in? Java? I am curious.

(I suppose if you are targeting one platform only, then it might make sense to write in languages typically tied to that platform, eg. Obj-C / Swift / VB / C# (as is vastly popular in Windows land)).

Re:Why C++ Sails When the Vasa Sank [pdf] by TheCondor on Tuesday June 24, 2014 @09:14AM (#7937486)
Writing certain windows apps?

The paper states that C++ must have done something right, as it is still consistently popular. If ms didn't go all in with it though, I think it would be a footnote in history.

Re:Why C++ Sails When the Vasa Sank [pdf] by loup-vaillant on Tuesday June 24, 2014 @05:44PM (#7940856)
> The paper states that C++ must have done something right, as it is still consistently popular.

Oh, yes it did. Mainly preying on human irrationality. Most notably status-quo bias, exploited with its embrace and extend strategy.

Re:Why C++ Sails When the Vasa Sank [pdf] by norswap on Monday June 23, 2014 @07:19PM (#7935373)
It's different in the sense that it adds a whole lot of features, which makes it even more complex. It's not just the new features, but how they interact with old one. C++98 is still there, just underneath.
Re:Why C++ Sails When the Vasa Sank [pdf] by pradn on Monday June 23, 2014 @08:27PM (#7935580)
The addition of a whole host of features in C++11 makes the language more consistent and easier to comprehend. The talk gives examples of this (auto variables, range for loops, etc.)
Re:Why C++ Sails When the Vasa Sank [pdf] by georgemcbay on Monday June 23, 2014 @11:09PM (#7936014)
Of course, as soon as you have to use any external libraries written for C++98 you are right back to having to understand both.

I, thankfully, haven't used C++ much in the past few years after using it nearly exclusively for about a decade, but the one thing about working in it that will always stick with me is how virtually every project would eventually have like 8 different string classes contained within it for much the same reason (different libraries and/or OS level APIs would use different string classes, often their own), and this is well after std::string/wstring were a thing.

That's the real danger with a sprawling language like C++, IMO. Not that you have to use every bit of it in your own code (in your own code you can get by with a very small subset), but the fact that because there's little true consensus on which bits of it to use it, projects with external dependencies (that are also in C++) generally grow to use not only the entire language and standard library in different places, but also a bunch of badly hacked up reimplementations of the standard library that come along with some of those dependencies.

Re:Why C++ Sails When the Vasa Sank [pdf] by humanrebar on Tuesday June 24, 2014 @10:58AM (#7938103)
The problem with string classes, including std::string, is that they are object oriented. The things you do with a string should be orthogonal to how the string works. When you think about it std::string is really a string buffer. And if we had good string algorithms, it wouldn't be much more useful than vector<char>.

In various circumstances you may want: string_views, copy_on_write_buffers, small_buffers (for small-string optimization), native arrays of chars, std::arrays of chars, std::vectors of chars, tries, and so on.

In all of the above cases, you should be able to write: auto firstSpace = std::find( begin(myCharContainer), end(myCharContainer), ' '); ...to get an iterator to the first space in your container.

And on top of all that, you could make versions of begin() and end() that return iterators that respect various character encodings.

Re:Why C++ Sails When the Vasa Sank [pdf] by rrrrtttt on Monday June 23, 2014 @11:43PM (#7936089)
Initially when you start with C++11 you get the impression that the old heap of idiosyncrasies was fixed, but then you realize there's a whole bunch of new ones. My most recent peeves:

1) You can create range for loops over containers:

  for (auto x: vec) {
    foo(x);
  }
but then if you want to do the same over a C array, you have to define your own wrapper with begin() and end() functions.

2. You can create shared pointers using make_shared, but you can't create unique pointers using make_unique. What's worse, if you define your own make_unique function, your code will eventually break because it's already decided that C++14 will have its own make_unique.

I'm sure all of this will get fixed eventually, but frankly I don't have more patience for this. The root cause is that the C++ process is broken and is lead by incompetent clueless people.

Re:Why C++ Sails When the Vasa Sank [pdf] by mgraczyk on Tuesday June 24, 2014 @01:02AM (#7936263)
1. That's not true, you can use range based for loops over C array types. http://stackoverflow.com/questions/7939399/how-does-the-rang...

2. As you mentioned, make_unique is a part of C++14 (although it will still be missing make_unique<T[]> ). I don't see the big deal is though since libc++, libstdc++, and VS2013 already have a compliant make_unique implementation.

Re:Why C++ Sails When the Vasa Sank [pdf] by pbsd on Tuesday June 24, 2014 @02:57AM (#7936505)
> although it will still be missing make_unique<T[]>

This is not true -- see §20.9.1.4 of the C++14 draft [1]. make_unique is defined for array types with unknown bound (i.e., T[]), but it is deleted for array types of known bound (e.g., T[5]). So to make an array of 100 default-initialized `int`s,

    auto array = std::make_unique<int[]>(100);
[1] http://isocpp.org/files/papers/N3690.pdf
Re:Why C++ Sails When the Vasa Sank [pdf] by Arnt on Tuesday June 24, 2014 @03:08AM (#7936534)
That's not how it felt to me. It felt more as if they added the new features underneath C++98. Exaggerating wildly: One new general rule turns three old special rules into simple corollaries.
Re:Why C++ Sails When the Vasa Sank [pdf] by 72deluxe on Tuesday June 24, 2014 @09:11AM (#7937468)
C++ does feel like a new language. If you just buy Stroustrup's new book and read through the "tour of C++" towards the beginning, you'll find lots of new bits without having to read the entire book (although I am still going to try and do that).

For me, I am constrained by the compilers that are used by my employers (VC10) so I can't use half of the new features (although I could use them in Xcode and macro them out I suppose).

Re:Why C++ Sails When the Vasa Sank [pdf] by dman on Monday June 23, 2014 @05:49PM (#7934935)
Looking forward to v1.0 of Rust to have some expectation that the constructs that I learn will endure over time.
Re:Why C++ Sails When the Vasa Sank [pdf] by EpicEng on Monday June 23, 2014 @06:16PM (#7935082)
I love how C++ is now considered by many to be "so low level". It's a high level language as far as my work goes. Sure, it's not Python-high-level, but Python isn't an option.
Re:Why C++ Sails When the Vasa Sank [pdf] by tormeh on Monday June 23, 2014 @10:09PM (#7935865)
What do you program in? Assembly? Binary? C++ is C with "all the things" tacked on. If you only use the C subset it's pretty bare-bones because, well, it's basically C at that point, and C is an assembly macro.
Re:Why C++ Sails When the Vasa Sank [pdf] by bstamour on Tuesday June 24, 2014 @10:04AM (#7937779)
C++ is indeed a high level language, comparable to, say, C#. Let's enumerate some features that we take for granted in most modern high level languages

1. Type deduction (C++ has it)

2. Lambda functions (C++ has it)

3. Support for OOP (C++ has it)

4. Generics (C++ has it)

5. Static typing (C++ has it)

6. Support for functional-style programming (C++ has it)

7. Support for garbage collection* (C++11 has it)

8. A powerful library of data structures and algorithms (C++ has it, and the library is growing very rapidly as well.)

C++ supports pretty much every feature other high level languages support, but the features are opt-in, that is, if you don't use it, you don't pay for it.

*As far as I know, however, no compilers are currently implementing garbage collection. But the language support is there already.

Re:Why C++ Sails When the Vasa Sank [pdf] by tormeh on Tuesday June 24, 2014 @11:37AM (#7938321)
Being high-level is about more than having features - you also need to lack some features. More is not always more, if you get me. High level languages don't get segfaults. I'm not saying that dangerous behavior should be impossible, just that it should require a conscious decision where the developer is aware of the danger. In contrast C++ almost actively seeks to lead the programmer astray, hampering every effort to create good code. It's not quite the sirens singing to Odysseus - that would be PHP - but it's close.
Re:Why C++ Sails When the Vasa Sank [pdf] by lispm on Tuesday June 24, 2014 @12:01PM (#7938463)
If you look at ANSI Common Lisp, there is no GC support. It is not even mentioned in the standard. But the whole languages is designed to use it by default. C++ is designed to not use GC by default.

Lambdas/closures in C++ are a total hack.

I'd say C++ is a mid-level language with lots of emulations of high-level features. The integration of closures into C++ is an example of that. Just by integrating a high-level feature poorly into C++ does not make C++ high-level.

Re:Why C++ Sails When the Vasa Sank [pdf] by cheez on Tuesday June 24, 2014 @11:44PM (#7942125)
How are they a hack? They are pretty much implemented the way a programmer would write them manually.
Re:Why C++ Sails When the Vasa Sank [pdf] by tomjen3 on Tuesday June 24, 2014 @10:51AM (#7938057)
I disagree with 5 being a requirement for a HLL (otherwise LISP is lowlevel) and will content that C++ lacks 7 since in my mind it GC has to be non-optional and enabled by default. In addition 8 is hardly satisfied by C++, since it has neither an XML parser nor an HTTP library by default (at least last time I checked). I do admit that it has a standard library that is decently designed and much bigger than Cs.
Re:Why C++ Sails When the Vasa Sank [pdf] by EpicEng on Tuesday June 24, 2014 @01:13PM (#7938883)
C and C++ most often,prototyping in MATLAB, Python, and even C# a times. There are a whole slew of languages in between assembly and C++ in terms of abstraction, as well as a whole slew of software applications outside the web and client apps.
Re:Why C++ Sails When the Vasa Sank [pdf] by cheez on Tuesday June 24, 2014 @11:36AM (#7938310)
def doappend_dwim(arg = []): arg.append('a') return arg

assert(doappend_dwim([]) == ['a']) assert(doappend_dwim() == ['a']) assert(doappend_dwim() == ['a','a'])