4 ms·
> You'll find crap in C++ like const *const char &, and hell if anyone knows what that really means since even though the pointer to a const to a const referenc
by hdevalence 13y ago
> You'll find crap in C++ like const *const char &, and hell if anyone knows what that really means since even though the pointer to a const to a const reference is consted to hell and back, oh look you can still increment it. They'd have been better off to just invent a new keyword: doesnotfuckingchange and stop there.
As I recall, Stoustrup originally wanted to call the const keyword 'readonly', which is a more accurate description of what it does (const data is not constant, it's read-only: something else can change it while you're not looking, but you can't change it). They didn't, for compatibility reasons with C.
That said, the const keyword allows you to move contracts about, e.g., "this method does not alter its object", from the programmer's head into the code where it can be checked by the compiler. (unless you have people doing stupid things with mutable or const_cast).
But yeah, C++ has flaws. Big flaws [1]. Anyone who tells you otherwise is probably uninformed or lying. The interesting question is, why do people keep using it in spite of its flaws? Certainly a large part of that is inertia, but I don't think that that's the only thing. I think there's a niche where there's really not a lot of good options other than C++, and that's quite unfortunate. But "C++ sucks" removes the possibility that there's anything useful there, making discussion of better alternatives (e.g., would D work? what is it about C++ that makes it useful? how do these languages compare? etc.) impossible. See, for example, Rob Pike's complaint about why C++ programmers aren't all moving to Go, which essentially ignores a bunch of reasons why you might use C++ (since Go is not a replacement for them). See [2], [3].
[1]: http://bartoszmilewski.com/2013/09/19/edward-chands/ http://bartoszmilewski.com/2013/09/19/edward-chands/
"I’ve been looking for a good analogy of what programming in C++ feels like and I remembered this 1990 Tim Burton movie, Edward Scissorhands."
[2]: http://blog.grok.se/2013/10/on-comparing-languages-c-and-go/ http://blog.grok.se/2013/10/on-comparing-languages-c-and-go/
[3]: http://commandcenter.blogspot.se/2012/06/less-is-exponentially-more.html http://commandcenter.blogspot.se/2012/06/less-is-exponential...
- catnaroek 13y ago> But yeah, C++ has flaws. Stroustrup dixit: "Within C++, there is a much smaller and cleaner language struggling to get out." Rust? > The interesting question is, why do people keep using it in spite of its flaws? Certainly a large part of that is inertia, but I don't think that that's the only thing. Ownership management. Which has been expanded into full lifetime management (including that of borrowed pointers) in... Rust! Static polymorphism. Which is implemented in a crappy way in C++, but at least is doable: 1. Non-specialized templates: Type constructors. 2. Concepts (sadly only in the heads of programmers): Type classes. 3. Exported typedefs and type traits: Type families. > See, for example, Rob Pike's complaint about why C++ programmers aren't all moving to Go, which essentially ignores a bunch of reasons why you might use C++ (since Go is not a replacement for them). Dude must be completely deluded.
- hdevalence 13y agoYeah, Rust is really interesting, and something I'd like to try on a real project. Hopefully I'll be able to do something with it this spring. But it's certainly more appealing as a replacement than, say, Go, which I don't think is really even that interesting as a language (but this is a personal opinion which I'm not willing to argue about on the internet). Rust also would immediately solve some things I find particulary annoying about C++ (lack of sum types, inability to create new types that behave identically to old types, etc). One thing that I think would be nice to have in a hypothetical language is vector support for integral types, the same way OpenCL has. The Eigen library for C++ is IMO a really good example of the "Edward C++hands" phenomenon. It's a terrific library, using C++ template magic to produce optimized assembly for your platform, to achieve performance you just can't get with C. On the other hand, it can be annoying to use, since there are places where the C++ warts come out, and the developers have to put in an extraordinary amount of effort just to get there. If you had this kind of thing built into the language, it's much easier for everyone involved: compiler authors, programmers, library developers, etc.
- charlieflowers 13y agoThat's cool. Do any of the new wave of systems programming languages offer this kind of capability? D, Rust, Nimrod, etc.?
- vinkelhake 13y agoPeople keep using C++ because there aren't any real competitors in its niche. It offers the same performance level as C, while having substantial improvements: namespaces, templates, RAII, operator overloading, type-safe containers. These are things that can help raise the abstraction level, while not giving up performance.
- colin_mccabe 13y agoThere are many "real competitors" to C++. The biggest one is C. Many things were written in C in recent years: the Postgres database, networkmanager, pulseaudio, the Linux, BSD, and Mach kernels, zeroMQ, sshd, Xfce, Gnome 2 and 3, the list goes on and on. You may not like it, but people chose to write these things in C when C++ was available. Similarly, Apple chose to base most of MacOS on another non-memory-safe, (usually) non-garbage collected systems programming language: Objective-C. We can debate the merits of these choices, but to deny that they exist is just prima facie incorrect.
- vinkelhake 13y agoSure, there are many competitors to C++ and that's not something that I'm contending. What I said was that there aren't any real competitors in its niche. If you want more powerful abstraction features, while preserving C-level performance, there aren't many real options. If you don't want or need those things, then C is a perfectly good choice. There are many other languages that raise the abstraction level, but most do it at a performance cost. As for Objective-C, I'm fully convinced that it would be an obscure niche language today if it hadn't been for Apple basing OS X on NeXTSTEP. I don't see it as a competitor to C++ unless you're actually working in the Apple ecosystem.
- ___1___ 13y agoI am C++ programmer. As you may be too. C++ has one big flaw the way I see it, and that is, it is incredibly difficult to learn well and it's very easy to teach badly. I have been programming C++ for many years now, I still look back on code I wrote a couple of years ago and can see how my style has development, and I won't even dare review the code I wrote whilst learning the language. That said, once you've straddled to learning curve, I really do believe that it is a great language for more than just niece core of use cases. Having learnt it there would be very few cases I would use C over C++, nor would I use an other compile "General purpose" programming language, like Java , D, Go or C#. The "next level up" for me is scipting with python or bash and the step down is asm or inline intrinsics. I am happy with C++ in the middle of that wide chasm.