Live data from Hacker News

Ask HN: Who is using C++ as the main language for new project?

news.ycombinator.com

191–199 of 199 posts

Re: Ask HN: Who is using C++ as the main language for new project?

#191

C++ is still often the best or only way to write performant code on embedded platforms, while having a rich library ecosystem available. Hence, my first choice for a new embedded project is almost always C++. I would love to be able to use something like Rust, but the RTOS options and library support are not quite there yet. With more powerful embedded processors becoming available, Micropython is an option for some…

You should checkout Nim! I use it extensively on embedded. Nim is fantastic to program in if you're an experienced C/C++ developer. Its safer and smarter but not not pedantic about it.

Nim compiles to C or C++ so its easy to use on any embedded platform and compiler suite. Thats still huge for embedded. Rust forces a type-trait centric programming style which makes interfacing hardware/embedded harder as you have to make type heavy HALs everywhere -- hence the lack of rtos & library support despite its relative popularity).

Its pretty trivial to re-use any C/C++ libraries which gives a big boost to the native ecosystem. I wrapped most of the esp32 idf in a few weeks: https://github.com/elcritch/nesper

The new GC (ARC) is basically a built in `shared_ptr` or `Rc`. You can also do stack-based programming too and the compiler enforces a safe memory accesses. The performance is great and can match or beat C/C++ if you do a few hours of tuning. Though its easy kill performance if you're lazy (e.g. parse json into a bunch of heaps objects), but that can have its place.

Re: Ask HN: Who is using C++ as the main language for new project?

#192
post #103

C++ is still often the best or only way to write performant code on embedded platforms, while having a rich library ecosystem available. Hence, my first choice for a new embedded project is almost always C++. I would love to be able to use something like Rust, but the RTOS options and library support are not quite there yet. With more powerful embedded processors becoming available, Micropython is an option for some…

I think the RTOS side is being addressed pretty well for rust, which libraries do you feel are missing now?

Nah, the RTOS side in Rust is still in its infancy. Hubris is pretty cool but really only supports two families of chips (and requires an MPU iirc).

Rust's ecosystem still struggles with no_std, so the majority of crates won't work. Worse (for me) is that using Rust with arrays (not heap allocated vec's) is still a pain.

Re: Ask HN: Who is using C++ as the main language for new project?

#193

C++ is still often the best or only way to write performant code on embedded platforms, while having a rich library ecosystem available. Hence, my first choice for a new embedded project is almost always C++. I would love to be able to use something like Rust, but the RTOS options and library support are not quite there yet. With more powerful embedded processors becoming available, Micropython is an option for some…

You should checkout Nim! I use it extensively on embedded. Nim is fantastic to program in if you're an experienced C/C++ developer. Its safer and smarter but not not pedantic about it. Nim compiles to C or C++ so its easy to use on any embedded platform and compiler suite. Thats still huge for embedded. Rust forces a type-trait centric programming style which makes interfacing hardware/embedded harder as you have to…

Hmm, I’ve been meaning to check out Nim. Now I definitely will.

Re: Ask HN: Who is using C++ as the main language for new project?

#194
post #103

Earlier quoted context omitted.

I think the RTOS side is being addressed pretty well for rust, which libraries do you feel are missing now?

Nah, the RTOS side in Rust is still in its infancy. Hubris is pretty cool but really only supports two families of chips (and requires an MPU iirc). Rust's ecosystem still struggles with no_std, so the majority of crates won't work. Worse (for me) is that using Rust with arrays (not heap allocated vec's) is still a pain.

(Hubris does require an MPU, you're recalling correctly :) )

Re: Ask HN: Who is using C++ as the main language for new project?

#195

Earlier quoted context omitted.

You should checkout Nim! I use it extensively on embedded. Nim is fantastic to program in if you're an experienced C/C++ developer. Its safer and smarter but not not pedantic about it. Nim compiles to C or C++ so its easy to use on any embedded platform and compiler suite. Thats still huge for embedded. Rust forces a type-trait centric programming style which makes interfacing hardware/embedded harder as you have to…

Hmm, I’ve been meaning to check out Nim. Now I definitely will.

It's smallish, but there's an embedded channel on Nim's discord thats active as well as the forums. Checkout https://github.com/embeddednim/ too, I've been working to get more projects there. Someone recently added a wrapper for the rpi pico's I've wanted to try :)

Re: Ask HN: Who is using C++ as the main language for new project?

#196
post #155

Earlier quoted context omitted.

> Modern C++ is getting a little better all the time. Honestly, this is the reason I haven't moved anything to Rust, despite seriously considering it in the past. I would ditch C++03 in a heartbeat, but C++14 and beyond are very usable. C++ could certainly be better - I'm hopeful about Carbon - but it's good enough and improving fast enough that if you're already a C++ expert, I think you're pretty happy.

Constexpr all the things is kind of a super-power of C++. Zig has an even more powerful comptime feature, but that's an aside. (Bonus points: Declare a static constexpr value in a compilation unit... and use it somewhere at runtime to get the moral equivalent of consteval for the values you care about.)

Compile time typing is awesome (in Nim its `{.compileTime.}`). Combine it with compile time "duck typing" and you can write some powerful but still simple code. I hope the style becomes more common!

Re: Ask HN: Who is using C++ as the main language for new project?

#197

Earlier quoted context omitted.

No, it's a GUI application. There are ways of making the GUI parts cross platform, like webview and such. But the GUI parts in this application are native to the OS. "Only" the core functionality is shared between platforms. This is also something I have been battling with in the past. All the cross GUI platforms have their quirks and problems and varying OS dependencies you are then married to. Since this is my own…

Very interesting. May I ask was what your approach is wrt the Mac GUI: are you going to use XCode's GUI builder or rather build a fully programmatic GUI (that is creating View Controllers, etc. by hand in Objective-C++ )? Have no direct experience myself but I intuitively find the latter approach more appealing. I have seen examples of it here and there.

I don't know yet, whatever feels easier. In Windows, the GUI is made so far with code and RC files.

Re: Ask HN: Who is using C++ as the main language for new project?

#198

We are using c++ mainly because Qt/QML exists. I guess if a Rust gui toolkit exists that is comparable to Qt/QML (looking at you https://slint-ui.com/ ), then future project would have to be re-evaluated.

Demos are down, if anyone from the project is here.

Demo works for me. What exactly is down? A github issues with details would be appreciated.

Re: Ask HN: Who is using C++ as the main language for new project?

#199

Earlier quoted context omitted.

Your last paragraph: I agree with C++ w/ GUIs if you need crazy performance -- oil and gas exploration, medical imaging, etc. If your user is internal / big-corpo, then Java Swing or C#/XAML is totally underrated and boosts developer productivity by many-X. Ugly UI is fine in these cases. I know this from experience. Have you used any of these and what is your experience?

I've been at it for 20 years and I've tried a TON of stuff. .NET is a perfectly reasonable -- dare I say enjoyable -- way to go if your systems are already configured to support it and you control the hardware you are running on. The .NET toolchain for compiling and installing .NET apps if you're not already in the Windows ecosystem was -- last time I tried, which admittedly was a while ago -- very clunky compared to…

This is a great reply. Thank you for the interesting feedback about a huge number of GUI toolkits. I /thought/ I was experienced with GUI frameworks until I read this post!

I also have a "soft spot" (personal preference) for Qt. Part of that is C++, part of that is small company "makes it big". Their documentation is absolutely first class. They only need to add more screenshots to improve the docs. (Facepalm... really, I should do that myself via PRs on their open source repo!) They should also allow people to submit sample code to demo each class -- or do it themselves. Yes, I know it is a huge burden, but it would serious lower the barrier for entry. So much of enterprise GUI programming is write sample code, inspect GUI, repeat. Modern GUIs are so incredibly complex that nothing can replace a set of tiny demos you can run and test / try different GUI features.

Post reply on HN