Hacker News new | past | comments | ask | show | jobs | submit login
Ask HN: Is C++ a bad idea for new projects?
9 points by akkad33 6 days ago | hide | past | favorite | 16 comments
C++ has its niche in parallel high performance computing. But would it be a bad idea to start a new project in 2024 using C++ when Rust and Zig exists? I'm looking at machine learning and array processing as applications





Programming languages are tools; I would use Go for a web server, typescript for a web site, C++ for a computer game or high performance desktop app... you have not given enough details for anyone to give you a recommendation on what languages might be good to use.

Zig doesn't offer much in terms of high level abstractions and is very manual (I'd consider it far too much pain here unless for the embedded realm) - it's a better C at best, no rival for C++'s power and software design capabilities...

Rust has serious pain points when you consider the borrow checker and want to do complex stuff asynchronously, there's a big learning curve here, also not in every realm is it crucial to have memory safety (a desktop computer game is not flight control software... which btw you could also use C++ for, and it is used here, albeit w/ care). On a one man project it's also much simpler to simply write good modern C++ code than it would be on a large scale project w/ hundreds of programmers. I've also read that Rust's build system (nice as it is) has still limitations w/ very complex build setups...

And whether it's good to use C++ in 2024 for a new project... C++ will be around for DECADES at this point, it has a swath of libraries and tooling, good compilers producing optimized output targeting everything under the sun... yep, it's not part of the "hype around town" languages on Reddit or other boards, but C++ is used every single day in almost every industry down the line by millions of programmers!

What exactly is your worry? That you can't compile your code from 2024 in 3 years? Relax about the online hype... there are areas where EOL languages are still used... C++ isn't dead yet, won't be for a long time. It won't pick up steam any time soon it seems, but for what it can do (including its tooling and libraries) it's hard to beat, and it's not obvious to me that Rust and Zig are obvious "successors".

Zig isn't even at a 1.0 version yet w/ no clear roadmap to get there... I'd be much more worried using it for a serious project than C++... and C++ knowledge will be better on your CV than "Zig knowledge" (which most people won't even have heard of).


Do you just want to pick it up as a learning opportunity, or are you trying to accomplish a goal? There’s probably ‘better’ (by better, I mean ‘easier’, in this context) langs (Python + numpy comes to mind) if your goal is to bang some ndarrays together and do ML-type stuff.

There’s gonna be a bit more headache at each step of the process (finding the right libraries, building your code, and learning the language) that might come easily to someone who uses it professionally or used it extensively in college.

That being said, I think learning C/C++ has value in A) the areas you mentioned where it’s used extensively (e.g. kernel, embedded, or HPC dev) and it’s a good lang to know if just to understand how computers work a bit better. This is purely ‘extra credit’ though IMO if you’re already a productive developer.


C++ is extensively used in HPC and in the lower level aspects of machine learning. I dont know what you are trying to make so I cannot make a recommendation.

C++ has a lot of pain points that are being either tackled by the committee or the community. But those pain points still rear their ugly heads.

But majority of the code for HPC and ML is written in C++ or has its core written in C++. Leaving such a huge set of libraries is not an optimal decision if you want to deliver your code without having to yak shave everything.


Depends on what you need. Rust's machine-learning tooling isn't very advanced, but then again neither is C++ if you want high-level features. You might want to use neither, if you can get away with a simpler language like Python.

Between Rust and C++ I tend to pick Rust for better tooling and simpler control over LLVM. It's entirely up to you, but I wouldn't be caught dead running Valgrind on my multithreaded machine learning app.


I wouldn’t start a new project in C++ unless I have a very good reason to use C++.

No. All the core libraries in HPC/Machine learnings have native C++ (or C) underneath. This will continue to be the case for at least another decade as the investment needed to rewrite is massive (FORTRAN still exists!). If you want to jump on trends about some vague/superfluous memory safety issues you have solved, then go ahead with the pain of writing in Rust and trying to make it interoperate with C/C++ libraries. Otherwise stick to C++.

Zig is a better language than Rust but it is even further behind in native support for the HPC/ML space.


Python is used in ML because it's not the slow Python that's doing the matrix multiplication (if you write it right), so if you're asking what to learn, I'd start with that to get a feel for the math involved before wading into the deep end of the pool with C++.

If I were starting a new project today, it would depend on the project and who I was doing it for as to the language I would use, but C++ would definitely be on the list.


I have an unspoken rule: Don’t build software that I expect to be used by others in a language I’m not familiar with. Unfamiliarity with domain + the language is a recipe for disaster. Just my $0.2.

It's not necessarily a bad idea as long as you apply modern C++ practices. If you're going to be poking around with raw pointers, you might want to use a safer language, but if you want to use things like std::shared_ptr, C++ can be quite safe while continuing to provide good performance.

Would you recommend a resource to learn about such practices?

I like C++ as it gives you direct access to many libraries both C and C++.

For machine learning you have the pytorch C++ API: https://pytorch.org/cppdocs/


This is most attractive about c++. But the huge syntax and several versions is daunting. Which version of C++ would you recommend?

Anything C++ 17 and above is golden. I personally use a few things from C++20/23 and rely a lot on carefully reading and trying to understand https://en.cppreference.com/w/ when it comes to anything I might not be familiar about.

You dont have to use every single feature. Use whatever is required and if the need ever comes, go in depth with the language.

Its about to become way more complex and cooler after c++26 and 29 [with possible introduction of contracts and reflection!]. There is no way to completely learn this language anymore. I am not even gonna try.


Based on the number of companies who are trying to hire c++ developers the marked is shrinking (c++ devs are getting old).

I like the simplicity of C and not having for wait several minutes to rebuild a project. Have you thought if Python and Cython would be adequate for the task you want to solve?


having near instantaneous builds is easy to achieve in C++ [depending upon projects, this will not happen for llvm] to the point that even REPLs for C++ exist that are used for large scale physics data analysis at CERN.

Despite many efforts to the contrary, there is no such thing as the C++ killer.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: