| ▲ | Ask HN: Do you still enjoy coding in C++? | |||||||||||||||||||||||||||||||
| 38 points by hasley 4 hours ago | 46 comments | ||||||||||||||||||||||||||||||||
In the recent years C++ received a lot of backlash due to its complexity and (perceived) feature creep. However, since C++11 I really enjoyed writing C++ with its strict type system (including const), range-based for loops, smart pointers, and how much you can do with templates. On the other hand, I know that it can be very tricky to write, for instance, a correct iterator, to get handling of rvalue references right, or to read error messages that involve templates. So, do you enjoy or dislike writing C++ source code and why? | ||||||||||||||||||||||||||||||||
| ▲ | chris_j 2 hours ago | parent | next [-] | |||||||||||||||||||||||||||||||
I'm really torn about C++. I love C++ but there are things that I really don't like about it as well. It's a fantastic language in a lot of ways, but it carries around 40+ years of cruft, of things that you wouldn't do like that if you were inventing a programming language today. I haven't written C++ professionally for many years at this point, and my memories of using it professionally (pre C++ 11) are not happy ones: having to agree on a strict subset of the language that we were allowed to use, which avoided features that any of the compilers didn't support well, or that my teammates didn't like. Sadly back then the list of forbidden features included templates and namespaces. But using C++ on personal projects nowadays, and being able to choose which bits of the language to use - and which to avoid - is much more enjoyable. And honestly, the language did get a lot better from C++ 11 onwards. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | gignico 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I love C++, in the C++11 days I even organized a local C++ User Group at my university, and I've used it for the last 20 years as my main language. I still appreciate its many merits but since a bit more than a year I migrated to Rust and I find it very difficult to look back, except for maintaining my previous C++ projects. Surprisingly, it's not Rust's memory safety features that I miss the most when turning back to C++. It's mostly the absence of algebraic data types and pattern matching, and the split between compile-time and runtime polymorphism, i.e. concepts vs virtual classes, where in Rust you just have traits and use them for everything. On top of that the tooling and the ecosystem are just amazing. There's a proposal for pattern matching sitting there under the committee's desk for some years now. With the mess that the standard committee is going through I really doubt they will be able to ship pattern matching for C++29 or even later. Too little too late. So to answer the question, yes, I still appreciate the merits of C++ but I don't enjoy writing it as much as I have in the past. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | adev_ 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
In one word: Power. C++ is by far the most powerful language around. And this is for the best and (often) also the worst. In term of generic programming, control on hardware, capacity of abstraction and more generally expressivity: Nothing, even today, come even close to C++. It is a language full of foot guns and it has its fair share of legacy problems. But if you learn to avoid it (throught experience and pain). You can reach a productivity and a level of performance in C++ which is very difficult to beat with anything else, including Rust. Ironically, I find it particularly true in the age of A.I. Because the amount of C++ around is so tremendous, that agents are currently pretty good at it if guided properly. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | dotdi 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I agree that C++11 was a big step. This was around the time I was working on a master's thesis, building a distributed optimization framework based around simulated annealing, using hand-optimized CUDA kernels on Nvidia CPUs. Writing CUDA code became a much nicer experience with C++11, and I didn't hate it. However, it was still a bad choice for all the plumbing, caching, networking, job-management, etc that a useful framework needed, and I started using more and more Python. C++ was frustrating for those bits. Eventually, after some important work on Numba[0], I was able to replace C++ completely, even for the CUDA kernels, and just write a subset of Python. It wasn't without it's (often quite esoteric) problems, but I was happy to throw out the last bits of C++ code. The thesis was praised and had some outside attention, but fizzled out in the years thereafter. | ||||||||||||||||||||||||||||||||
| ▲ | mort96 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I enjoy writing C++ code. I acknowledge that C++ is a bad language in a lot of ways, but it's a bad language which I know really well, and it fits with how I think about code. And it lets me effortlessly do "clever" things with how memory is managed to avoid unnecessary allocations etc. I've already learned most of its idiosyncrasies, handling rvalue references/move semantics, how to go about implementing contracts like iterators and containers, etc. I also like writing Rust, and I like how Rust makes sure I don't make mistakes. I think Rust is a better language in many ways and I think it's the future of low-level programming (and I think it's wild that it took so many decades to get a proper competitor to C++!). But I also like how C++ doesn't care and lets me do whatever I want without acting as a nanny. I would never ever dare to write a publicly exposed web server in C++, but a game? Sure! | ||||||||||||||||||||||||||||||||
| ▲ | simonask an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Oh, C++. C++ feels like an old lover who I think fondly of. We were together many years, until about C++20, through thick and thin. It was exhilarating - blazingly fast, perhaps irresponsibly so, but heck, the ride was wild. It taught me so many things, and shaped me into the programmer I am today. But we went our separate ways when its shortcomings became too large to bear, and its behavior - too often undefined - no longer excusable. I keep up with it because I still have love for it, but I have to admit I am deeply concerned about many of the life choices it is making. I should have seen how problematic it was, because I knew its history, but I had hope that it could change, and it just looks like it never will. I'm still rooting for C++, even though I am very happy with my new primary language, Rust. I hope it changes to the better, because I really want the best for it, but right now I'm just not seeing it. It keeps repeating old mistakes (e.g., more UB footguns with every new feature), without addressing any of the big flaws (insufficient tools for building robust software). I sometimes still write C++, but I'm not excited about it the way I used to be. When I do write C++, it's because I have to. When given the choice, Rust is simply just a better choice for almost everything I do. Right now, I don't see a future for C++ and me. | ||||||||||||||||||||||||||||||||
| ▲ | zagal an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I only used it for bare-metal embedded and Linux user space where efficiency was important. Some features are nice. Some arrived too late, like std::optional in C++17 [0] or std::expected in C++23 [1], and some features requires too deep knowledge of the language, like std::move unable to optimize for containers of structs without "noexcept" in their constructors. [2] But honestly, the reason why I don't enjoy it is unrelated to the features added to each new standard. It's the build system. I just want to cross compile easily, add sanitizers to testing, and the minimal third party libraries I may need. I think I don't have to explain here how complicated it can get when you have to use CMake/Meson/Bazel, compared to other build systems. [0] https://en.cppreference.com/cpp/utility/optional | ||||||||||||||||||||||||||||||||
| ▲ | bulbar 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Still loving writing C++ and generally, it got much better over the years. User-Code (vs. library code) is quite easy to understand and it's easy to avoid pitfalls for the most part when using modern practices. Main problem I see is that it has to move pretty slow. Reflection arriving finally now, but some more modern features might take an additional decade. It feels however that around C++23/26, a lot of decade-long developings ( i.e.compile time stuff) are getting close to form a complete system without major limitations for the most part. They also took notes regarding errors and templates, so the user experience also improved a lot (i.e. with concepts). | ||||||||||||||||||||||||||||||||
| ▲ | pjc50 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I'd like to put in a "no" after spending many years writing C++; my day job is in C# now. The templating system is more powerful than any other language I have significant experience with, but that also lets people write incomprehensible systems. And the compile times always have been really long. | ||||||||||||||||||||||||||||||||
| ▲ | throwaway81523 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Yes I mostly enjoy it, but I don't do anything critical with it and I'm nowhere near expert level. I use the subset of it that makes sense to me. If I were doing something critical I'd want to use Ada, which I've played around with a little bit. I think the lurking question is about Rust. I've read a book about it and it has some attractions but also what I think are some poor decisions. I suppose I'll have to use it for something sometime. C++ is sort of like Perl, it seems to me. A lot of what seems like bloat is actually affordances, so the thing you want is often surprisingly close at hand. Some things of course are awful. I wouldn't call C++ a good language but it does most of the things. Enjoyment doesn't always mean productivity anyway. I enjoy using Forth but that's almost like enjoying riding a unicycle. I wouldn't do anything substantial with Forth except for recreation. I do feel fairly productive in C++. | ||||||||||||||||||||||||||||||||
| ▲ | adg001 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I never enjoyed programming in C++. I feel its (original) syntax and approach to OOP to be obnoxious. I never looked into C++11, though; I hope things improved. The first love was always for C; notwithstanding all its shortcomings, I feel at home writing C, and I would still enjoy doing so. | ||||||||||||||||||||||||||||||||
| ▲ | ketzu 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I really enjoyed writing C++. At least the C++ with for loops, calling functions and the sort. Not so much the c++ of template specifications. I recently saw [1] and the point of C++ building new things with the template mechanics really resonated with me. Features built that way stopped me from using the part of C++ I really liked. However, I stopped writing C++ once I switched to Rust. I assume I would still enjoy writing C++, as long as I can avoid a lot of the templating features. (I might have a different opinion if I worked on different kinds of C++ projects, eg more people, more library oriented, etc.) | ||||||||||||||||||||||||||||||||
| ▲ | NooneAtAll5 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I still don't understand the "feature creep" complaint python just introduced built-in sentinel, and only comment on an explainer video brought up that it's nothing new and is just a rename of unittest.mock.sentinel who even knew there's unittest module? who even knew there's unittest.mock? definitely not me because it doesn't matter - you use what you need and learn what you encounter. Same thing with C++ | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | nukanse 35 minutes ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I like that it can do anything. I don't like the sintaxis. | ||||||||||||||||||||||||||||||||
| ▲ | egorfine 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
There is C++ and then there is C++. Totally different things. One I enjoy programming. Another I dread. | ||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||
| ▲ | cjfd 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I like coding in C++ a lot. I think it is great that it can both be a high level language an a low level one. One has control of the bits if one wants that but there are also a lot of goodies to make things happen automatically. I think RAII is the greatest invention in programming ever. | ||||||||||||||||||||||||||||||||
| ▲ | i_am_a_peasant 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Yes, but I feel reticent nowadays in voicing out loud why exactly I like it (along with liking Rust). Because I don't want to give up my business ideas for free. | ||||||||||||||||||||||||||||||||
| ▲ | saagarjha 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Whenever I write C++ that isn’t, like, pure algorithms I usually find myself wishing I had a nicer language where I could represent what I wanted in a clearer way. | ||||||||||||||||||||||||||||||||
| ▲ | pjmlp 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Yes, on side projects where I get to use concepts or modules, or even ranges. Languages like C++, Scala, Haskell, is where I get the most fun coding, unfortunately the question can be reformulated as "Do you still enjoy coding?", as we get pushed to program into natural languages instead. | ||||||||||||||||||||||||||||||||
| ▲ | amelius 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I stopped using C++ around the time when Boost libraries were a thing. It was fun to think a bit of how to do metaprogramming, but it quickly became apparent that this was not the right way to do things. | ||||||||||||||||||||||||||||||||
| ▲ | tonyedgecombe 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
>Do you still enjoy coding in C++? No, I migrated away from it in 2014 and it was one of the better decisions I made in my business. Productivity and quality went up. | ||||||||||||||||||||||||||||||||
| ▲ | coderenegade 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Modern dialects of C++, sure. There's a nice language in there, it just comes with everything else and the kitchen sink. The most horrific code I've ever had the misfortune of working on was also C++. | ||||||||||||||||||||||||||||||||
| ▲ | mightymosquito 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
As someone who's planning to get into low level - would you still recommend C++ or rust? | ||||||||||||||||||||||||||||||||
| ▲ | krona an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
The metaprogramming features of C++ are the killer feature. Only zig comptime comes close. But zig deliberately doesn't allow operator overloading, so high-performance array/tensor programming APIs aren't anywhere near as ergonomic. Since I work in high performance scientific computing, this is a major drawback. FWIW I was a Rust contributor, pre v1. I don't see Rust as a competitor to C++, but a 'better c' - you can clearly see this by looking at where Rust adoption is highest. C++ has a boilerplate problem but at least more recent versions have addressed the biggest pain points - 1000 line compiler dumps of of template instantiation errors are less of an issue. | ||||||||||||||||||||||||||||||||
| ▲ | mococa 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
Yes. It was my first language (which I started to produce something useful, got jobs, etc...) - and it will be my last. | ||||||||||||||||||||||||||||||||
| ▲ | aktenlage an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I have a love-hate relationship with C++. I am currently working with C++23 professionally in a complex project, with python layer on-top. C++11 and later turned the scale more towards enjoyment, but having less time for tinkering and deep diving makes me annoyed. It's not entirely the core language's fault, but since high performance is the name of the game for C++, every library seems to make twists and turns to not leave anything on the table, which increases the cognitive load when writing code, be it performance critical or not. AI now alleviates that quite a bit. I wish it was as concise as python, e.g. with the list comprehension. When I try to use the newfangled ranges algorithms to replace a (range-based) for loop, I roll it back in 90% of the cases because it neither is shorter nor more expressive. | ||||||||||||||||||||||||||||||||
| ▲ | mark_l_watson 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I had a love-hate relationship with C++. In the decade prior to the release of the first version of C++ my company bought me a Lisp Machine, and programming was so much fun. C++ was gnarly, and I put a lot of effort into making C++ easier for our new hires out of college to use (I wrote a C++ GUI library for them to use that evolved into my personal code for my two “Portable C++ GUI” books for McGraw-Hill). I ended up writing 5 C++ books, and using the language was fantastic for my career, but: I never really liked C++ | ||||||||||||||||||||||||||||||||
| ▲ | taspeotis 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I enjoy using C++ as “C with classes.” | ||||||||||||||||||||||||||||||||
| ▲ | m00dy 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I don't like C++ because I don't want to be on the losing side. | ||||||||||||||||||||||||||||||||
| ▲ | staszewski 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
What is coding? | ||||||||||||||||||||||||||||||||
| ▲ | ephaeton an hour ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
when I didn't know better (i.e., didn't know many other languages), back in 96 to maybe 2002 or so, I tremendously enjoyed C++. I felt so powerful. It was hard to get things right and fast following the literature at the time, but hey, low-level, power, yay! Then I took a turn and learnt LISP, ML, and a whole potpourri of functional languages. Things were so easy to express in comparison to looking at _all_ the details _all_ the time. I dropped my C++ for quite a while. Fast forward a decade, and I spent about a decade writing C++11 code. Then C++17. I didn't particularly enjoy it, but it got the job done. In the environment at the time, alternatives were not accepted, so I obliged. Now I just see loaded and unsecured footguns everywhere when I look at C++. Note that I'm still paid to write C++, but after learning to trust smart compilers in semantically proper languages, learned about data oriented programming, learned about all the bad from the pointer-laden object-oriented style, about the problems of (thread) synchronization C++ style vs. message passing between programs (CSP), ... I grew to despise it. Frankly, nowadays, I'd rather write in Ada, drop all the "smart" constructs whose smell reek through the whole code-base, and all the implied semantics of various interfaces which are not described on language-level but (maybe, hopefully) in the comments ... the everything-and-the-kitchen-sink approach of C++ bites us regularly, but still, the environment has a hard time accepting non-C++ code. | ||||||||||||||||||||||||||||||||
| ▲ | logicchains 3 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
I like writing in C++ because Claude does most of the work and if I structure the source well it compiles much faster than my Rust code. | ||||||||||||||||||||||||||||||||
| ▲ | globalnode 2 hours ago | parent | prev | next [-] | |||||||||||||||||||||||||||||||
yep, i actually liked stl, iterators with auto also seem like a godsend now compared to how verbose they used to be. the biggest pain point for me was keeping track of all the required ctors and operator overloading. admittedly i used it back when all pointers were just *, once i discovered a single line of python could do what it took 10-100 lines of C++ to achieve i switched. so its been a looooong time since i programmed in C++, but i did like it overall. | ||||||||||||||||||||||||||||||||
| ▲ | arya0 3 hours ago | parent | prev [-] | |||||||||||||||||||||||||||||||
idk but my claude seems to really enjoys writing code in C++ | ||||||||||||||||||||||||||||||||