6 ms·
I think what makes C++ so challenging for me isn't C++98, C++11, C++14 or whatever comes next. The challenge for me is that I need to know the superset of all t
by arcticbull 11y ago
I think what makes C++ so challenging for me isn't C++98, C++11, C++14 or whatever comes next. The challenge for me is that I need to know the superset of all the features (and past 'features') at the same time, doubly so to interoperate with existing code or libraries.
The more gets layered on without taking anything away the more difficult it is to reason about your code let alone that of anyone else. And without taking anything away, all the cool new features can't defend you at all, they're just more rope.
The challenge for me is just how much context C++ forces me to hold in my head at any given time. And thanks to operator overloading, I can't trust anything I see -- when you can change the meaning of the comma operator, any piece of code can do literally anything other than what it looks like.
Ultimately, I stopped developing in C++ because there's just too much cognitive load for me. In a professional setting you're not coding for yourself, you're coding for you 6 months from now, and that guy has know idea what kind of tricks you were playing back in the day.
- pjmlp 11y ago> And thanks to operator overloading, I can't trust anything I see -- when you can change the meaning of the comma operator, any piece of code can do literally anything other than what it looks like. I always laugh at this complaint specifically against C++. Except for Go and Java, all other mainstream languages allow for either operator overloading, or symbolic names for functions/Methods. Even JavaScript ES7 might get them, http://51elliot.blogspot.de/2015/01/fluent-talk-summary-brendan-eich.html http://51elliot.blogspot.de/2015/01/fluent-talk-summary-bren...
- Gankro 11y agoThere's a difference between overloading `+`, `-`, `<<`, (which must obviously run custom code when applied to custom types), and overloading `,`, copying, assignment, moving, and tons of other "already works on everything" operations. Both can cause problems when used inappropriately, but the latter is just chaos.
- jawilson2 11y agoHow would you handle deep vs. shallow copying and assignment for classes without overriding those operators?
- kibwen 11y agoIn Rust, the = operator always represents a shallow copy (for types with move semantics, it will also statically invalidate the source) and there's no way to override this or otherwise permit user-defined code to run. Deep copying is done via a standard method, `.clone()`, which makes it obvious that user-defined code is running.
- Gankro 11y agoMy answer to that is "you shouldn't want to deep copy on assignment". It's a performance trap and makes the code harder to understand. Without pervasive copy/assignment/move ctors you would be surprised to see how little you actually want to explicitly invoke them (usecases may vary, of course). Sadly this is the path that C++ has taken.
- AnimalMuppet 11y agoShallow copy on assignment is dangerous because it leads toward double frees and therefore chaos in your heap. Ironically, the original topic (upthread quite a ways) was pointer safety...
- steveklabnik 11y ago... however, Rust's semantics specifically prevent this double free.
- AnimalMuppet 11y agoWhich, if we were talking about Rust here, might be relevant. But in this thread of the conversation, we're talking about C++ operator overloading and why you need it for deep copying on assignment. In the immediate context, how Rust does it is not relevant.
- fauigerzigerk 11y agoThat's all true. But there's a dilemma we can never completely avoid. The more expressive power a language gives you, the more productive you can be when you really know the code in and out. The same expressive power will make it more difficult for others or for your future self to understand what the code does. It's always going to be a trade-off. The more focused you are on one piece of code, the more it makes sense to use an expressive language. The more you switch between projects, the greater the developer turnover, the dumber the code needs to be in order to stay close to maximum productivity. If we really want to have an impact on productivity, we need to change how teams are put together and stay together.