Live data from Hacker News

Has C++ jumped the shark?

johndcook.com

61–69 of 69 posts

Re: Has C++ jumped the shark?

#61
post #21
post #8

C++ is the only language I'm aware of where every extension made to the language is careful to only affect compilation time/complexity, while preserving the speed and operational semantics of the code at runtime. This makes it perfect for some domains, e.g. console game development, where the speeds required are only attainable by dicking around with pointers in C, but people want to use better abstractions than C is…

This is thing that annoys me about C++'s illusion of control: unless you have / take full responsibility over the compiler and standard library, the "control" that C++ gives you is actually an abnegation of choice which leaves you to reinvent the world if you want specific features. What if you want something like Smalltalk / Lisp images? Runtime code generation and optimization of virtual method calls? Precise garba…

That C++ doesn't impose, but does permit these runtime features is what allows it to adapt to such a wide variety of constrained environments. Baking those features into the language can certainly be much cleaner, at the cost of versatility.

We need system level languages and C++ currently stands alone in its combination of powerful abstractions, low level control, and ecosystem size, though it certainly has competition in these aspects individually.

I don't doubt that a language could be everything C++ is and much cleaner too, but that is a big challenge that relatively few language designers want to take on.

Re: Has C++ jumped the shark?

#62
post #48
post #36

Earlier quoted context omitted.

I don't know who your audience is. I understand that most (about 2/3) of that data is symbol information. The complaint was obviously that a 200 line file generates 8MB of symbols and takes longer to compile than the rest of the project put together. And the existence of this 200 line file is precicely a pimpl attempt to isolate the C++ brain damage as much as possible. Your point seems to just be agreement with mine…

Perhaps C++ will finally become a scripting language. So you don't get to complain about the compilation cost. Seriously, I think it's too much trick to do meta-programming in the language. If meta-programming should be allowed, it should be easier, simpler, and for the ordinary people. Just like Ruby.

I agree very much, good comment. I think meta-programming in a language such as C makes a lot of sense, as you want to be able to generate efficient, compiled code, with as little developer effort as possible. Metaprogramming makes it possible to specialize abstract types, data structures, and so on.

But why does the metaprogramming syntax in C have to be so convoluted, bloated and difficult? Do we really need >30 second compile times per file on recent CPUs? If a language is hard to parse both for computers and humans, something went wrong. It should be easy to read for one of both, preferably both.

Re: Has C++ jumped the shark?

#63
post #60
post #21

Earlier quoted context omitted.

This is thing that annoys me about C++'s illusion of control: unless you have / take full responsibility over the compiler and standard library, the "control" that C++ gives you is actually an abnegation of choice which leaves you to reinvent the world if you want specific features. What if you want something like Smalltalk / Lisp images? Runtime code generation and optimization of virtual method calls? Precise garba…

"What if you want something like Smalltalk / Lisp images? Runtime code generation and optimization of virtual method calls? Precise garbage collection?" What is the point of controlling all of those things? The GP was talking about speed - how are GC, JIT and images related to this?

Precise GC, JIT and images all give you more speed.

Precise GC is asymptotically more efficient than manual allocation; you need to use other approaches, like arenas, to get back that lost time, but they are not always applicable or easy to introduce.

Optimizing virtual method calls at runtime (e.g. monomorphic or polymorphic inline caches) is rather awkward without JIT. Similarly, C++ templates cannot be instantiated at runtime, meaning less efficient, more general and indirected code needs to be used instead.

Images optimize startup hugely: they completely remove the need for any initialization not directly related to acquiring external resources. For example, this is one of the biggest reasons Chrome is so quick to start up - it uses freeze-dried heaps in V8 (its Javascript engine).

Re: Has C++ jumped the shark?

#64
post #31

Earlier quoted context omitted.

How do those features impact runtime performance? One example of templates affecting runtime performance is poor use of the instruction cache due to code duplication in every instantiation of a template.

If you are instantiating equivalent functions (sorting foo* vs sorting bar* ) then the linker will merge their binaries -no dupes there. If you are generating different functions (sorting foo vs foo* ) then you are asking for different functions -no dupes there either. If you want to keep everything down to one function, qsort() didn't disappear when they added std::sort() and it is pretty close to what a dynamic lan…

I believe this is called Identical COMDAT Folding in VC++

Re: Has C++ jumped the shark?

#65
post #58

Earlier quoted context omitted.

Take a look to the Boost libraries and cry. Indeed! The thing I don't understand is that you go to the boost library website and you see that it touts itself as an all-volunteer effort. Who are these people who volunteer their time to produce this massively bloated, over-elaborated code? What is their motivation? What's going on here? I understand bureaucracies usually bureaucrats are paid and produce code and memos…

You shouldn't generalize. Saying 'X' about Boost is like saying 'X' about the US or Europe. There are many different components in there.

OK, I have slogged through quite a few boost libraries looking for stuff to use.

If you can give me an example of a part of this "continent" which is "lean and mean" rather than over-elaborated, I'd be grateful.

Re: Has C++ jumped the shark?

#66
post #51

Earlier quoted context omitted.

My theory is, upon reading his book, is that he knows it as well as all but two or three people anywhere.

Could you please clarify that a bit? That would imply that either everybody knows C++ or that I don't. Thanks!

Sorry for the confusion.

I was trying to say that he (is that you??) understand more about C++ than almost everybody.

Re: Has C++ jumped the shark?

#67
post #63
post #60

Earlier quoted context omitted.

"What if you want something like Smalltalk / Lisp images? Runtime code generation and optimization of virtual method calls? Precise garbage collection?" What is the point of controlling all of those things? The GP was talking about speed - how are GC, JIT and images related to this?

Precise GC, JIT and images all give you more speed. Precise GC is asymptotically more efficient than manual allocation; you need to use other approaches, like arenas, to get back that lost time, but they are not always applicable or easy to introduce. Optimizing virtual method calls at runtime (e.g. monomorphic or polymorphic inline caches) is rather awkward without JIT. Similarly, C++ templates cannot be instantiate…

Ok, but:

1. GC is fast at the cost of using more memory, which it turn slows the entire app down. 2. JIT can do all those optimizations, but how many of them are done in practice? How fast is the software compared to a binary compiled in C or C++? 3. Can be useful, but the only software that I've seen having trouble with startup times in the first place is written in .NET and Java :)

I guess that what I'm getting at is that C++ code is still faster than e.g .NET code even if C# has GC and JIT. In the end that's all that matter, not whether you can do optimization X.

Re: Has C++ jumped the shark?

#68
post #67
post #63

Earlier quoted context omitted.

Precise GC, JIT and images all give you more speed. Precise GC is asymptotically more efficient than manual allocation; you need to use other approaches, like arenas, to get back that lost time, but they are not always applicable or easy to introduce. Optimizing virtual method calls at runtime (e.g. monomorphic or polymorphic inline caches) is rather awkward without JIT. Similarly, C++ templates cannot be instantiate…

Ok, but: 1. GC is fast at the cost of using more memory, which it turn slows the entire app down. 2. JIT can do all those optimizations, but how many of them are done in practice? How fast is the software compared to a binary compiled in C or C++? 3. Can be useful, but the only software that I've seen having trouble with startup times in the first place is written in .NET and Java :) I guess that what I'm getting at…

.NET code is C++ code. The CLR is written in C++. In many ways this kind of argument is pointless, because it's really about a way of creating a piece of software, than particular to any one language. But some languages make life really hard here - in C++, you need to build a runtime.

I'll assert that memory is not normally a constraint in most situations that need to scale (i.e. not constrained clients), these days. (Though I will say I have noticed that Firefox 4 is significantly slower than FF 3 when switching tabs, and I believe it's because of memory reduction optimizations they've put in because of everybody moaning about bloat. I'd prefer it use more memory and less CPU.)

JIT optimizations like PICs? For over 20 years. The benefits are magnified in languages that make many operations virtual, so you see it in things like Smalltalk (very long time), Javascript (Chrome's V8) and Java JVMs (methods virtual by default so it's a win).

Re slow startup - you're deluding yourself if you think there isn't much software that doesn't have startup time issues. I need only restart any machine I have to know how slow initialization is; with HDD transfer rates in excess of 100MB/sec, there's no good reason for it to take more than 10 seconds or so when no hardware has changed. You're simply not aware of how much faster things could be if startup were faster because you're used to how slow everything is. You just know you can't e.g. fork utility X more than 200 times a second in a script, but don't realize it might be 10 or 100 times faster with a different approach.

Re: Has C++ jumped the shark?

#69
post #19

Earlier quoted context omitted.

Several years after I swore I would never work in C++ again, I agreed to do C++ in order to get a job with a company I was really interested in joining. I ended up working on a project that used C++ with lots of rules and restrictions, and it was not too bad except for lots of boilerplate. I would like to see something better come along that has some of the low-level power of C, but also supports sophisticated high-l…

> I would like to see something better come along that has some of the low-level power of C, but also supports sophisticated high-level abstractions Objective C this very well. It adds classes and protocols. Closures can be implemented with blocks. Everything else is the same as in C.

I've been intending to try Objective C for many years now. I like C, I like Smalltalk, and I like Mac OS. Maybe when I finish my degree, but there's no time now.
Post reply on HN