Hacker News new | ask | show | jobs
by RivieraKid 785 days ago
Which one would you recommend? My ideal C++ alternative would be something like Swift but faster.
5 comments

For low-level compiled system applications: Rust, Zig etc.

For compiled garbage-collected applications (web/cli): Go.

For high-level applications (web/cli/etl/desktop): Java, C#.

Also here is good writeup: https://hackernoon.com/the-real-c-killers-not-you-rust

discussed here two times:

https://news.ycombinator.com/item?id=34792932

https://news.ycombinator.com/item?id=39770467

I have a similar opinion: For low level stuff Rust or more "obscure" langs like Zig or Carbon offer a lot in that space. The moment you leave low-level I'd always go with C#/Java or TS for web-stuff. The productivity gains you get from switching from C++ to C# are absolutely insane.
Little reason to use Go here. C# is a much better language at allowing you to tactically write high-performance low-level code where it matters and relying on higher level abstractions when it's not (struct generics are just like in Rust allowing you to expend a little effort for achieving zero-cost abstractions, although not as convenient as just using objects everywhere).

Go is inadequate, poorly typed, has abysmal FFI overhead and bloated binary sizes as it does no metadata compression and other tricks C#'s AOT compilation does.

With Go, I can easily cross-compile a statically linked binary for each of the major platforms.

You cannot do that with C#.

Cross compilation story in C# is very good actually.
With Go, I can use my Linux CI server to compile a statically linked binary for MacOS.
You can publish across platforms with modern .NET
But the fact that developers often need to be able to cover any one (or even multiple) of these areas, and that language proficiency (with platform APIs and various quirks) is quite hard to achieve - makes me think that the actual alternative is the elephant in the room, the one not even listed here: JavaScript.
Having been programming continuously on JavaScript for over 20 with all the popular frameworks, I'd try to stay away from it as much as possible:

1. Dynamic typing must die. Except for R/Julia/Python (aka JuPyteR) notebooks use-case, where it's awesome. My list includes only statically-typed languages. Typescript is much better, but its type-checking still fails sometimes, unlike real static-typed languages.

2. NPM is a mess that allows any transitive dependency to run arbitrary code on your machine at a time of installation (including cleaning up after itself). Compare that to Java's Maven -- libs quality is much better. no arbitrary code runs, just downloading.

> allows any transitive dependency to run arbitrary code on your machine at a time of installation

This point gets parroted so often on HN [1]. You can install packages with the --ignore-scripts flag to disable this behavior, or just set the option globally in your NPM config file. I do like the way Bun disables lifecycle scripts by default [2], but it takes me all of two seconds to run `npm config set ignore-scripts=true` on a new machine, so it's basically a non-issue for me.

[1] https://news.ycombinator.com/item?id=38797176

[2] https://bun.sh/docs/cli/install#lifecycle-scripts

Are you seriously mentioning JS as a C++ alternative? I am confused.
I am old enough to remember when everything was written in C++, except embedded and OS kernels in C. Today even my chat, email client and IDE are written in JavaScript...
> Today even my chat, email client and IDE are written in JavaScript...

Yeah I don't consider that a good thing :-)

Just so you know, Rust is in many ways a lot like Swift, and not just because many Rust compiler devs went later to work on the Swift compiler.
I think it depends on what you use C++ for. For low-level high-performance systems work, the thing I probably miss most in many of the alternatives is the extensive metaprogramming and generics capabilities of C++. This is unfortunate given both the power of this language feature and how much opportunity there is to improve the ergonomics of C++ metaprogramming.
Rust, since you're mentioning speed. It was refreshing to use, partially because the standard library is so much nicer.
That's C# :)