I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. It takes me hours to write something that would take less than a minute in Java even though I have experience with plain C. The worst th…
coming from java you probably don't need all that stuff (and you should already know about constructors). you really need to understand the differences between call/return by value and by reference, and RAII - the rest can be left to the library writers.
Nobody Understands C++: Intro (2007)
41–50 of 53 posts
Re: Nobody Understands C++: Intro (2007)
#42It is not that I necessarily disagree with the author but it does seem like he is making it a bit too easy for himself to make his point. Ever since C++ got lambdas, I would say that bind should be considered deprecated. It is more difficult to understand AND cannot possibly be more efficient. The general point stands though. If you try to make everything as general as you can, you are going to make it more difficult…
i don't think that std::bind is that difficult to understand - here's some stuff about it i wrote earlier: https://latedev.wordpress.com/2012/08/06/using-stdbind-for-f...
But surely GP cannot be talking about std::bind in the context of
> Ever since C++ got lambdas, I would say that bind should be considered deprecated
since both came about in C++11.
Given the context of the article, GP is most likely talking about boost::bind, which was intended as a replacement API for std::bind1st, std::bind2nd (which were deprecated in C++11 and removed in C++17), and largely fills the same niche that std::bind does (except with surprisingly many caveats / differences between the two).
Re: Nobody Understands C++: Intro (2007)
#43Earlier quoted context omitted.
coming from java you probably don't need all that stuff (and you should already know about constructors). you really need to understand the differences between call/return by value and by reference, and RAII - the rest can be left to the library writers.
I'm always saddened by the distinction between "user level C++" and "library level C++", but I hope it's gotten better over time. I remember once trying to write my own shared_ptr clone after the release of C++11, and having to learn as I went about why reference collapsing was invented was very, very discouraging.
Re: Nobody Understands C++: Intro (2007)
#44> The comment in question begins “My take on C++ is that the best programs only use a fraction of the features.” The commenter further states that he is weary of operator overloading and templates. > In my experience, people who make comments like the above tend to be people who think they are C++ experts but who are actually only novices. I do not know the commenter personally, so I’m not trying to say anything abou…
> get just as much done with high quality C in half the time. Bullshit. C++ may have plenty of warts, and sometimes people go way OTT with templates (90% of Boost), but there's no way you're writing code as fast in C as C++ unless it involves no string manipulation, pointers, containers, etc. String manipulation alone is so awful in C that there's no way you're right. But throw in smart pointers, collections, JSON, r…
Please keep the quality of conversation high here. Thank you.
Re: Nobody Understands C++: Intro (2007)
#45Earlier quoted context omitted.
Class composition is about reuse. Class inheritance isn't.
That may be the case in practice but it is not literally true, since semantically, inheritance is effectively a form of copy-and-paste in the compiler. It is literally about reusing components written elsewhere. I would argue that both are forms of code reuse, with the latter also having consequences for type checking.
No, not really. The whole point of inheritance is declaring new types by implementing specifying interfaces in a way that specify type hierarchies.
If your goal was code reuse and "copy-and-paste" then nothing would beat composition. If you decide instead to go with inheritance, you have far more requirements to meet that go way beyond code reuse.
Re: Nobody Understands C++: Intro (2007)
#46I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. It takes me hours to write something that would take less than a minute in Java even though I have experience with plain C. The worst th…
The main difference between Java and C++ in the features you listed boils down to a key difference between Java and C++: object ownership and lifecycle management.
Java's "let's just heap allocate the world and let the JVM sort itself out" allows Java developers to be oblivious to the need to actually think about the life cycle of any object at all. That's fine for some uses, and definitely most of Java's uses, but it's also something that prevents Java from even being considered an option in performance-minded applications. It also gets Java developers to develop incomplete mental models of how computers work. For example, a Java developer who does not understand pointers/references is also a Java developer who fails to understand Java's value and reference types. A Java developer who doesn't understand constructors has also more pressing matters to concern himself with.
In C++, there's a conscientious effort to ensure developers have full control over the life cycle of each and every single object ever instantiated throughout an app session. Smart pointers were added to provide clear semantics on how heap allocated objects should be owned and shared. Move semantics were added because developers want to transfer ownership of resources instead of having to deep copy objects around. These features are aimed at performance and memory safety in a language that by design allows developers to handle low-level details if they want to.
Then there's the backwards compatibility. Perfect forwarding is basically syntactic sugar to get rvalue references to work as expected.
> The worst thing is that after it finally compiles I feel I can't be sure if I've followed all the rules and best practices correctly or if it's going to blow up spectacularly and potentially unsafely at runtime.
The same goes for any programming language. You mentioned Java. I know people who work at an unicorn whose hiring process consists of putting together a Java web service, and they outright rejects people who present a project that hasn't been onboarded onto PMD or SpotBugs. We're talking about companies who hire experts and enforce code reviews, and they still enforce the use of linters and static code analyzers.
Re: Nobody Understands C++: Intro (2007)
#47I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. It takes me hours to write something that would take less than a minute in Java even though I have experience with plain C. The worst th…
> I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. The main difference between Java and C++ in the features you listed boils down to a key difference between Java and C++: object owners…
I'm not sure I'm following, are you suggesting that experts don't need static analysers or linters? Or that enforcing linters is not in and by itself a good thing?
Re: Nobody Understands C++: Intro (2007)
#48I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. It takes me hours to write something that would take less than a minute in Java even though I have experience with plain C. The worst th…
> I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. The main difference between Java and C++ in the features you listed boils down to a key difference between Java and C++: object owners…
Basically most of the complexity I mention comes from memory management. It's just a lot of details to know about and keep in your head. It's the price to pay for the flexibility and power.
In Java you need to understand references and object lifecycles or you get memory leaks and slow applications.
Actually, I work on a performance sensitive application and it's written in Java and it's a good choice for it, since the performance comes from algorithmic complexity, mostly from asymptotic complexity. A C++ rewrite wouldn't significantly impact the performance of the application.
Re: Nobody Understands C++: Intro (2007)
#49Earlier quoted context omitted.
> I realized all this class-ification effort was pure waste, since most of it would never be reused. I don't think this is a valid take. Classes are not about reuse at all. They are about encapsulation and specifying types/providing interfaces. > Same with all the idiomatic conversions. What's your complain about idiomatic conversions? > Don't get me started on boost. Why is Boost, or any library at all, relevant in…
> Why is Boost, or any library at all, relevant in a discussion about C++? I don't have a dog in this fight, but I've been following the scene since early 2000s, a lot of boost made it into the standard. FYI.
Some components that have been proposed to be admitted to the C++ standard were also contributed to Boost, but that's about it. There are far more components in Boost that were never even considered for the standard than the ones that were.
Nevertheless, the relevant part is that Boost is not nor it ever was C++, or representative of C++. Conflating third-party libraries and frameworks with the C++ programming language is at best a pointless straw man.
Re: Nobody Understands C++: Intro (2007)
#50Earlier quoted context omitted.
> I find today's C++ extremely challenging to pick up speed for someone coming from let's say, Java. Smart pointers, pointer/references, rvalue reference, copy/move semantics, (perfect) forwarding, constructors, and how all that interacts with templates. It's just so unwieldy complex. The main difference between Java and C++ in the features you listed boils down to a key difference between Java and C++: object owners…
When I mention constructors I am talking about initializer lists and all the subtleties and special cases around them. Basically most of the complexity I mention comes from memory management. It's just a lot of details to know about and keep in your head. It's the price to pay for the flexibility and power. In Java you need to understand references and object lifecycles or you get memory leaks and slow applications.…
That's basically the point: your complain is not really about C++. You're complaining about a computational problem that some programming languages abstract away with a heavy performance tradeoff. Programming languages that allow developers to manage memory will also force developers to think through memory management and object life cycles. This is not a problem caused by or specific to C++. That's the natural consequence of programming computers.
> Actually, I work on a performance sensitive application and it's written in Java and it's a good choice for it, since the performance comes from algorithmic complexity, mostly from asymptotic complexity. A C++ rewrite wouldn't significantly impact the performance of the application.
I'm sorry for being blunt, but if you think performance-sensitive applications stay at the algorithmic complexity level, you are definitely not dealing with a performance-sensitive application. You're just not writing naive code.
To go straight to the point, performance-sensitive applications are applications where low-level details, such as if memory is allocated at all, if an object is copied or not, and if some data is kept in cache, represent critical performance regressions. We're talking about details beyond cache locality, and keeping that cache hot is a critical feature. Algorithms alone don't cut it.
I recommend checking out the talk from Timur Doumler on low-latency C++ to see what I'm referring.