20 ms·
C++ is an absolute blast
- pjmlp 2y agoWhile it is a great language, ir would profit from less "lets code C with C++ compiler" attitude. Basically it is like renaming those JavaScript files from .js to .ts, and keep coding as if nothing else is available as productivity and safety improvements.
- ablob 2y agoHaving read the article, nothing really stands out to me as "C with C++ compiler". It talks about ranges, shared/unique pointers, lambdas... Essentially a lot of things C is lacking. I don't know where exacly the overlap you're insinuating comes from.
- pjmlp 2y agoWhere did I mentioned the article?
- rickmode 2y agoPronoun confusion. The second pronoun is ambiguous. Since we are all “hackers” here, I’ll be pedantic… “While it is a great language…” The “it” pronoun clearly refers to the C++ language, as I’m sure you intended. “…ir would profit from less ‘lets code C with C++ compiler ’ attitude.” The “ir” — presumably a typo for “it” — can refer to the article or C++. Given that this thread is about an article, the second “it” referring to the article is a natural assumption.
- pjmlp 2y agoIt with typo refers to C++.
- thefourthchime 2y agoI feel like an abused spouse after C++. I now avoid: - Inheritance - Reference counting - Threading - Templates - Classes if possible - Hidden memory allocation - Anything that looks clever Anytime I use them I get flashbacks to some mangled mess of templated threaded classes with some memory leak that shows up after 3 days. I remember writing C++ and trying to figure out how the design would work between these classes, I would end up with something complicated and not entirely correct. Eventually, I thought, what if I did this in C? What would it look like, 90% it turns out with 90% less design and code (and bugs).
- pjmlp 2y agoThere is no rule that requires "programming in C++ proper" being equal with using 100% of the language standard. There is a middle layer, without having to keep repeating all the security flaws of coding in plain C.
- unclad5968 2y agoYou don't have to use any of that and you still get lots of nice things like range based for loops, STL containers, algorithms, namespaces, and constexpr.
- xorvoid 2y agoI’m glad someone is having fun in C++. Personally, after >20 years, I have to be done with C++. It’s just a mess. If I really need the low-level control, I can wrangle C (warts and all), otherwise Rust, Python, etc just make me happier.
- pjmlp 2y agoBeware of C23 and later. C is basically going into "we want C++ but without OOP and with templates done via _Generic". Also LLVM and GCC aren't going to be rewritten from C++ into Rust anytime soon.
- bilekas 2y ago> Also LLVM and GCC aren't going to be rewritten from C++ into Rust anytime soon. I'm afraid you underestimate the will power of rustaceans to find literally anything to rewrite.
- pjmlp 2y agoI doubt Cranelift will ever match the only project that has beaten the contribution level of Linux kernel.
- cornstalks 2y ago> Beware of C23 and later. Beware of what? C23 fixed a number of issues. Sure, there are some oddballs (QChar and auto, mostly), but overall I think C23 is an improvement.
- NotGMan 2y agoThe problem with any language trying to replace C++ for larger codebases is that it's not half as powerful as C++. I've often cursed in C# because something that could be done trivially in C++ if impossible and causes the dev to create convuluted C# while it could be trivialy done in C++ due to its very expressive language features. Those 0.1% of the time that you need those extreme features are what makes or breaks the language in PRODUCTION.
- tester756 2y ago>I've often cursed in C# because something that could be done trivially in C++ e.g?
- sidpatil 2y agoWhat are some examples of these C++ features you've missed in other languages?
- pixelpoet 2y agoZig not having operator overloading makes it suck horribly for writing any kind of vector code. If everyone had to write int a = int_add(int_mul(3, 7), 2) etc there would rightly be a riot, but since they're not 3D coders they just don't give a shit. Too bad, Zig looks great.
- pixelpoet 2y agoSorry, one more thing to add to this: Andrew Kelley is obviously a genius, and his talk introducing Zig[0] is in my top 10 of all time technical presentations, for many reasons. But I really do wish someone close to him with a passion for how coding is in many ways applied mathematics, would ask him to please have broader algebraic support for basic operations like +, -, * and maybe divide, with their basic dataflow characteristics. Optimal speed for complex numbers vs std::complex out of the box would be attractive. I understand his point about not wanting to allow every random C++ feature, but in these cases, it isn't a C++ feature, it's language-level basic algebra. In C++ land, ISPC[1] is often what you use when you want top speed rendering perf on SIMD CPUs, e.g. Moonray project[2] Please, just go ahead and define a nice clean API for vectors and scalars like OpenCL provides on its beautiful reference cards: https://www.khronos.org/files/opencl-1-2-quick-reference-card.pdf https://www.khronos.org/files/opencl-1-2-quick-reference-car... [0] https://www.youtube.com/watch?v=Gv2I7qTux7g https://www.youtube.com/watch?v=Gv2I7qTux7g [1] https://ispc.github.io/ https://ispc.github.io/ [2] https://openmoonray.org/ https://openmoonray.org/ Final edit sorry: in the end I love C++ and have been learning Rust mainly out of curiosity. Avoiding C++ quirks one can have few problems and a great time.
- GlenTheMachine 2y agoOK, so I admit I also washed my hands of C++ sometime around 2009 and I am being forced back into for <reasons>, and I had no idea what these auto and lambda keywords were. Can anyone point me to a learning reference that will let me jump the meta programming apocalypse and just get to the good stuff?
- seanthemon 2y agojump into learncpp and choose where to start from, goodluck
- olvy0 2y agoThe "Back to Basics" videos from cppcon are pretty good, IMO. For lambdas: Back to Basics: Lambdas - Nicolai Josuttis - CppCon 2021 https://www.youtube.com/watch?v=IgNUBw3vcO4 https://www.youtube.com/watch?v=IgNUBw3vcO4 Back To Basics: Lambda Expressions - Barbara Geller & Ansel Sermersheim - CppCon 2020 https://www.youtube.com/watch?v=ZIPNFcw6V9o https://www.youtube.com/watch?v=ZIPNFcw6V9o For auto, this one is short and summarizes some of the gotachs: C++ Weekly - Ep 287 - Understanding `auto` https://www.youtube.com/watch?v=tn69TCMdYbQ https://www.youtube.com/watch?v=tn69TCMdYbQ
- eschneider 2y agoThe CPPCON "Back to Basics" videos on YouTube are pretty good. Just pick out the ones you want/need for a good tutorial.
- vitaut 2y ago> C++ has built-in regex now and they're pretty damn good too Sadly, `std::regex` is anything but good (poor performance, lack of Unicode support) and should be generally avoided.
- yodsanklai 2y agoThe linter used at my work insists on not using it....
- fooker 2y agoIs there something wrong with the specification that causes poor performance?
- steveklabnik 2y agoIt’s ultimately a “won’t break ABI” issue: https://stackoverflow.com/a/70587711 https://stackoverflow.com/a/70587711
- johannes1234321 2y agoThe underlying issue is that for the matches the interface relies a lot on heap allocations for the individual matches, leading to a lot of allocations of small regions to copy from the original input. Many other libraries provide a lot more control there. In benchmarks std::regexp often is a lot slower compared to other implementations, independent from the standard library implementation of choice. The big upside compared to all others is that it's always available. But if there is a choice alternatives are often better.
- sumuyuda 2y agoI’m not for sure auto is an improvement. I know it is required for lambdas and it makes it easier to type out a very verbose type, but it really does reduce code readability. I’ve even seen developers use it instead of bool, which is pretty laughable as the they are the same number of characters.
- wk_end 2y agoA verbose enough type - and C++ has plenty of those - is indistinguishable from line noise. There are places where having an explicit type annotation can improve readability, places where it harms readability, places where it doesn’t make much difference one way or another. Giving us the option has been a blessing. All programming calls for good taste, C++ programming calls for it more than most.
- BeetleB 2y ago> but it really does reduce code readability. How about not specifying the type, and letting the compiler infer it correctly and error out when it cannot - like so many other languages do? And those languages are much stricter about types than C++. And auto reducing code readability? Having to figure out the intricacies of a detailed type to write was a huge barrier, and virtually anyone reading the code with a type involving several nested angle brackets would not bother mentally parsing it anyway.
- Leherenn 2y agoI think it does reduce readability in some scenarios. For instance: const auto& processes = getCurrentlyRunningProcesses(); for (const auto& process: processes) { // Ok, what do I do with process now? Is it a pair from a map? A struct from a vector? // If it's a pair from a map, is the key the pid, a unique id, something else? } std::unordered_map<Pid, ProcessData> is more readable than auto here IMO: you don't need to open the definition (or hope your IDE correctly display the type).
- deleted 2y ago[deleted]
- 2y ago
- SloopJon 2y agoThis is a long rant that covers a lot of ground, a lot of which will inevitably be ignored because the letters "C++" trigger people, myself included sometimes. (Skip ahead to "It's Not All Puppies and Butterflies" for some of the complaints.) The author is really impressed by C++11, as am I, after purposely ignoring C++ for the better part of twenty years. I appreciate the shout outs to some packages and libraries to play with, although I still often find it a pain to incorporate other libraries into my projects. (Single-file headers, anyone?) I'm intrigued by FTXUI. And boy, howdy, he's right: cppreference.com is amazing. Python's documentation is pretty good, but I've never seen anything as good as cppreference.com.
- zahlman 2y agocppreference.com is very, very good at being reference, as in the name. Python's documentation is scattershot and incomplete in many places, and lacks a consistent copy-editing style - but it offers good coverage of all kinds of documentation (per the Diataxis framework), not just reference. The people writing that documentation explicitly take that framework into consideration and use it to look for ways to improve. (But it's still a volunteer effort that works basically the same way the code development does, following open-source principles, so.)
- tecoholic 2y agoThe article filled me on a lot of things I didn't know about C++ because I learnt it at school and college, but soon moved to Python/JavaScript for day job. I have been itching to "get closer to the system" for a while now, and learning Rust on the side hasn't been easy. This article gave me hope that, I might be able to do that if I refreshed C++. Hello CMake… or I should probably say, Meson.
- DidYaWipe 2y agoI've had some good times in C++. But for everything that's been thrown into it, I can't believe we're still dealing with header files. That was one of the greatest things about moving to Swift: no more of that BS. But with SwiftUI, Swift has also become "unfun." SwiftUI and Apple's half-assed, broken observation and "reactive" paradigm have made programming a joyless slog.
- badpun 2y agoC++20 has modules, which replace header files completely (unless you use old libraries which aren't available as modules yet). Compiler support is there, but unfortunately IDEs are lagging. If you use modules with Visual Studio, say goodbye to IntelliSense. Maybe they'll iron out the bugs in a couple years...
- DidYaWipe 2y agoWow, that's ridiculous. I wonder if Xcode does any better with them. Now that would be something.
- ModernMech 2y agoC++ has modules for small values of "modules": https://arewemodulesyet.org https://arewemodulesyet.org It's a bit tongue in cheek but: "Are we modules yet? Nope. ... Estimated finish by: Wed Sep 20 2541"
- badpun 2y agoYou can use modules to structure your own codebase. No more need to write headers and think about how to structure your code in terms of compilation units. But yeah, your link shows that practically none of the popular libraries (except STL) can be imported as modules today.
- wiseowise 2y agoC++20 that is not complete in 2025. I don’t know how C++ developers can work in this with a straight face.
- 01100011 2y agoI periodically work on c++ instead of C and each time it follows a similar pattern where I learn about some new c++ trick, think it will make things better, write my code, hit a compiler error, then spend the rest of the day learning why I can't do what I want. Granted, I usually am stuck at c++14, and some of the issues are fixed in future versions but still... I really want to love C++. It gives me a more powerful C that theoretically should improve my output but in the end it carries so much cognitive baggage that I usually end up writing "C with classes" and move on.
- blastonico 2y agochatgpt or copilot helps a lot with that. I usually copy the text and let it decipher the thing for me.
- mithametacs 2y agothey’re still bad for generating any significant body of code. They’re a little bit better about deciphering errors. They’ll still bullshit* you and send you on wild goose chases. *hallucinate if you prefer
- matheusmoreira 2y ago> They’ll still bullshit you and send you on wild goose chases And confidently at that. It can't seem to find the backbone to say no to me either. If I say something like "wait, X doesn't seem to make sense, isn't it actually Y and Z?" it will agree and reformulate the answer as if Y and Z were correct just to placate me. I usually use the LLM to learn new things, I don't don't actually know if Y and Z apply.
- fooker 2y agoC++, like most technology, works better if you put in the work to learn about it. (Admittedly there are languages like python and ruby that buck this trend.)
- 2y ago
- liendolucas 2y agoA bold statement from Ken Thompson on C++: https://m.youtube.com/watch?v=c-P5R0aMylM https://m.youtube.com/watch?v=c-P5R0aMylM
- jonstewart 2y agoEvery time I try to use Rust instead of C++, I'm left asking "bruh, do you even functor?"
- blastonico 2y agoThe amount of high performance, production grade, massively tested libraries written in C++ is unbeatable. I will be honest here, it's easier to improve C++ security by implementing a compiler that produces safer C++ (like Typescript to Javascript) than rewriting everything in any other language (Rust, Zig, Odin, whatever). I mean, could you estimate the cost ($ and time) it would take to rewrite the best audio framework in any other language? (https://juce.com/ https://juce.com/).
- devjab 2y agoZig is great, it’s not aiming to be a replacement for C++ though. One of the awesome things about Zig is its interoperability with C. In that sense it’s more of a Typescript to C than Rust is to C++. I’m still not sure what I think about Rust personally. In my region of the world I suspect it’ll continue to struggle to find any form of adoption as the C++ people seem to have very little interest in trading their decade long experience for Rust. Zig on the other hand is winning the hearts and minds of most C programmers I know. I hope Rust succeeds though. I say this more from a change management perspective than anything else. It’s extremely hard for us to find developers who will primarily work with garbage collected languages but occasionally have to work with either C or C++ when bottle necks appear. Rust makes that much easier, or perhaps less dangerous would be a better term. I’m not sure any of the attempts at making C++ more safe to use is going to really succeed in this regard. Maybe, but I nothing within the C++ community seems to pull in that direction so I doubt it. I’d like to mention that I’m aware that Zig isn’t helpful in this regard either as it’s not memory safe.
- coderenegade 2y agoZig's interoperability with C really is a stroke of genius. That and the fact that it tries to focus on simplicity with no hidden control flow. It's a fine line to walk, because there's always a tradeoff between abstracting things away to make the code more readable, and tucking potentially critical flaws away out of sight. But so many of C++'s edges come from that hidden control flow, and quirks around things like initialization, ownership, and even things like assignment that less experienced programmers take for granted (if they've ever thought about it at all). And I say that as someone who uses C++17 both professionally and privately, and enjoys the language.
- FpUser 2y agoAgree. Sure there are problems here and there but I think that overall modern C++ is likely the most versatile tool in the "compiled to native, can do anything" family
- byyoung3 2y ago[flagged]
- blurbleblurble 2y agoUsing c++ after learning rust feels like picking through moldy bread
- hypeatei 2y agoUsing C++ after Rust made me appreciate the latter a lot more. You quickly learn all the footguns that the compiler stops you from doing and is generally a good learning experience.
- ModernMech 2y agoThis is what I feel as well. I liken it to using an aimbot in Quake. Turn off the aimbot and you still win because the aimbot trained you how to get headshots. There are many times the Rust compiler told me I couldn't do something I had insisted would be fine, only to ponder and realize in fact what I was doing would cause subtle bugs in an edge case. Rust catches it at compile time, C++ allows you to write the code and sends you a segfault when the subtle edge case occurs in production.
- chowells 2y agoSegfaults in production are the good case. They're when the system recognizes you've made a mistake and stops it from propagating. The bad cases are when the program keeps running but silently does the wrong things.
- spacechild1 2y agoYes! This can be a real problem when your data structures are allocated from a memory pool. Since the whole memory region is owned by the program, out-of-bounds writes will either do nothing or silently corrupt your program state.
- ModernMech 2y agoThe good case is that you catch the error in development and it doesn't even get to production.
- aleden 2y agoFor the love of God when will c++ compilers finally be able to output template errors that aren't completely expanded and are written in terms of the user's typedefs? Most of the time I spend parsing template errors with boost is just to figure out what the hell is being complained about.
- ModernMech 2y agoI have found LLMs are a great tool for metaprogramming. I think the template error problem has been wanting for a sufficiently advanced compiler, and that's what I see LLMs as being. ChatGPT has been a great help in debugging programs I've written in C++ templates, both in generating the template code and trying to decipher errors generated, leading to suggestions for the template code rather than the expanded syntax.
- aleden 2y agoYeah, totally. I find LLMs are very useful for doing stuff with the preprocessor, too. ChatGPT taught me how to use boost preprocessor (BOOST_PP_FOR_EACH_PRODUCT). Still though, I want to see MyMapType::value_type in compiler errors rather than... Well, you know. It's going to contain the type of the key, the type of the value, the type of the allocator, just when all you want to really know is that it's a pair<key, value>, which I think most people know of as My map type::value_type.
- wk_end 2y agoWeren’t concepts supposed to fix this? Apparently they made it into the 2020 standard. I haven’t touched the language in many years - did they not help?
- andrewflnr 2y agoConcepts did not actually make it into the standard. I vaguely recall they were cut at the last minute or something.
- 2y ago
- ryao 2y ago> I want you to ask yourself an honest question. When was the last time you actually had fun in programming? Every time I write C code.
- binary132 2y agoFor me, C is fun until I hit a certain level of abstraction complexity involving fake homespun vtables and it starts getting harder than it should be to chase down bugs.
- ryao 2y agoUse ASAN: https://en.wikipedia.org/wiki/Code_sanitizer https://en.wikipedia.org/wiki/Code_sanitizer
- NooneAtAll3 2y agoevery time I write C code, I don't want to remember how to implement unordered map
- kragen 2y agoYou mean enum { nb = 1024 }; struct { int k, v; } hash[nb]; // 0 is an invalid key void incr(int k) { int i = k % nb, j = i; do { int k2 = hash[i].k; if (k2 && k2 != k) { i = (i+1) % nb; continue; } hash[i].k = k; hash[i].v++; return; } while (i != j); abort(); } Apologies for the telegraphic variable names and weird control flow. I wrote this on my cellphone. Lacking these 15 lines are what keep you from writing C? There's a nice tutorial on hash tables in K&R, and I can also recommend learning about Chris Wellons's "MSI" hash table design, described in C at https://nullprogram.com/blog/2022/08/08/ https://nullprogram.com/blog/2022/08/08/. He shows a more full featured hash table in about 30 lines of code, depending on what functionality you need. It's eminently practical, and usually a lot faster than generic algorithms. That's not an exceptionally simple hash table either. One night I hurriedly wrote a rather long-winded implementation also on my cellphone (strings, with separate chaining and a djb-style hash function) and it also came to about 30 lines of code: http://canonical.org/~kragen/sw/dev3/justhash.c http://canonical.org/~kragen/sw/dev3/justhash.c
- 8f2ab37a-ed6c 2y agoCome write products on top of Unreal Engine, you will have the opportunity to dive into 20+ MLoC of real time C++ goodness. Make sure it's a multiplayer experience for bonus points, eventual consistency makes everything extra exciting. It gives you an appreciation of just how unlikely we're to ever move away from the stuff, short of an LLM innovation that can digest codebases of that size and do an automated port, which I suppose is not outside of the realm of reality these days.
- IshKebab 2y agoThere's too much wrong in this rant to list...
- ModernMech 2y agoI think we can start with "C++ is not popular enough to attract the weirdos". Presumes C++ is not popular and also popularity attracts weirdos. If anything, weirdos are attracted to languages that are not popular at all. I remember once I was on a small language project and this guy on the mailing list wouldn't stop going on about how our language had to support vorpal math.
- nayuki 2y ago> C++ Is An Absolute Blast No, it's one of the worst languages I ever used. Tons of footguns and bad design choices everywhere. Too much cognitive load for less benefit than other languages. I'm surprised the article didn't mention <iostream>. The f.fail(), f.eof(), f.flags() are confusing and verbose. Even something as simple as f.read() doesn't return the number of elements read, so you need to make a separate call to f.gcount(). And then there are all the opaque types like std::streamsize, std::mbstate_t, etc., where you have no idea how their sizes relate to language types like int/long/etc. or fixed-width types like int32_t/uint64_t/etc. https://en.cppreference.com/w/cpp/string/char_traits https://en.cppreference.com/w/cpp/string/char_traits And then there are the redundancies. int x = 0; int x(0); int x{0}; all roughly do the same things but have subtle differences in more advanced use cases. This recent thread ( https://codereview.stackexchange.com/questions/294784/c20-robust-file-interface https://codereview.stackexchange.com/questions/294784/c20-ro... ) reminded me that `typedef` got replaced by `using`. A while ago, I came up with a long list of near-duplicate features: https://www.nayuki.io/page/near-duplicate-features-of-cplusplus https://www.nayuki.io/page/near-duplicate-features-of-cplusp... > JavaScript still can't even figure out what a for-loop is ECMAScript 6 added the for-of loop, which is the more useful alternative to the for-in loop. > C++ has lambda, and it's not bullshit like Python's lambda C++ lambdas have a heavier syntax than any other lambda I know of (e.g. Python, Java, JavaScript, Haskell, Rust), because it needs to specify attributes and captures. https://en.cppreference.com/w/cpp/language/lambda https://en.cppreference.com/w/cpp/language/lambda > My thinking is C++ is now about as good as any other language out there Not by a longshot. Instead of C++, I reach for Java if I want fast design time, safe operations, and a more limited set of tools (e.g. not needing to decide how many layers of pointer indirection I want). I reach for Rust if I want the power of C++ without its footguns. Heck, my motto for Rust has always been, "C++ done right". Every time I compare analogous features in C++ and Rust, I find that the Rust version is much better designed. As the simplest example, in Rust it's a compile-time error to use a variable whose value is moved out, whereas in C++ the variable is still usable but has an invalid value. Another example is that Rust has traits but C++ relies on instantiating templates and then "duck-typing" to see if the resulting code can actually compile. And let's not forget nullptr, the trillion-dollar mistake - C++ makes nullptr implicitly part of every pointer(*) type, but Rust bans it by default unless you opt in with Option<T>. Rust has other quality-of-life features such as easily declared tuple types, the unit type instead of void (which makes functional programming easier as you don't have to special-case void), pattern matching and unpacking, methods on primitive types (e.g. 456u32.isqrt() instead of sqrt(456)). I just can't look at C++ seriously when Rust is miles ahead, being more expressive and safer. > The Amazing Comeback of C++11 I will agree with this in a limited sense When I write C++ code (because I'm a masochist), I will not tolerate anything less than C++11, because C++03 and C++98 are much, much worse. I'm talking about things like various types, standard library classes/functions, unique_ptr, and move semantics.
- halfcat 2y agoI recall not being very effective with C++ for years, and then someone recommended the book Large Scale C++ Software Design, and that was a big unlock. I didn’t use 80% of what’s in the book, but just having a comprehensive way of structuring the code was a massive productivity boost. Looking back, I suspect it was less that it was “the right way”, but just that it was “a way” and most of the benefit was it kept me from overthinking and got me to work. Later with C++11, I kept having this thought, “in Python this would be way less verbose”, and I started writing C++ that looked more like Python, creating whatever helper functions Python would have (mostly simple stuff, string handling, etc). That was one of the most productive seasons of programming I ever had, and I still get tempted to write stuff in C++ that Python is better suited for, just because the benefit of not overthinking is that significant (at least for me).
- andai 2y ago>But, C++ kept evolving, and the standards committee seemed to realize that if they don't do something they'll become an obscure language only used by a single 10 trillion dollar industry. How pathetic! Which industry is this referring to?
- brabel 2y agoMy guess is that it's the game industry, because it's probably worth that much and is almost pure C++.
- metaltyphoon 2y agoThe game engine industry is pure C++. Most games are written in C# just because of Unity
- ajuc 2y agoThe stuff you use for work is not fun. The stuff you use for fun is fun. There, I solved the mystery for you. If you choose technology for work by what is the most fun - you enter a hedonist treadmill. Stop. JS framework insanity lies that way. No cool technology will save you from burnout.
- klysm 2y ago[flagged]
- derriz 2y agoI was C++ dev for 5 or 6 years, up to the late 2000s. I got another C++ job about 3 years ago but bailed after about a year. I could write a tome about what I dislike but to start with, any language that lacks a working standard built-in string type, is just a hard no for me at this stage in my life. Life is just too short. The tooling and IDE support is atrocious, no standard dependency management for 3rd party libraries and CMake makes maven look well designed. I tried to pull my knowledge up to date. Hmmm, we used to have lvalues and rvalues, what's this prvalue thing? Surely cppreference can explain: > a prvalue (“pure” rvalue) is an expression whose evaluation > - computes the value of an operand of a built-in operator (such prvalue has no result object), or > - initializes an object (such prvalue is said to have a result object). > * The result object may be a variable, an object created by new-expression, a temporary created by temporary materialization, or a member thereof. Note that non-void discarded expressions have a result object (the materialized temporary). Also, every class and array prvalue has a result object except when it is the operand of decltype;* > The following expressions are prvalue expressions: > a literal (except for string literal), such as 42, true or nullptr; > a function call or an overloaded operator expression, whose return type is non-reference, such as str.substr(1, 2), str1 + str2, or it++; > a++ and a--, the built-in post-increment and post-decrement expressions; > a + b, a % b, a & b, a << b, and all other built-in arithmetic expressions; > a && b, a || b, !a, the built-in logical expressions; > a < b, a == b, a >= b, and all other built-in comparison expressions; > &a, the built-in address-of expression; > a.m, the member of object expression, where m is a member enumerator or a non-static member function[2]; > p->m, the built-in member of pointer expression, where m is a member enumerator or a non-static member function[2]; > a.*mp, the pointer to member of object expression, where mp is a pointer to member function[2]; > p->*mp, the built-in pointer to member of pointer expression, where mp is a pointer to member function[2]; > a, b, the built-in comma expression, where b is an prvalue; > a ? b : c, the ternary conditional expression for certain b and c (see definition for detail); > a cast expression to non-reference type, such as static_cast<double>(x), std::string{}, or (int)42; > the this pointer; > an enumerator; > a non-type template parameter of a scalar type; > a lambda expression, such as [](int x){ return x * x; }; > (since C++11) > a requires-expression, such as requires (T i) { typename T::type; }; > a specialization of a concept, such as std::equality_comparable<int>. > (since C++20) > Properties: > Same as rvalue (below). > A prvalue cannot be polymorphic: the dynamic type of the object it denotes is always the type of the expression. > A non-class non-array prvalue cannot be cv-qualified, unless it is materialized in order to be bound to a reference to a cv-qualified type(since C++17). (Note: a function call or cast expression may result in a prvalue of non-class cv-qualified type, but the cv-qualifier is generally immediately stripped out.) > A prvalue cannot have incomplete type (except for type void, see below, or when used in decltype specifier). > A prvalue cannot have abstract class type or an array thereof. Yeah, this language is loads of fun. I've worked on compilers, interpreters, implemented extended Hindley-Milner type systems, etc. so normally love reading formal language specs but this is just insane.
- TrianguloY 2y agoI've had a similar situation with Kotlin. I've always been a java developer, and I enjoy using it, but even with the newer features it's just...slow. When I had to script things I chose JavaScript (native JavaScript) since it's way faster to iterate, but I've always missed the static typing (I also know python, but I honestly prefer JavaScript) Until I learned Kotlin. It's been a blast to use, incredible common libraries, streams everywhere, nulls that you can use without issues...I just love it (so much in fact that I'm in the process of switching project from java to Kotlin). When I need to do scripts, like for the advent-of-code, I choose Kotlin.
- adra 2y agoI also really enjoyed the jump into Kotlin as well! That said, I'm also very happy with recent java versions trying very hard to close the gap. It does feel like at least half of Java's recent major lifts have been to emulate things done well in other languages (a great attribute for a self-aware language developer). I definitely never appreciated a lot of their newer feature choises like records until I saw them working really well in Kotlin data classes.
- shmerl 2y agoC++ is fun, but "Rust weirdos" are right. Don't use C++, use Rust. That's all.
- wiseowise 2y ago> Need package management? Check out Conan, Meson's WrapDB, and vcpkg. No, just no. All of them are complete, utter crap that doesn’t hold a candle to languages that were designed with packages in mind. We’re using Conan at work, I’ve been using vcpkg at home and I loathe both. > I mean, do you really think Python's package management is top notch? You do? Why are there like 10 package managers then? Worst Python package manager runs circles around whatever C++ offers.
- synergy20 2y agowhat's wrong with vcpkg? looks good to me
- Philpax 2y agoI don't think we need to pretend Python package management is good to contrast C++, they're both awful for different reasons. At least there's maybe a way out for Python (uv / the various PIPs); C++ doesn't appear to have any kind of plan whatsoever, outside of gesturing in the direction of modules.
- amelius 2y agoIs anyone still using the Boost libraries?
- spacechild1 2y agoYes! Boost.Asio is still the go-to networking library. (It's also available as a standalone, though.) Some parts have been adopted by the C++ standard library and can thus be considered obsolete, there a still quite a few goodies!
- nurumaik 2y agoYes, it gives me free coffee breaks every time I compile my code
- ironman1478 2y agoC++ really is a blast and I think the complaints people have about it really depend on context. Lots of C++ devs hate that language but imo misdirect their hate. They actually work on legacy products built by people who were never that great at writing software. This happened to me with Rust actually where I was thrust into an existing rust project at the company I work for. It's an "old" codebase with many different and conflicting conventions within it (different error handling types that don't compose well, bad class abstractions, lots of unsafe block when not needed, etc). The project was the most miserable project I've ever worked on and it's easy for me to blame Rust, but it's really just bad software development. There are warts in C++, but a lot of the pain people run into is just that they are working on crap code and it would be crap in any language.
- psyclobe 2y agoThis 1000%, stop blaming the tools!
- mrcsd 2y agoHow can we make better tools if we don't blame tools?
- zdragnar 2y agoEh, I'm reminded of the old "programming languages as weapons" comic, with the one that I still remember is JavaScript was a sword without a hilt, with the blade being the "good part" and in place of the hilt, another blade labelled the "bad part". You can blame devs instead of tools all day long, but you can't deny that there are things about the tools that hold the developers back.
- nvarsj 2y agoTrue - but it’s much easier to make an incomprehensible mess in more complex languages. Whereas blub language projects are pretty easy to decipher regardless of the state of the codebase.
- zahlman 2y agoI really can't resonate with this. The type system is obnoxious (and you don't even get proper memory safety out of it), the "most vexing parse" truly is vexatious, there's all the weirdness inherited from C like pointer decay (and then building new solutions like std::array on top while being unable to get rid of old ways of doing things), and of course the continued reliance on a preprocessor to simulate an actual module import system (and the corresponding implications for how code for a class is organized, having to hack around with the pimpl idiom etc....) Essentially, the warts are too large and numerous for me to find any inner beauty in it any more.
- wkyleg 2y agoI learned C++ and enjoyed it but never went too deep. I always enjoyed C more. There's also so many S tier codebases to read to learn C better like the original Dune game engine or Unix utilities. Having dabbled a bit with Rust recently I can't see any strong reasons to use C++. The combination of strong functional programing inspired type system with performance seems unbeatable. Almost a perfect language. I'm sure there must be some legacy reasons to use C++ though. Maybe Game Engines, embedded programing, some kind of other legacy tie in?
- PartiallyTyped 2y agoHFT perhaps?
- wkyleg 2y agoI can see that. On most metrics I've seen Rust is comparable on general speed. Maybe if you're at the level where you've essentially writing portable assembly and are okay with lack of safety. You need to know exactly what is happening within the CPU, maybe on custom hardware. I bet some defense applications would be in this category too, although for my own sense of self preservation I would prefer the Rust type system.
- gpderetta 2y agoRust would probably be a good fit for HFT, but as the field is so dominated by C++ is hard for another language to make inroads. Java managed to some extent. I would expect a lot of unsafe though.
- cempaka 2y agoEcosystem effects are definitely important to C++'s dominance in HFT, but it's also a domain where a lot of the guarantees Rust offers just aren't all that relevant. From a security perspective most code always runs in sandboxes accessible to only a select few whitelisted IPs. True, you don't want a segfault while you're in the middle of sending an order to an exchange, but most of those are pretty easily smoked out in simulation testing.
- indigoabstract 2y agoI really love how politically incorrect this post is. And how honest and fresh it sounds, though quite a few have been quick to say how wrong he is. They could be right, but I think it misses the point. Yes, it's way too easy to do dumb stuff in C++, when you're tired or not sure what you're doing. Things like holding raw pointers or references to things you shouldn't like std::vector::data(), or questionable reinterpret casts and many other things. The compiler won't stop you, only your experience. But he's right about one thing at least: Programming should be fun! All these layers and rules and concerns about memory safety and security don't offer only advantages. They also have tradeoffs. And it's the same thing with those scrum agile ceremonies. It serves its purposes. But it's also the best invention ever to suck all the joy out of programming. I think that both C and C++ still have that fun feeling going for them. When you know what you want to work on and how to do it and you just start doing it and get into the flow. And if you're careful and do things right, it just works and it's a blast! That's my takeaway from the article. That feeling like you're talking directly to the machine, getting it to show you on screen what you saw in your mind, without anything else getting in your way. Now, that is fun!
- zahlman 2y agoProgramming should be fun. I don't think that's controversial or politically incorrect. (Or if it is, I don't know why.) A lot of people don't naturally have the kind of fun in C++ that Zed describes, and it seems most people here (including myself) would rather talk about that.
- indigoabstract 2y agoIt's controversial because of how he makes fun about the people using and promoting other languages, like Rust. I thought it was hilarious. And in case you haven't noticed, C++ isn't seen in a good light anymore for some years now. There are a lot of loud voices saying its time has past and calling for it to be replaced with something newer and better. It's all subjective anyway, but I resonate with the feeling of fun he describes when doing projects in C++. Feeling productive and being protected from whole classes of bugs common in C++ is all well and good, but he was talking about programming being fun and I do not get that same feeling when programming in other languages. It's perfectly understandable that you don't feel the same way though. I hope you do when programming in your favourite language. Otherwise it becomes just something you do to pay the rent.
- avalys 2y agoIf you're starting a new project with a talented team that knows how to use modern C++ well, I agree that C++ is great! It's a pleasant and powerful language, delivers great performance and (while complicated) is straightforward to debug and optimize. I had the privilege of working on a codebase that was about 5 years old, written to C++11 standards or later, and I thoroughly enjoyed it, for many of the reasons expressed in the article. If you are working on an older codebase that has evolved over 20-30 years, or one that has not been maintained by talented people, you will have a very different experience.
- creato 2y ago> If you are working on an older codebase that has evolved over 20-30 years, or one that has not been maintained by talented people, you will have a very different experience. I'm trying to think of any other language that could fit that description and not also be a terrible experience. In fact, I'd prefer C++ to many other possibilities I can think of (C, Java, Fortran). The exception would be C#, but I'm not sure if it's old enough to fit.
- avalys 2y agoFair point, although I think it's true that C++ gives you more rope to hang yourself with, and if I had to choose, I'd rather maintain a crusty old codebase written in Java than one written in C++.
- snovv_crash 2y agoThe issue is that the JVM has started deprecating features which old codebase rely on. I don't work with it, but even I know about the JVM no longer supporting sandboxing or being able to kill threads programmatically. C++ doesn't have this issue because you can still deploy code from an old toolchain onto a modern OS.
- adra 2y agoYou can and always have been able to .destroy() threads in java, but doing so breaks the memory model in ways that make it clear that you should never do it. My guess is that if you're kill heavy in c++, then you've also run into bugs waiting on locks of threads you've now just murdered. That's why there's a ton of great abstractions for how to "kill work running somewhere else" that doesn't leave your application in a potentially unstable state. Java 9+ sure did kill off a lot of things that weren't particularly ideal. Most normal devs who don't write libraries probably can't even name a single feature removed (corba, script interpreters, some jmx cruft, etc). Most of what was culled still exists in libraries that could easily be added back with project imports. Maybe Java applets are super dead now? I don't believe any modern browsers still support native plugins, but maybe there are some niche individuals bemoaning the loss of java web start. As for the "can still deploy code" comment, the same applies to java. Look around, and sadly you see very old releases of java still in use today. My guess is that if I fired up a java 1.0 compiler and JVM today, it would run on my PC (poorly). Before criticising something, please consider being well enough informed to warrant the comment.
- runjake 2y agoCan anyone recommend some good “modern” C++ books in this spirit (writing software for fun, not large enterprises)? Preferably for Linux and/or Windows.
- rramadass 2y agoNot sure about what you mean by "fun" but Peter Gottschling's Discovering Modern C++ An Intensive Course for Scientists, Engineers and Programmers is pretty good. For a catalog of shiny new C++ features Marius Bancila's Modern C++ Programming Cookbook is comprehensive.
- chubot 2y agoIMO the way to make C++ fun is to: 1. Build and run it with a shell script (because the build systems do suck) Dependencies may complicate this, but you can still link with them with a shell script And use Unix – I started with C++ on Windows, and that sucks (also mentioned in the article) 2. Turn on address sanitizer in development, which makes it memory safe – you get a Python-like stack trace on errors instead of undefined behavior Example: $ echo 'int main() { return 42; }' > foo.cc $ c++ -fsanitize=address -o foo foo.c && ./foo; echo $? 42 I use an actual editor, and unit tests, but essentially shell is my REPL for C++. It’s easier to figure out that way. Newer features like constexpr have subtle rules, so it’s easier to just try it (even though I’ve used C++ for many years). I run all the tests with Clang too. --- Example with ASAN: $ echo 'int main() { char buf[1]; buf[1] = 42; }' > error.cc $ c++ -fsanitize=address -o error error.cc && ./error; echo $? ==118199==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7ffcd94eb431 at pc 0x56217647520f bp 0x7ffcd94eb400 sp 0x7ffcd94eb3f8 WRITE of size 1 at 0x7ffcd94eb431 thread T0 #0 0x56217647520e in main (/home/andy/git/oilshell/oil/error+0x120e) #1 0x7f7928446249 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58 It’s not too hard to learn to read the output, and then basically you can go nuts like C++ is Python. For a small program, the edit/run cycle will be extremely fast, like Python. The silent undefined behavior is a big barrier to learning, and this removes most of it. (You can also pass -fsanitize=undefined for UBSAN, which finds other bugs, but many fewer IME) ASAN is built into compilers; you don’t need to install anything. A bare Debian or BSD system has all this good stuff :-) (copy of lobste.rs comment)
- epolanski 2y agoA well written blog post that makes many valid points but comes with a wrong assumption: that making a language creativity-friendly is an absolutely desirable trait. It's a desirable trait for my personal projects, where I may use Haskell, Ruby, Ocaml, Racket or something more exotic. At work, I'd rather use languages that are boring, with well defined and uncreative patterns and practices. Professionally I expect to not be surprised often and I want the smallest group cognitive load possible. Languages that breed too much creativity tend to have a rather short list of killer software (that kind of software that makes it worth learn a specific programming language).
- barbazoo 2y agoI feel that way with Ruby vs Python sometimes.
- zahlman 2y agoI wonder if Zed started using, or went back to, Perl after getting so worked up about the 2 -> 3 transition. (From what I can tell, he's still complaining about it, and still wrong in many of those complaints, and makes unsubstantiated claims in others.)
- bnolsen 2y agoI worked with c++ for many years and it has lots of warts. Slow compilation, lack of decent build system (no cmake isn't that great), mistakes made in the standard library (iostreams), weak cross platform standard libraries were always a headache. But I always loved the power that <algorithm> and the like provides, although attaching allocators (and other template things) kind of sucks. When I looked at and test drove rust all I saw was heaps of complexity stacked up yet again. Probably didn't help that I smacked headlong into the Arc Mutex and lifetimes mess. I'm really more inclined to go for something like 'zig' which does so much with simple syntax (and awesome comptime) and still gets excellent performance.
- marssaxman 2y ago> no cmake isn't that great Nor is cmake even really a standard: after thirty-odd years writing C++, I've yet to work on a project which used it!
- PittleyDunkin 2y agoThat's pretty damn impressive! How did you manage to avoid codebases with CMake? Or are you just saying you personally chose not to use it for your own?
- marssaxman 2y agoIt simply hasn't come up: none of the teams I've ever worked on have chosen CMake. I've certainly encountered & compiled libraries which use it, but I've never had any reason to edit a CMakeLists file myself. Of course CMake has only really been a practical tool for 20-ish of those 30-odd years, and "Modern CMake" was only published twelve years ago; it's definitely gained a lot of popularity over the last decade, but the idea that CMake is the default C++ build system, not just one among many, still feels to me like a recent change.
- funny_falcon 2y agoIt seems meson is gaining traction and will overpass cmake in near future.
- readyplayernull 2y agoI returned to C++ after 20 years to program ESP32 microcontrollers. The Arduino Framework is compiled with C++ 21... wait, what? Well that's the value of __cplusplus = 202100L Glad to find the standard library progressed so much to make C++ more similar to modern languages, but sometimes I wish there was a simpler way to access the std namespace. Any proposal to replace "std::" with $
- lairv 2y agoI just spent 3 days to statically link a third party dependency to my C++ project, in a way that works with linux/windows/macos. The package wasn't available on conan/vcpkg, it was just a github repo with a weird combination of Makefile/cmake file. While I'm far from a cmake/cpp expert, this is a non-issue with most modern languages: you just pip install, cargo add, npm install, go get etc. You can read front-to-cover books about every details of C++ semantics and it'll still be a PITA to work on real world projects
- 77pt77 2y agoThe javascript toolchain for dependencies and build is as arcane as the sloppiest Makefile. It's amazing that we ended up with the javascript equivalente of autotools.
- agumonkey 2y agoyeah, dealing with npm really made me feel like the best part of autotools
- dannymcgee 2y agoCreated an account just to say: I am a 10-year JavaScript veteran who knows the ecosystem at least as well as any sane person could possibly be expected to, and this is 100% correct. When I tell people that JS build tooling is the second-worst headache to C/C++ build tooling, they laugh, but stick a toe outside the happy path of `npm create <some-framework-project> && npm start` and you will know what pain feels like. I did get some similar vibes trying to work with Gradle and Maven for a project a while back, but I don't really live in that world so it's hard to say whether my experience was typical or just symptomatic of my inexperience.
- smarkov 2y agoAnd it'll continue to get worse because JS devs love coming up with their own abstractions over everything and piling complexity. You don't write JS, you write TS. You don't write HTML, you write JSX. You don't write CSS, you write Tailwind. And of course, React has its own compiler as of recently. Now you have to figure out in what order to run these parsers, bundle everything together including your hundreds of dependencies, minimize, obfuscate, tree shake, and whatever else fairy dust magic you want to sprinkle on top. Meanwhile, the default build tool of choice changes about once every 2 years, and now you also have a choice of runtime - node vs bun vs deno. Can't wait to see what the next revolutionary idea would be to contribute to this madness.
- _zagj 2y agoI had a similar reaction returning to C++ a few years ago, and getting exposed to stuff like lambdas, smart pointers, and template metaprogramming painpoints being fixed. One especially nice thing about C++ is GCC, which lets you use relatively recent features even on obscure HW/OS architectures that other, trendier languages ignore. For example, you can use modern C++ features, at least upto C++17, on OpenBSD.
- jimberlage 2y agoEvery article like this I scan to see if the author had previous C++ experience. And every article, they do. I will be very impressed and curious if I find a glowing article about C++ from someone who didn’t grow up knowing it as a smaller, simpler language. The C++ community needs enthusiastic converts who didn’t do it back in the 2000s if it’s going to stay relevant.
- unclad5968 2y agoI learned c++ after c++20 and after several attempts to enjoy rust, c#, go, and C, I always come back to c++ as the most enjoyable language to develop.
- jimberlage 2y agoNice! If you blog at all your perspective would be super interesting to hear.
- NooneAtAll3 2y agoI'm gonna be weird and not engage in language war (I love c++) but, dear author: > +95% of the compiler errors this. this is unforgivable +X means "additional X". As in "I have Y and I add +X to it". When you are invited to an event, your invite states you can take your +1 with you (one more person that will come within the same invitation) if you want to say "more than", you use X+ !! as in "95%+". Because you have some X amount, and you add some more to get X+... get it together. you're awesome
- anentropic 2y ago> I remember insane discussions with people who thought adding two numbers with a template was "faster" than adding two numbers directly, even though the assembly language output was exactly the same. I know almost nothing about C++ and have never programmed in it... but I thought that the point of that kind of 'template metaprogramming' was that the code got executed at compile time instead of runtime? i.e. instead of generating identical assembly output the goal would have been to output a constant value
- sour-taste 2y agoAs per usual with c++ it depends. In some situations things are guaranteed to be compile time evaluated. E.g. even in early templates this would need to work: Func<1+2>(); Something like this there's no guarantees around: template <A, B> int Func() { return A + B; } For almost all compilers it should constant fold this into a constant but in theory it could end up with an add instruction. Basically we can't second guess the author here because it depends on the specifics.
- andrewflnr 2y ago> I firmly believe that for creativity to blossom you need to be able to get your idea out without fear of criticism and shame. This section is, it seems to me, the linchpin of the "fun" argument. But you've been able to do that with all the other languages too, all this time. The much-loathed and feared Rust Evangelism Strikeforce doesn't actually come to your house and make you use a bunch of generic-heavy code from crates.io. The React people can't stop you from using vanilla Js. The worst they can really do is send you mean tweets, but Shaw thinks this is a lethal threat to his creativity, enough to switch language ecosystems over. For an article written in a superficially rebellious, lone-wolf tone, that's kinda sad.
- ratmeadow 2y agoThis article seems kinda confused. It makes a lot of points, but I'm struggling to extract why that means C++ is more/less fun. The simultaneous description of modern C++ as "extremely high quality" and yet pervasive legacy bs, horrible tooling, etc is confusing. They say unique_ptr is great yet they "really hate RAII". Many of the discussed topics are largely irrelevant or incorrect. Metaprogramming used to be everywhere but now isn't (what?? Take a look at concepts)? C++ has the best graphics libraries (surely not true)? Installing Python is harder than C++? These seems like odd obsessions of the author, with little relation to the argument. I think the author just finds C++ fun for some complex combination of personal factors, which is fine. Perhaps partly due to a "hacker" type personality. Some of the most fun I've had with programming has been C++, due to its performance and technicality. At the same time, C++ is in practice crap for "real" software development where your own short-term enjoyment is not paramount (for a billion reasons we all know). C++ is a deeply conflicted language, scarred by decades of legacy and politics. Ignoring the reality of C++ is the biggest mistake of those who discuss it. My attitude towards C++ these days is of tiredness. I don't want to jump through the hoops C++ has thrown at me for the past many years. We don't need to beat an already long dead horse. It's ok to let C++ be what it is.
- mst 2y ago> I think the author just finds C++ fun for some complex combination of personal factors, which is fine. Perhaps partly due to a "hacker" type personality. I think that sums up the point of the article just fine. To me at least, it's not so much that it's confused as that it's him being excited about having fun and doing his best to share his joy. Which means that, sure, it's not a proper essay at all, it's not really trying to convince you to agree so much as saying "if you find this relatable without me trying to actively convince you, maybe you'd find it fun too." I think given you've been mugged by reality in commercial work to the point of tiredness, your not finding it to make sense at all is completely understandable, though. I'm currently having a blast writing javascript of all things, and I imagine if I wrote up a similar blog post explaining why it'd come across just as badly to somebody burned out on the last decade of commercial javascript too. But I'm glad he's having fun, and I'm glad he decided to share the joy.
- PittleyDunkin 2y agoI am a bona fide C++ hater, but that's just because I resent working on it for professional code that needs to work reliably with coworkers I don't entirely trust. For personal projects it's one of the most satisfying coding contexts I've ever worked and it is indeed a blast to have such fine-grained control over execution. I abandoned the language about a decade ago and I don't see myself looking back. My projects these days need long-term reliability more than anything and rust + cd/ci hits a sweet spot. That said, I do miss the thrill of designing and executing a program that runs in a certain way exactly as I intended and knowing that it was my expertise and insight that allowed this execution. Would I want to work with someone that was driven by that? Hell no! But it is personally a joy I won't forget. Other inexcusable pain points: the build systems and package management is an absolute nightmare; the pre-processor feels like a sadistic joke; the syntax is horrible; there's so much cruft in the runtime you need years of experience to not machine-gun your foot off by using the most obvious tool at your disposal. But in a sense this just increases the joy of shipping a working executable with all your cleverness and blood and tears wrapped with a bow.
- nnadams 2y agoKudos for one of the most relatable descriptions of C++ I've read. I did a couple years writing C/C++ professionally, and I hope to not go back to that. Too many hours debugging other people's code, suffering vague integration issues, and just trying to get the build system spaghetti to run.
- mempko 2y agoWork should be fun too, not just personal projects. I've noticed that over the last 10 years, the tech world has seemed to lose this idea. I blame this on the large tech companies who seem to take the best people and put them in an adult prison. Granted a prison with good food and soft chairs. Even startups seem to be less fun. It seems the VC world foments a narrow window of thought with a lot of copy cat startups doing the same thing. Fads, lots of fads. I use C++ for every new project because I know if I need to build something myself, I can do it. Using frameworks all the time sucks because frameworks never work the way you want. Especially if it deals with the core of the project. If you can build it yourself, then do it, otherwise use a framework. And if you can build it yourself, C++ is a great tool because it can do everything and doesn't get in your way in all the important ways. Meaning, I can express my mental model directly in C++, where a language like Rust might complain I'm doing an unsafe thing. Sometimes I think in pointers damned and pointers are a great thing! Lets bring fun back! Not just in our personal lives, but work too!
- Animats 2y agoThe fundamental problem with C++ is that it has hiding ("abstraction") without safety. That's rare. - C -- No hiding, no safety - Python, Javascript, LISP, other interpreted languages -- hiding with safety - Pascal, Ada, Modula, Rust -- hiding with safety - C++ -- hiding without safety. C++ is, decades late, trying to get to hiding with safety. But there's too much legacy.
- gpderetta 2y agoWell C has functions. Isn't that the original hiding abstraction?
- pornel 2y agoIt is an abstraction, but the safety requirements are neither enforced nor abstracted away. C's type system can't communicate how long pointers are valid for, when and where memory gets freed, when the data may be uninitialized, what are the thread-safety requirements, etc. The programmer needs to know these things, and manually ensure the correct usage.
- everyone 2y agoC++ is great, but I hate .h files.. I'm kind of shocked that some tool to automate writing .h files isnt the the standard.
- moth-fuzz 2y agoI'm of two minds when I see comments complaining about header files. Practically speaking, I think "have the preprocessor copy & paste source files together" is a bit of a hackjob, but, conceptually speaking, having your interface and implementation separate is ultimately a good thing. The problem of course lies not with header files, but C++ the language, as all public fields and private fields must be specified in the class declaration so that the compiler knows the memory layout. It's kind of useless in that sense. You can move private methods out to a separate source file, but, you don't gain much in doing so, at least in terms of strict encapsulation. And of course, if you use templates at all, you can no longer even do that. Which is its own can of worms. Unfortunately, none of these problems are problems that modules solve. Implementations very much disagree on interfaces vs implementations, precompiled vs simply included, etc etc. In my own usage of modules I've just found it to be header files with different syntax. Any API implemented via modules is still very leaky - it's hard to just import a module and know what's truly fair for application usage or not. You still ultimately have to rely on documentation for usage details. At the end of the day I don't really care how the implementation puts together a particular feature, I care about how it affects the semantics and usability of the language. And modules do not really differ in proper usage from headers, even though the whole backend had to be changed, the frontend ends up being the same. So it's net nothing. All said and done, when it comes to defining library APIs, I prefer C. No public/private, you just have some data laid out a particular way, and some functions to operate on it. The header file is essentially just a symbol table for the binary code - and said code can be a .c file or a .o file or even a .a or .lib or .dll or whatever - C doesn't care. Raw functionality, raw usability. No hoops.
- holografix 2y agoTl;dr programming as a hobby building what and how I want is much more fun than doing it for money and being told what to do.
- globalnode 2y agoI have the luxury of only writing software for myself, which is almost always Python, but after reading this ill go back and have another look at C++. Did one big project in C++ after uni but then never touched it again.
- 8n4vidtmkvmk 2y agoIt takes some getting used to. I wrote it for about 10 years then didn't touch it for 10 years and now I write it full time again. Took a few months to get up speed again and stop shooting myself in the foot.
- akoboldfrying 2y ago>I really hate RAII. I'm baffled by this. Deterministic destruction (necessary and basically sufficient for RAII) was one of the best design decisions in C++, I think. RAII means you can't forget to clean up a resource. You don't have to type anything for it to get cleaned up at the right time, it just happens. It's basically what GC promised developers, except for all resource types, not just memory. Your code gets shorter and more correct. I'm extremely curious to hear how this could ever be bad.
- AnimalMuppet 2y agoRAII isn't just about the destructor, though. It's about writing the constructor in such a way that you can always safely destroy the object. If you don't write the constructor right, RAII might become something you really hate, because it could blow up on you any time the destructor fires.
- akoboldfrying 2y agoI meant that it's wonderful to use RAII classes that others have developed, rather than implement RAII classes for others to use. But now that you mention it: >It's about writing the constructor in such a way that you can always safely destroy the object. I agree, but I see this as a good thing, even though it makes the class slightly harder to implement than it might be if responsibility for getting the object into a state safe for destruction is dumped on (or even shared with) the calling code. The latter approach requires programmer discipline at every use -- but you will only implement the class once, and probably use it many times.
- AHTERIX5000 2y ago"I really hate RAII" but smart pointers are great?
- g42gregory 2y agoFor me, it's basically C++ for low-level, Python for high-level, Java for insanely large corporate codebases, JavaScript (oh boy...) for the Web. Tons of better languages are out there, but they lack the same level of support, tooling and libraries' availability.
- EVa5I7bHFq9mnYK 2y agoThere were 91 occurrences of the word "rust" in 264 comments so far.
- sseagull 2y agoOnly 7 instances of “footgun” (or a variation) though. HN is slacking - must be the holidays
- teleforce 2y ago> Well, actually the Rust weirdos will bother you but they're usually too busy making the borrow checker happy to actually get anything done so you can ignore them. Ouch...
- medo-bear 2y agoI plead the 10th https://en.m.wikipedia.org/wiki/Greenspun%27s_tenth_rule https://en.m.wikipedia.org/wiki/Greenspun%27s_tenth_rule
- donedealomg 2y ago[dead]
- doug_durham 2y agoThe metaprogramming metapocolypse resonated with me. In the late 1990's the entire software world got "pattern disease". Yikes. We are still paying the price.
- thdhhghgbhy 2y ago>shame grifters Love this. This is an old post though right, still talking about C+11?
- anothername12 2y agoI think I will take another look. I recently helped my grandson with his university C++ assignment. It was a lot better than I remember C++ in the 90s. Fun wise though, I get the most fun with dynamic languages that are highly interactive like Forth, Common Lisp and Smalltalk. I don’t have to drop out of the zone to kick the compiler all the time.
- jebarker 2y ago> I recently helped my grandson with his university C++ assignment. That is awesome. I hope if my kids have kids i'll be of some technical use to them too!
- nixosbestos 2y agoShout-out to the Rust users rolling their eyes in this thread, but keeping their mouth shut out of fear of being labeled as a Rust evangelist or something. I find these discussions hard to take very seriously. Even in this thread some people nodding at Rust are implying that C++ is easily/regularly faster which is really a take, given nearly every single RIIR example/benchmarking I've seen so far.
- mihaaly 2y agoI was smiling throughout : ) (it is a good smile)
- rperez333 2y agoQuestion for pros: I'm a Python dev who recently started diving into C++, hoping to build plugins for DCCs. However, every time I read these threads, I feel as if I'm on the completely wrong path. Positive views like the OP's are rare. While I understand that not everyone gets to work on a John Carmack level codebase, is working on a C++ project really as challenging and unrewarding as it seems? Is the productivity that low, and do every step feel so difficult that they eventually drive developers away?
- koiueo 2y agoI couldn't get rid of a (borderline cringy) feeling that the author is whining about all the idiots around them, which usually indicates some problems within. It all became clear by the end of the post — the author is a Windows user. My gut feeling wasn't wrong. Give me my 20 minutes back please.
- IYasha 2y agoI can't believe I can agree this much with a C++ article. My thoughts precisely. But whenever _I_ brought up the crazy angle-brackets::madness period in language's history, most devs tended to disagree. I rarely follow fads anyway. But there's a downside to C++ as I still see it now: steep learning curve in tooling. I am used to work on legacy projects with long lifespan (mostly infinite, not that I look at it :) ) and kinda got lost when tried to contribute to a modern project (I'd call it a hipster project): the amount of abstractions in build/management tools was terrifying. CMake, for example, is and abstraction over an abstraction above another abstraction. And they used an abstraction over CMake! It also required Python. And not the one available in my OS. I admit, I'm more used to cursed MSVC projects and simple Makefiles. But when CMake starts its dirty work, it's like a black hole of weird scripting and endless pulling of hopefully compatible dependencies you can hardly control (yeah, where does MSVS store that pulled and precompiled garbage? Oh, shi- it's in %userappdata%??? what about other users? What if I want it on a different drive, like MY project?). CMakeLists.txt has a syntax of it's own, and a really obscure one: is it declarative? Are those commands? When does the order of lines matter? Why are CMakes so incompatible? What are those vars? How is any of that online documentation useful? How do I make things work as I want?? And it still doesn't because some required repos have moved, are offline or became incompatible. The infrastructure surrounding my helloworld.cpp was getting SO immense, but it never built as... in the end I was required to upgrade to Windows 10 or 11, which I'd never do, so... This is the sad non-C++ part of C++ programming that I utterly hate.