Hacker News new | ask | show | jobs
by joaquincabezas 590 days ago
I've been a long time considering that I should learn Rust. I am using Python as main language (for Machine Learning tasks) so I am at the edge:

Go with:

C++, because I used to code in C (for embedded, 8-bit microcontrollers) when I was younger and also for its possible advantage for learning some CUDA (this last thing is mostly for fun)

or

Rust, because I have some trauma for kernel panics with bad memory management back in the days with C, and because I want to build some tooling in a nice, efficient way

7 comments

Learn both. Rust first, because it's a lot more approachable. Modern C++ doesn't really have much in common with C to be honest.

Also, you'd probably have found these quickly, but cppreference.com is the nicest C++ reference (!cppref on DuckDuckGo) and doc.rust-lang.org (!rust on DuckDuckGo) has the Rust standard library documentation.

In some way I am stuck because I don't want to dismiss any of these (kind of Buridan's donkey) but planning this in a sequential way seems smart and would end the inner monologue
Coding in C++ is very different than it is for C and you should not consider them similar in any way. They are now two very different languages and nearly all the idioms in common use in C are considered bad practice in C++. It has been many years since these two languages could be considered similar.
Exactly this. I've felt it while checking some C++ OSS projects, thinking "wow I am more Java than this, and I don't do Java". This prevented me directly jumping into C++ which would be the natural step coming from C (because in reality it's not the natural step)
One thing that surface tutorials in either C++ or Rust won't get at, which might worry your residual C programmer is: how the fuck can any of this be implemented efficiently on the machine ?

In C it often (too often actually but that's a different rant) feels as though what you wrote just translates directly into what the machine does, no surprises, so then it seems intuitively to make sense that this delivers good performance. And it's not anywhere close to obvious in idiomatic C++ or Rust, where yeah, "more Java" in some sense.

One option is to trust it, it's the fastest option as it's no work but you may find you can't bring yourself to do that.

Another option is to satisfy yourself by measuring, time it, or measure how big it is, now and again when you find something that seems like it ought to be dramatically worse - is it really worse? Huh.

The final option, which is very time intensive, is to learn the depths of how this actually works. That probably means learning assembly language, and a bunch of things about how CPUs work, how memory works, etc. If you never did this for C, I'd suggest not starting now as it's a huge time sink and is often going to shake what you thought you knew. But it's an option if you aren't satisfied by the other options.

You are forgetting yet another option which is widespread and common practice among serious C++ developers, which is to use the Compiler Explorer to see how the code directly translates into machine instructions. It is almost normal to always have this open next to your IDE if you care about performance.

Note that most people who use Compiler Explorer don't actually know assembly that well, but you don't need to know it to see what is happening at a basic level, which usually suffices.

However, it is not necessary to care so much about performance in most cases. The language is generally fast compared to other languages, even if you don't try to make it fast -- the compilers and the language spec usually have that outcome. But when you really want to squeeze out the most efficient code, Compiler Explorer is the way most people do it.

> Note that most people who use Compiler Explorer don't actually know assembly that well

To add to this, if you hover over assembly instructions, it'll give you a description of what they do.

IMHO Rust is between C and C++: more secure and powerful than C, simpler than C++, but it has the potential to do everything.

If you already know C and Python, it would be a better and faster choice. I’m more a C++ expert, but I’ve written a few small command line tools in Rust and it looked a bit like the Python equivalents.

If you would have just learned it in the time you’ve spent considering learning it then you would not need to decide. Go download the rust book or lessons in the terminal. They’re great resources.
Imo C++ only makes sense if you commit enough time. If you are not planning to work with it as an expert I would look somewhere else.

I dont want to comment about rust, but personally I just don't like ideological people. Also some people seem to not understand, that the set of all valid computer programs is greater than the set of all programs that can be proved correct. It is a fact and can be proven.

Imo C# is a well designed language and would be the best start to learn more about a modern statically typed language. Swift is also interesting, but its mostly apple and has similiar ideologic problems like rust (e.g. pointers are evil).

If Rust would stop the politics pushing, I wouldn't be so afraid of it
Rust, the language can not push any politics. For me, technical stuff and politics are disjoint sets. I do not care at the least what the political leanings of people I work with are. To me it sounds as none of my business as what car they drive or what perfumes they like.

What exactly are you afraid of?

Sure the language can't, but the people running the language can.
IF you learn C++ I'd suggest to use it as a nicer C, without any std:: or the million other complications. Write your own List / String classes for fun, they can't be much worse than the std ones.
The string class you implement will be worse than the stdlib one, unless you implement small-string optimization, too, which is a massive pain.
This is such bad advice.