5 ms·
While I love this paper and this proposal in general, as a C++ developer every time C++ adds a new major feature I get somewhat worried about two things: 1. ho
by qalmakka 2y ago
While I love this paper and this proposal in general, as a C++ developer every time C++ adds a new major feature I get somewhat worried about two things:
1. how immense the language has become, and how hard it got to learn and implement
2. how "modernising" C++ gives developers less incentives to convince management to switch to safer languages
While I like C++ and how crazy powerful it is, I also must admit decades of using it that teaching it to new developers has become immensely hard in the last few years, and the "easier" inevitably ends up being the unsafe one (what else can you do when the language itself tells you to refrain from using `new`?).
- fragmede 2y agoYeah that's because you're not supposed to be using "new" anymore since the introduction of smart pointers in C++11. Std::shared_ptr and std::unique_ptr are preferred. Shared pointers ref count and auto-delete, and unique pointers can't be copied.
- deleted 2y ago[deleted]
- pjmlp 2y agoWhile I share the feeling, I don't feel that my daily languages (Java, C#, TypeScript) are getting that far behind. Even Go is rediscovering that staying simple just doesn't happen for any language that gets industry adoption at scale.
- naertcxx 2y agoI agree with this. Python is now more complex than C++. Python looks as if it is simple, because the syntax looks clean. If you read the new "compilers" [1] in packages like PyTorch, which are unfortunately written in Python, you stare at a huge code base with walls of text, objects calling one another in a maze of ravioli code and generally no help at all to make sense of it all. Compare that to the gcc code bases, where it is always possible to find some entry point to understand the whole thing. [1] "compilers", because despite the huge code base (wasn't Python supposed to be terse?) they preprocess the function graph and then call g++ and Triton to do the actual work.
- gpderetta 2y agoI very much have a love/hate relationship with python, but it does have a significantly milder ramp for beginners. The complexity is relatively well hidden. I can recommend python as a first language to someone that wants to learn to program. I can't do that with C++ with a straight face, unless one is especially interested in the areas were C++ still dominates.
- oldpersonintx 2y agoThere is no alternative to modernizing C and C++ Indeed I wish they were even more aggressive about breaking changes Rust is nifty but there is simply too much existing C/C++ out there and "rewrite it in Rust" is not a serious suggestion Maybe one day we have some cool AI that magically rewrites old C/C++ automatically, but by then I also assume we will have AI-designed languages Until then, we need C/C++ to be maintained and modernized because we are actually running the world with these languages
- Zambyte 2y agoThoughts on Zig? Just not popular enough to fit the bill or are there technical reasons? I bring it up partially because they are not taking a "rewrite it in Zig" approach, they are specifically aiming for incremental migration in mixed C / Zig codebases.
- binary132 2y agoIMO zig is neat but not that much different (for better or for worse) than C and C++. I do really like the comptime concept and wish C had it, and I like it that allocators are explicit in interfaces. There are other things I don’t like about it and I don’t think it has much chance to supplant C or C++.
- pjmlp 2y agoZig is basically Modula-2 for C afficionados, those of us that are confortable with C++ hardly have any benefit from it, those improvements are also on C++ type system.
- naertcxx 2y agoI think the focus on smart pointers is a huge mistake. Code bases using shared_ptr inevitably will have cycles and memory leaks, and no one understands the graphs any more. Tree algorithms that are simple in literature get bloated and slow with shared_ptr. The only issue with pointers in C++, which C does not have, is that so many things are copied around by default if one is using classes. So the way to deal with tree algorithms is to have a hidden tree with pointers and a class that wraps the tree and deletes all dangerous copy methods, implicit and explicit. stdlib++ seems to use that approach as well.
- Slyfox33 2y agoYou actually think managing memory manually using new and delete is easier than dealing with occasional problems with leaking memory using shared_ptr? That seems pretty ridiculous to me.
- naertcxx 2y agoFor algorithms like the ones in CLRS, which are explicitly written and proven with pointers in mind, definitely. As I wrote, the stdlib++ agrees. Read that code and reevaluate your view on whether it is ridiculous. For other graphs, it depends on the specific application. I am not saying that shared_ptr is always wrong, but often it is.
- gpderetta 2y agonaertcxx point is that you shouldn't use shared_ptr for your next ptr in your list (or other node based container) node. It is slow and error prone. Instead the list container itself should own the nodes and delete them on container destruction. I think it is a good point. unique_ptr is better, but still not always ideal.
- account42 2y agoshared_ptr isn't the only smart pointer and definitely shouldn't be used for everything. The default should be unique_ptr which is simple to reason about and a huge improvement over only having raw pointers that may or may not be owning what they point to.