Ask HN: Is C++ a bad idea for new projects?

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

5 points | by akkad33 91 days ago

9 comments

  • fragmede 90 days ago
    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.

  • ArtixFox 90 days ago
    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.

  • wojciii 90 days ago
    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?

    • ArtixFox 90 days ago
      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.
  • solsane 91 days ago
    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.

  • speedgoose 91 days ago
    I wouldn’t start a new project in C++ unless I have a very good reason to use C++.
  • npalli 91 days ago
    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.

  • talldayo 91 days ago
    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.

  • LorenDB 91 days ago
    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.
    • akkad33 91 days ago
      Would you recommend a resource to learn about such practices?
  • dana321 91 days ago
    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/

    • akkad33 91 days ago
      This is most attractive about c++. But the huge syntax and several versions is daunting. Which version of C++ would you recommend?
      • ArtixFox 90 days ago
        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.