Live data from Hacker News

Ask HN: Rust or C or C++ in 2023?

news.ycombinator.com

31–40 of 56 posts

Re: Ask HN: Rust or C or C++ in 2023?

#31
It really depends on the kind of systems programming you are doing. As a rough heuristic, C for embedded because portability across odd silicon; C++ for complex software close to the metal, like database kernels; Rust for somewhat higher level software — not so close to the metal — where performance matters. Right tool for the job, and all that.

All are good choices in the right context. None is unambiguously superior for all systems programming use cases.

Re: Ask HN: Rust or C or C++ in 2023?

#32

Learn enough C to encounter the pain points C++ & Rust are trying to solve. C is simple, but not easy. Then learn enough Rust to be productive. Then learn enough C++ to interact with the enormous amounts of existing C++ code. Once you know a bit of all 3, decide where to focus based on the work you're trying to do. Rust is the easiest, but least widely supported. C is necessary either way, unless you're working for M…

> C is simple, but not easy. I think I know what you're trying to say, but unfortunately C is anything but simple. The semantics are riddled with surprises of all kinds. It's unlikely the average C programmer has never written a program with undefined behavior, for example.

> It's unlikely the average C programmer has never written a program with undefined behavior

I'd add that the average C programmer can't spot UBs before they cause a problem, they are not your average bug. Unless you're very well read or are just told about them, that is.

Re: Ask HN: Rust or C or C++ in 2023?

#34

C is the best choice to learn systems programming. C is the simplest of C, C++, or Rust and most other languages have C interop or foreign function interface. First learn C and then you can learn Rust or C++ if needed. The concepts you learn in C programming will help you to better understand the more advanced concepts used in Rust or C++. Recommended first book: https://en.wikipedia.org/wiki/The_C_Programming_Langua…

Biases because that's how I learned, but yeah... I agree. Learning C will help you be a better programmer in any C-like language. C forces you to think like a programmer. Once you grasp that, you can learn most other languages with relative ease. Maybe not counting Lisps.

I highly recommend learning enough C that you at least decently understand pointers. That’s a major stumbling block and worth overcoming.

Re: Ask HN: Rust or C or C++ in 2023?

#35

C is the best choice to learn systems programming. C is the simplest of C, C++, or Rust and most other languages have C interop or foreign function interface. First learn C and then you can learn Rust or C++ if needed. The concepts you learn in C programming will help you to better understand the more advanced concepts used in Rust or C++. Recommended first book: https://en.wikipedia.org/wiki/The_C_Programming_Langua…

+1 and I say this as a rust fan. The rust programmers that learned C first always have very elegant solutions and have the least issues in their unsafe blocks. C to learn how memory works and how to manage resources, then Rust to understand how to use a higher level systems language for more productivity in places where it helps. I work as a C++ dev and there are jobs in it, but unless you are trying to work a C++ jo…

Another rust fan here (with 3 years experience writing it full time at this point). I agree with all of this.

C knowledge also helps to understand what rust's borrow checker is actually doing. And it will teach you what Box / Rc / etc are for. Its surprisingly easy to write rust code that Box everywhere, and runs very slowly in practice. (I've seen rust programs run slower than their javascript equivalents). Learning C first will give you the right knowledge base to appreciate rust and use it well.

Re: Ask HN: Rust or C or C++ in 2023?

#36
post #28

Earlier quoted context omitted.

> C is simple, but not easy. I think I know what you're trying to say, but unfortunately C is anything but simple. The semantics are riddled with surprises of all kinds. It's unlikely the average C programmer has never written a program with undefined behavior, for example.

I'd go so far as to say it's unlikely the average C programmer has ever written a program with defined behaviour.

So my 5k lines of C code project from back in college is all... undefined?

Re: Ask HN: Rust or C or C++ in 2023?

#37
post #4

C is the best choice to learn systems programming. C is the simplest of C, C++, or Rust and most other languages have C interop or foreign function interface. First learn C and then you can learn Rust or C++ if needed. The concepts you learn in C programming will help you to better understand the more advanced concepts used in Rust or C++. Recommended first book: https://en.wikipedia.org/wiki/The_C_Programming_Langua…

Agree that C is easier to explore the concepts in, but knowing enough C to know why e.g. [0] gets the behavior it does is IMO not useful if the goal is to learn the _concepts_ before switching to a language that doesn't do this kind of thing. So, IMO worth jumping to Rust as soon as you feel confident with the stack vs the heap, use-after-frees, etc. [0]: https://godbolt.org/z/x7bf4edo9

You lost me here with p += (&ys[2] - &xs[0]);

I mean, why would I expect the parenthesised subtraction to do anything I can rely on? Or did you mean (&ys[2] - &ys[0]) ?

Re: Ask HN: Rust or C or C++ in 2023?

#38

C is the best choice to learn systems programming. C is the simplest of C, C++, or Rust and most other languages have C interop or foreign function interface. First learn C and then you can learn Rust or C++ if needed. The concepts you learn in C programming will help you to better understand the more advanced concepts used in Rust or C++. Recommended first book: https://en.wikipedia.org/wiki/The_C_Programming_Langua…

C is a good learning language for systems programming, no doubt about it. All of the elementary concepts are exposed in a simple way that will server you well in any systems programming language. It was also a language design that informed many of the systems language designs that came later, so the history is educational.

However, it is not a productive systems programming language these days compared to C++, Rust, or Zig.

Post reply on HN