Live data from Hacker News

Five Popular Myths about C++: Postscript

isocpp.org

21–30 of 39 posts

Re: Five Popular Myths about C++: Postscript

#21

> "Unfortunately, there is not a single place to go to look for C++ Libraries." I don't understand this. I code in C++ everyday at the moment (that's a story for another day) so I know the ecosystem, at least for scientific computing, pretty well. With all the changes and improvements being introduced, what's stopping a package manager from being added? The bane of my existence at the moment is the fact that I have t…

Because a package manager for C++ is infinitely more complex than one for a bytecode language like Java or .NET, where theres either a well defined spec (.NET) or a reference implementation (Java, Python) that everyone measures compatibility for?

The first obvious problem is that there is no ABI for the C++ standard library. This makes sharing any kind of binaries plain impossible because exchange of C++ standard library objects between your project and a binary from the package manager will very likely just blow up. So the package manager, right from the bat, has to build every library and every (recursive) dependency of that library on demand on your computer using your C++ development environment. That alone is a herculean task if you consider the number of compilers (GCC (MinGW), Clang, VC, ICC), their respective versions and possible C++ standard library implementations used. And remember: you can't mix and match!

There is a reason even a C++ library such as ZMQ exposes only a C interface, and it's because things become extremely messy very quickly when you are juggling around native code.

Re: Five Popular Myths about C++: Postscript

#22
Sometimes I just wish there would be less ISO standardization process and more new features added to the language. I guess it's not happening because language extension are evil and because maintaining compiler is hard.

But still, I think it would be great to be able to have module right now as an unofficial clang or GCC extension, even if it breaks later. I guess it has more chance happening in the open source realm.

Re: Five Popular Myths about C++: Postscript

#23

Earlier quoted context omitted.

The bane of my existence at the moment is the fact that I have this HUGE Boost dependency in my code, even if I'm only using a few packages... It just startles me that there isn't a single, consolidated package manager... Sincerely, I have never understood this common complaint about C++ (applies to C as well, actually). My OS comes with a huge repo of C++ libraries. For example, there is a separate package for each…

Windows. OSX (to some degree; Homebrew and MacPorts mitigate this). Linux if you want library versions newer than those supplied by the distro, if you want something that's not supplied by the distro, or if you want to be able to handle your build in a distro-independent manner (those "separate packages for each of the Boost libraries" you reference are provided by your distribution; Boost themselves only distribute…

Do you really believe that a C++-specific package manager (PM) repo would somehow be much more up to date than an OS one? Why?

Any PM repo will eventually be missing something you need, and then you will have to compile it yourself, and if you've done that a few times you should have an idea of the difficulty involved in providing a set of compiled dependencies for one system, nevermind multiple versions of multiple systems.

I don't doubt the usefulness of the Python, Ruby, and Node PMs, but those libraries mostly depend only on the interpreter and other interpreted code. It's just so much simpler. The fact that it's all going through an interpreter (compiled specifically for that system by the system PM in most cases!) solves so many of the problems.

Re: Five Popular Myths about C++: Postscript

#24
post #19

Earlier quoted context omitted.

I've encountered each of these myths "in the wild," and I dare say you'll see them thrown up repeatedly here on HN in various contexts. The third item on that list especially is something you can almost certainly see every day in a random HN thread about programming languages (along with counterpoints). In fact, 'safety', of which GC is a subset, is a huge objection, and one of the first, most frequently raised in my…

Note that one can be against a programming language feature without being afraid of them. I think pointers are a bad feature in a programming language because they're not necessary. It's rather unfortunate that Go, for example, supports pointers (which is of course not surprising when you consider who designed it).

You're correct, of course, and I should probably have not used that loaded term.

Re: Five Popular Myths about C++: Postscript

#25

Earlier quoted context omitted.

The bane of my existence at the moment is the fact that I have this HUGE Boost dependency in my code, even if I'm only using a few packages... It just startles me that there isn't a single, consolidated package manager... Sincerely, I have never understood this common complaint about C++ (applies to C as well, actually). My OS comes with a huge repo of C++ libraries. For example, there is a separate package for each…

Using the packaged versions that comes with the OS is very convenient if you can live with the versions you get. This means that you might have to update your application code when updating the operating system. This can be fine for open source development, but it has never been acceptable at any closed source shop where I've worked. We wanted the freedom of not updating things in lockstep.

This is exactly why 'stable' or 'long-term-support' versions of OSes exist. They go out of their way not to break binary compatibility (by not upgrading libraries all the time) so that user code need not be recompiled.

Re: Five Popular Myths about C++: Postscript

#26
post #18

Manual memory in C++ is so cumbersome that is efectively imposible to develop programs with no memory leak bugs in real life. Anyway, the more important fact about C++ is that it is a language complicated to no end, with an insanely bad design on purpose, so a couple of guys can sell consulting services, write books, and the like. The year 2015 is about to come, let's just stop filling the world with such primitive a…

shared_ptr a = make_shared (10); What's so hard about managing that? shared_ptr is basically equivalent to Python garbage collection. Shared_ptr were standardized in 2003, and Microsoft implemented CComPtr way back in the 90s for this easy to use reference-counted smart-pointer concept. http://msdn.microsoft.com/en-us/library/aa266806%28v=vs.60%2... So... yeah. Stop doing manual memory management in C++. Something be…

Correction: shared_ptr wasn't in C++98/03. It was originally developed in Boost, then added to TR1 (in 2005), and finally incorporated into C++11.

One of the major differences between shared_ptr and CComPtr is that shared_ptr is non-intrusive - it can manage anything, even things like ints that don't know anything about strong/weak refcounts.

Re: Five Popular Myths about C++: Postscript

#27

There are a lot of objections to C++, but I've never seen any of the five he mentions. They sound more like strawmen to knock down than real objections by actual users or commentators critical of the language.

Objections from the article.

1. “To understand C++, you must first learn C”

2. “C++ is an Object-Oriented Language”

3. “For reliable software, you need Garbage Collection”

4. “For efficiency, you must write low-level code”

5. “C++ is for large, complicated, programs only”

1. Not a myth. To write your own C++ code, no. To do anything with C++ other people wrote... Yes, you must first learn C.

2. Weird one, I don't remember hearing this one ever. But it'd be a myth on many levels. C++ has some object-oriented features, but it's indeed not an object-oriented language in the original sense of the concept from Smalltalk. But if you see the effort, it can be used as one. It can also be used as a procedural language. Or even as a functional one to some extent.

3. Real myth detected! GC doesn't affect reliability. Manual memory management reduces reliability. In C++, you can do manual or RIAA-type memory management.

4. This one is not a myth. To get best possible efficiency, you do need to use assembler or compiler intrinsics. The difference you can gain is up to 40x (in my personal experience, this case was about vectorization and branch elimination), typically 2-3x, so it's not insignificant either.

5. Myth. You can use C++ for any size complicated program. You can write simple C++ programs, but the language tries very hard to make sure you can't understand a piece of code out of context. You can't even know what your arithmetic operators do without knowing the includes and other context.

Re: Five Popular Myths about C++: Postscript

#28

Earlier quoted context omitted.

Using the packaged versions that comes with the OS is very convenient if you can live with the versions you get. This means that you might have to update your application code when updating the operating system. This can be fine for open source development, but it has never been acceptable at any closed source shop where I've worked. We wanted the freedom of not updating things in lockstep.

This is exactly why 'stable' or 'long-term-support' versions of OSes exist. They go out of their way not to break binary compatibility (by not upgrading libraries all the time) so that user code need not be recompiled.

That just means that forced updates are less frequent. The flipside of it is that you are now stuck with, potentially, ancient packages. No matter how you slice it, being tied to the release cycle of the OS has problems.

Don't get me wrong, there are definite advantages to sticking with OS-provided packages. I do it for all my personal projects, but it's not a panacea.

Re: Five Popular Myths about C++: Postscript

#29
post #27

There are a lot of objections to C++, but I've never seen any of the five he mentions. They sound more like strawmen to knock down than real objections by actual users or commentators critical of the language.

Objections from the article. 1. “To understand C++, you must first learn C” 2. “C++ is an Object-Oriented Language” 3. “For reliable software, you need Garbage Collection” 4. “For efficiency, you must write low-level code” 5. “C++ is for large, complicated, programs only” 1. Not a myth. To write your own C++ code, no. To do anything with C++ other people wrote... Yes, you must first learn C. 2. Weird one, I don't rem…

> the language tries very hard to make sure you can't understand a piece of code out of context

The language goes out of its way to make it possible to write code that is understandable with as little context as possible; type deduction, lambdas, range-based for loops— all of these are tools for reducing the amount of context or number of contexts necessary to understand a portion of code.

The language also allows you to write code that requires an inordinate amount of context to understand, yes. So does C. Hell, so does every other programming language worth using. It's practically impossible to prevent such code from being written without totally crippling the language.

> You can't even know what your arithmetic operators do without knowing the includes and other context.

If you can see that the arguments to your arithmetic operators are numeric (and you should be able to tell without looking outside of function scope), you need no more context. If the arguments are of user-defined types, you need no more context than if a function named "plus" had been used instead of the function named "operator+." If that is not enough context to understand the code, you have a problem with someone choosing poor names for functions, which goes far beyond operator overloading. For example, sure, operator overloading allows for code like

    auto operator+ (string_t a, string_t b) {
        return a.length () - b.length ();
    }
but so what? User-defined functions allow for code like

    void uppercaseify (char* str) {
        unlink (str);
    }
but it would be patently absurd to blame the language for code like that.

Re: Five Popular Myths about C++: Postscript

#30
post #29
post #27

Earlier quoted context omitted.

Objections from the article. 1. “To understand C++, you must first learn C” 2. “C++ is an Object-Oriented Language” 3. “For reliable software, you need Garbage Collection” 4. “For efficiency, you must write low-level code” 5. “C++ is for large, complicated, programs only” 1. Not a myth. To write your own C++ code, no. To do anything with C++ other people wrote... Yes, you must first learn C. 2. Weird one, I don't rem…

> the language tries very hard to make sure you can't understand a piece of code out of context The language goes out of its way to make it possible to write code that is understandable with as little context as possible; type deduction, lambdas, range-based for loops— all of these are tools for reducing the amount of context or number of contexts necessary to understand a portion of code. The language also allows yo…

I guess you don't maintain [legacy] C++ code. Occasionally I have to.
Post reply on HN