Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's easy to dislike or hate C++ due to its immense complexity, and programmers like to be able to keep simple abstractions in their head so they can concentrate their energies on their problem domain without worrying about language confusion. With C and many other languages, this is possible as they are smaller languages. C++ on the other hand: is there any language with widespread use that is so deep and complex? However, there are undeniable conveniences to C++ (safety, a good library, much more -- especially functional-style programming with lambdas now) that can speed up your work process, and if you can accept that you will never know the entire language and can just use those bits that make things easier, it is possible to have a healthy relationship with the language. And it offers tremendous room to grow as you get more and more comfortable with it. Few languages allow you to just keep diving in deeper and deeper as you desire, while still letting you get to work right away without being a master. Even template metaprogramming alone is gigantic area of ongoing research -- the stuff you can do with it is mind-bending and unavailable in nearly all other languages. Templates are, after all, one of very very few wholly functional, immutable languages out there. And template instantiation is the underlying force behind many of the modern features like lambdas that allow you to access that power without actually knowing templates well. It's a powerful language for which you must accept its character flaws in return for its abilities.

It's doesn't hurt either that the libraries available in C++ are really cool.



> Few languages allow you to just keep diving in deeper and deeper as you desire, while still letting you get to work right away without being a master.

I find it to be the case with most languages.

> Even template metaprogramming alone is gigantic area of ongoing research -- the stuff you can do with it is mind-bending and unavailable in nearly all other languages.

Your are being a bit hyperbolic. Meta-programming is not necessarily a hard thing to do, but in some languages, like C++ it was made impractical at first. Then, templates introduced some metaprogramming aspects with another layer of Turing-completeness. I can appreciate the usefulness of C++ and how templates contribute to it, though.

> Templates are, after all, one of very very few wholly functional, immutable languages out there.

XSLT too ;-)

> And template instantiation is the underlying force behind many of the modern features like lambdas that allow you to access that power without actually knowing templates well.

Lambdas roamed the earth long before templates.

> ... and if you can accept that you will never know the entire language and can just use those bits that make things easier, it is possible to have a healthy relationship with the language.

Agree.


> Lambdas roamed the earth long before templates.

I'm talking about C++ lambdas, in particular, which are templates under the hood.


> safety

Um, no. C++ can be safer than C (which is an incredibly low bar) but only if you carefully constrain yourself to certain subsets of the language, which is why the web is chock-a-block with byzantine "C++ coding standards" documents describing all the rules you have to follow in order to avoid shooting yourself in the foot.


Indeed that not only you have to follow, everyone else on the project has to follow, as well as every newcomer and every piece of third-party code that is brought in.

"Avoid the parts you don't like" works best for one programmer working alone.


I had an instructor once that insisted on having a single exit point for all loops. "Never use break or continue or return from a loop." The argument was that understanding control flow is more complex when you don't have to deal with these things.

However, those things exist in the language. You can't just pretend nobody is going to use them, because there might be very good reasons to use them, especially in an imperative context.

(Though I suppose if you're grading 100 projects, such a rule might make it easier to get the code structured the same everywhere.)


In the world outside of that instructor's classroom, there are coding conventions which forbid certain things, with excellent reasons for doing so.

Back when ISO C++ was still staffed by people with useful ideas, they invented various more specialized, safer casts that refuse to do "off topic" conversions. These replace the "(type) expr" C casting notation.

A C++ coding convention document can cheerfully forbid C style casts; there isn't any reason to use them.


>only if you carefully constrain yourself to certain subsets of the language

I'm curious which subsets are included in this?


The answer(s) to that question take(s) the form of documents with many dozens or hundreds of pages. For example:

https://github.com/isocpp/CppCoreGuidelines

So not the sort of thing one can answer in-line in an HN comment.


It's not just the complexity. It's the complexity relative to the payoff. It seems like since C++ 98, the language has accreted a ton of new features that add complexity and decrease regularity without really carrying their own weight. Templates are a good example: lots of little features to make template mets programming easier to offset the fact that templates are a poor basis for metaprogramming to begin with.


> if you can accept that you will never know the entire language

As a developer responsible for understanding what everyone else is doing on the same project, no I cannot accept that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: