
Ask HN: C, C++, or Rust which language to learn next? - backslash_16
I&#x27;m mostly new to C (have gone through about half of Learn C The Hard Way) and completely new to C++ and Rust. For my day job I use C#, JavaScript, SQL, and a little Python.<p>I got the Bjarne Stroustrup book Programming: Principles and Practice Using C++ as a gift and now I&#x27;m trying to figure out if I should keep digging into C, jump ship to learning C++ or take a look at Rust.<p>I started learning C because I wanted to dig into a non GC language and get a little &quot;closer to the metal&quot;, not because I need it for my day job. My friend got me the C++ book because he said I should spend my time learning a language that I might end up using in a job but that&#x27;s not my primary concern right now.<p>Lastly I started looking at Rust because the HN search (https:&#x2F;&#x2F;hn.algolia.com&#x2F;?query=rust%20c&amp;sort=byPopularity&amp;prefix&amp;page=0&amp;dateRange=all&amp;type=story) returned a lot of interesting comparison beween it and C&#x2F;C++. They all make it sound like Rust is an easier to learn systems language which lowers the chance of making memory related errors and has a few nice features to make the code easier to read and understand.<p>Does anybody have opinions on which language I should learn for the purpose of understanding how code interacts with the computer at a low level better, manual memory management, and learning how to deal with pointers (instead of C#&#x2F;Java references)? Any personal preference out of all the languages?
======
jbandela1
Learn C++. You will have the opportunity to learn low-level features but know
how to wrap them up inside highly performant, high-level components.

Rust is interesting, but I think it will remain an interesting language
outside the mainstream without any major commercial backers (Mozilla does not
count). In addition, C++ is taking a lot of the ideas from Rust and
incorporating them along with tooling that will provide 95+% of the value of
Rust while still keeping the advantages of C++ (see
[https://www.youtube.com/watch?v=hEx5DNLWGgA](https://www.youtube.com/watch?v=hEx5DNLWGgA))

What is interesting with C++ is that although a lot of vendors are pushing
their own languages - Microsoft with C#, Apple with Swift, Google with Go,
Facebook with Hack, Mozilla with Rust - they are all deeply involved with C++
because C++ powers their mission-critical code. Another way of putting it
would be that despite all the promotion if all of Mozilla's Rust code were
eliminated tomorrow nobody would notice, but if all of Mozilla's C++ code were
eliminated, it would cease to exist.

Also, C++ is rapidly evolving and by learning Modern C++ 14 now, you can avoid
a lot of the mistakes of C++ that were common in the past and write safe,
elegant code. C++ is also experiencing a renaissance (see
[https://www.jetbrains.com/cpp/cpp-today-
oreilly/](https://www.jetbrains.com/cpp/cpp-today-oreilly/)). C++ is now the
one high-level language that is natively supported by the system vendor across
Windows, Linux, Mac, iOS, Android, Windows Phone, XBox, and Playstation.

~~~
seren
I agree about the universality of C++. I also agree you have to compare C++ +
code analysis versus Rust regarding safety. However, my team is spending over
100k$ a year to get access to these tools. In the grand scheme of things,
compared to the salary and other expenses, it is insignificant.

But for a small team for a new project, it is probably easier and more cost-
effective to use a language that is safe from the ground up, rather than
relying on external vendors. (Most of these tools have a free option for FLOSS
projects, but you might need to develop something closed source)

I honestly don't know if this is something that can tip the balance, or if
this is a "detail". Time will tell.

~~~
jbandela1
Take a look at Herb Sutter's talk from CppCon 2015. The slides are here
([https://github.com/CppCon/CppCon2015/blob/master/Keynotes/Wr...](https://github.com/CppCon/CppCon2015/blob/master/Keynotes/Writing%20Good%20C++14%20By%20Default/Writing%20Good%20C++14%20By%20Default%20-%20Herb%20Sutter%20-%20CppCon%202015.pdf))
and the video is here
[https://www.youtube.com/watch?v=hEx5DNLWGgA](https://www.youtube.com/watch?v=hEx5DNLWGgA).

Microsoft will be releasing the static analysis tool as a free cross-platform
tool (and I think open-source IIRC). They shipped a preview for Visual Studio
2015 with Update 1, and are planning on shipping a cross-platform version
soon. As tools like this become free and ubiquitous, it will greatly improve
C++ code safety.

------
elbows
For your purposes I would recommend C. It's a very small language with very
little abstraction, so it forces you to really understand pointers and memory
layout.

Rust is more complicated than C and it tends to insulate you from the low-
level details. The way it combines low-level control with high-level
abstractions is really interesting, but from an educational point of view I
think you'd get more out of it after you understand C pretty well.

C++ is a giant, sprawling mess. It can be very useful but I'm not sure what it
will teach you other than how not to design a language. :)

------
nostrademons
Assuming your purpose is _learning_ rather than writing a practical project, I
would go in the order of C => C++ => Rust. Each of them builds on concepts of
the previous.

It is easier to learn C++ if you already know the distinction between value
vs. pointer types, if you're already familiar with C syntax, if you already
know how to manage memory manually, and if you already know how to use
functions, function pointers, and opaque types to create an API. C will teach
you all of those.

It is easier to learn Rust if you already know about RAII, ownership,
generics, both run-time and compile-time polymorphism, and move semantics. C++
will teach you all of those (in its C++11 and C++14 variants, at least).

~~~
DerekL
You should only learn all three languages if you want to know all three
languages.

Learning C as a stepping stone to C++ is a waste of time. You might think it's
a good idea, because C++ is based on C, and most of the features of C are
available in C++. But writing good C code requires idioms that are useless in
C++.

For instance, suppose you need to write a function that opens a file, reads
the contents into a some data structure, and then returns a result. Before the
function returns, it needs to free the memory in the data structure and close
the file. If you write this in C, you either have to make sure you only return
at the end, or use nested "if" statements, or use "goto" statements. But in
C++, you don't have to worry about this, because the object destructors will
handle it.

~~~
rnovak
If you go into it as a means to an end, then yes, it probably would be a waste
of time.

But....if you actually approach it as an opportunity to expose yourself to new
ways to think about problems, I don't think that would _ever_ be a waste of
time.

I disagree that you'll _never_ use C idioms in C++ or Rust, but even _IF_ that
were true, there's absolutely no way that having a better understanding of
what the underlying hardware is doing is a bad thing.

------
dpc_pw
C. Learning C is like being dropped on island and having to learn all the
skills necessary to survive. After you master C, you go back to civilization
and enjoy the simple life conveniences again, while being able to see through
them at the real, crude and dangerous reality.

After you learn C, go to Rust. Rust will just teach you more than C++.

------
_RPM
I believe C is the most important language to know. It's pretty low level and
doesn't provide you with much, but learning what is taken for granted in
higher level languages is valuable.

------
mbrodersen
Learn C. Then you ACTUALLY 95% understand how things work. If you want to
understand 100% then learn Assembler. Assembler is surprisingly simple once
you get it.

------
untothebreach
I don't think you need to learn C and C++ as a prerequisite for learning Rust,
but I still think C is worth learning. The concepts that you would learn with
C++ can be learned just as well by learning Rust, so I would skip C++ if I
were you.

If you decide to learn Rust, the Book[1] is, I think, the best way for you get
started, seeing as you already have experience programming.

1: [http://doc.rust-lang.org/book/](http://doc.rust-lang.org/book/)

~~~
sudeepj
> I don't think you need to learn C and C++ as a prerequisite for learning
> Rust

While this is true, it's just that only after knowing C++ pain points one can
appreciate Rust more :o)

------
tmaly
start with C. If you look at the programming language benchmarks, it is still
one of the fastest.
[http://benchmarksgame.alioth.debian.org/](http://benchmarksgame.alioth.debian.org/)

if you look at the C++ code on there, much of it is written in the style of C.
If you can write newer code and do not have to maintain old code, C++ would be
a good second. There are still tons of high paying jobs for C++. Some pay
400K+ in the NYC area

~~~
wkoszek
Which jobs are that?

~~~
seren
I would assume high performance / low latency software in finance.

------
tjr
I'm currently starting a new project in C++, because various logistics
conspire together to make that the ideal choice. If that weren't the case,
well, I personally do not like C++ much, though sticking with C++11 style over
older C++ paradigms seems like an improvement.

Just picking a low-level systems language for my own fun and edification, I'd
still learn C because it is so ubiquitous, but I for one hope that something
more like Rust is the future.

------
sudeepj
I am a C++ developer and I would recommend Rust. By learning Rust my C++
development practices have improved when it comes to memory management.

------
Arzh
I think C, it will help you learn all the rest. It also allows you to see how
much some stuff like concatenating strings really cost in terms of
performance. I think just knowing that as a fact will help you in writing in
higher level languages.

