8 ms·
I've been a C++ programmer for 20 years. Having just seen the example of template arguments in lambda functions: 1) I am reminded of this Larson cartoon: http
by verytrivial 6y ago
I've been a C++ programmer for 20 years. Having just seen the example of template arguments in lambda functions:
1) I am reminded of this Larson cartoon: https://imgur.com/gallery/4gR7tX7 https://imgur.com/gallery/4gR7tX7
2) I have a palpable urge to learn Go.
- UncleOxidant 6y agoI've programmed in C++ off and on for the last 25 years. I keep wondering if I should spend the time to level up on modern C++ (C++11,14,17,20) or if I might be better off to just chuck it all and dive into Rust and/or Zig and place my bets there instead.
- speedgoose 6y agoGo with Golang if you want simplicity. Go with Rust if you want a complex but still neat programming language. Rust is much better than C++ in my humble opinion. I use these programming language as a hobby and I don't think I will ever use c++ on a new project again.
- UncleOxidant 6y agoI've never been that impressed with Go - it seems to be missing a lot of modern features. To me, Zig looks nice from a simplicity standpoint and it fits in the systems programming space.
- zlynx 6y agoEverything Go is missing is what makes C++ complicated.
- gumby 6y agoThat is by explicit design. I don’t mean this as an insult: Pike is quite open about choosing a different region of the design space; he had good reasons for it, they just happen not to work for me.
- deleted 6y ago[deleted]
- Gibbon1 6y agoI off and on wonder if Net Core is going to eat golangs lunch outside of google.
- TomMarius 6y agoRead this before you go with Go: https://fasterthanli.me/articles/i-want-off-mr-golangs-wild-ride https://fasterthanli.me/articles/i-want-off-mr-golangs-wild-...
- jfkebwjsbx 6y agoGo is not a replacement for C++ or Rust. It is not an actual systems programming language.
- Ericson2314 6y agoIf you learn Rust or C++20, the marginal cost of learning the other should be trivial. After writing a bunch of Rust, I recently had to learn C++. I've been storing C++ in my brain as "Rust + delta of dubious ideas", which, not to start a flame war, has easily been a better compression algorithm for my brain than storing C++ in isolation. For example: - C++, const is part of the type. Clearly wrong. - Rust, mut is property of variable, or & vs &mut. Correct, but lack of & with mut-polymorphism just causes needless suffering. - Rust construction: good, Rust destruction: bad - C++ destruction: bad, basically like Rust's. C++ construction: bad, matches C++ destruction. (I've been saying for years that drop needs to consume, not borrow the thing to be destroyed, but no uptake :(.)
- vlovich123 6y agoWhat's the issue with Rust/C++ destruction? What do you mean by consume instead of borrow?
- Ericson2314 6y ago`drop(&mut self)` means, strictly going by the types I could call drop twice! We want an `&own` that is like C++'s rvalue references (so we can still drop DSTs) so we can have `drop(&own self)`. This correctly prevents one from calling Drop::drop twice without extra hacks, and demonstrates that the location is completely deinitialized and can be reinitialized to anything. It is also dual to how, seemingly magically, let x; x = foo(); works without Rust thinking there is an old value of `x` to get rid of.
- saghm 6y ago> `drop(&mut self)` means, strictly going by the types I could call drop twice! Wouldn't calling a destructor on an object twice will also compile in C++? I don't really see this as an issue in either language; the solution is "don't ever call `drop`/destructors manually"
- steveklabnik 6y ago
- secondcoming 6y agoDoes anyone actually use Zig in production? I've only ever read about it here on HN. There's no avoiding Rust. It's becoming the jQuery of systems programming. C++ has lost the plot in some respects but you don't, and probably won't ever, end up using all of it. A lot of it is to make it easier to write things like the STL, not your typical end-user program. Learn up to 17, there's some good stuff in there. If someone in an interview gives you some highly complex templatey code snippet to analyse just tell them to go fuck themselves.
- gpanders 6y ago> Does anyone actually use Zig in production? Likely not, or at least they shouldn't, as it still has yet to have a 1.0 release and is undergoing constant changes in syntax and API. However, that doesn't mean one can't take the time to learn it right now. Zig shows a lot of promise for being a real contender in this space once it does have a stable release.
- UncleOxidant 6y ago> Does anyone actually use Zig in production? As I'm mostly retired at this point, I don't really care how marketable skills are anymore. I go for what looks interesting.
- secondcoming 6y agoLucky you!
- chubot 6y agoI agree that C++ has lost the plot, but I find that it's a very good language for code generation. I don't write it directly, but I use its incredible compilers and ecosystem, including multiple profiling and debugging tools (uftrace is a nice one that even dynamic languages seem to lack). I'm translating a subset of statically typed Python to C++: http://www.oilshell.org/blog/2020/05/translation-progress.html http://www.oilshell.org/blog/2020/05/translation-progress.ht... http://www.oilshell.org/blog/2020/01/parser-benchmarks.html http://www.oilshell.org/blog/2020/01/parser-benchmarks.html I use very much a "pidgin" subset of the language -- one that is easy to step through in the debugger! The problem with all these fancy new features is that you're more likely to trip over bugs in the debugger, e.g. incorrect line number information and stack traces. So the generated code doesn't even use operator overloading, which e.g. C++ 11 range for loops require. I want to be able to see everything. Yet I also want to use features like templates, virtual methods, and strict enums, which C doesn't have. ----- Another "modern" project that does this is the Souffle datalog compiler, which generates "monolithic" C++ programs with heavy use of C++ templates: https://souffle-lang.github.io/translate https://souffle-lang.github.io/translate (I heard about it due to its role in prototyping Rust's type system) C++ templates are not fun to write but they have some interesting properties for code generation. ----- So I would happy if we stopped writing C++ by hand. But I do not like the alternative rewriting inferior versions of existing programs/libraries in entirely new languages. They often have new bugs, are slower, and have fewer features. I really like what Zig is doing to reuse existing code (i.e. bundling a C compiler). I think that both Rust and Go ecosystems have led to a lot of fragmentation and redundant efforts.
- gumby 6y agoI did this a few years ago: picked up C++ 17 after a 25 year hiatus by treating it as a brand new language (and by treating its connection to C as you would Java’s connection to C: a distant ancestral relative). Modern c++ is a powerful, expressive language. It’s not a “object oriented” language in the fetishistic sense — I don’t write that many classes comparatively. A lot of generic programming and functional algorithms in my case. And I can couple directly to the iron as needed. Yes there are some unfortunate syntactic issues due to it having evolved from C but that’s how the world works.
- goodcanadian 6y agoI keep wondering if I should spend the time to level up on modern C++ (C++11,14,17,20) Yes, absolutely. I (somewhat recently) did that, and I find modern C++ to be almost like a new language. The "modern" features are very useful and powerful.
- jfkebwjsbx 6y agoLearning up to C++20 if you are an experienced C++ programmer is easy as long as you only use whatever features you learn or make sense for your project. Studying everything new is, of course, a much more ambitious goal.
- doorstar 6y agoThe more I program in Go, the more retroactively irritated I get at C++. A buddy of mine did a few 'brown bag' sessions on advanced C++ templating and my jaw just dropped further and further at each one. Who has the energy for this? It's hard to write, it's hard to read, it's hard to debug. For someone who a) knows what they're doing and b) really needs to squeeze every last millisecond out of the code I suppose they could be useful. It made me want to send Rob Pike a thank you card.
- jandrese 6y agoIMHO if you're messing with templates in C++ you've probably over-engineered your solution. There are a few cases where they can make sense, like in the standard library, but most of the time without them your code will be cleaner and you'll never actually run into the case where they pay off.
- dkersten 6y agoIf you need compile-time stuff that constexpr can't do, then you have little choice. Of course, in reality, its very rare that you "need" compile-time stuff.
- pooya13 6y agoIt is not rare at all to want your program to handle generic output. Templates might not be the cleanest syntax but they do address a real need.
- dkersten 6y agoI wasn’t referring to genetics or saying that templates aren’t necessary or useful, or even that they aren’t common. Those uses of templates are relatively straightforward most of the time. Where templates, IMHO, become unwieldy is when trying to compute things at compile time. In many cases constexpr works here, but my point was that the remaining cases are relatively rare, certainly when you need it (as opposed to just wanting it, eg for performance).
- secondcoming 6y agoI think unambiguous parsing drives the chosen syntax more than pleasing aesthetics.
- firethief 6y agoOther languages manage to be parsable without the syntactic aesthic getting Lovecraftian. I think the other factor in C++ is the how much has been added to the language while maintaining backward-compatibility.
- xfer 6y agoIt's new feature for a standard that's not even out yet. It doesn't matter how long have you been learning C++, unless you are invested in the language design and read proposals.