Is it a good idea to learn Rust as a first language?

Hi all, recently I decided to get more into programming. I have only done a tiny bit of Java in my life, so I do not have much experience. I learned a bit more about Rust and find it very fascinating, and am interested in the future of the language. But I noticed many do not recommend it as a first language due to difficulty and lack of resources.

Some of these discussions happened years ago, so I feel that there are much more resources available now to start learning.

Right now I'm considering a few options:

Continue with Java and move on later in the future

Learn a easier, high level language such as Python and move on later

Learn a harder language such as C, and move on (I've read that this makes it much easier to move on to Rust)

Go cold-turkey and learn Rust

If anyone has any other idea, I would love to hear it! Thank you for reading, and have a nice day

Hi, I'm just linking the discussion on reddit so people can read what have already been said. https://www.reddit.com/r/rust/comments/hyumr0/is_it_a_good_idea_to_learn_rust_as_a_first/

2 Likes

Thanks!

This is the only thing I recommend not doing:

It may technically be true that learning C first makes Rust easier -- that was my experience, at least -- but that doesn't mean you should go and learn C first. Knowing how to drive a tractor might make it easier for you to learn to drive a car. But if you want to drive a car, and you have no desire to drive a tractor, you wouldn't go out and get tractor driving lessons "to make it easier" to learn to drive cars.

Also, learning to write halfway decent C is hard, much harder IMO than learning to write halfway decent Rust. If you want to learn C (or any language) properly, you'll need to spend a lot of time making mistakes -- it's how we all learn. The difference is in C you often don't find the mistake until you run the program and trigger a bug, where Rust would have pointed it out to you with extremely detailed error messages and suggested a fix.

Learning Java or Python first is a little different as I'm assuming these are languages you might want to learn anyway, for reasons other than just as a stepping stone to Rust. I have no particular opinion on whether it's better to learn an "easier" higher-level language first, or start with Rust -- I think in the end it probably doesn't really matter. If you already know some basics in Java you can probably start with the Rust book and be fine.

5 Likes

I agree.

When I first learned C on joining a new team and a new project back in the early 80's I was appalled to find that my first simple efforts would crash and burn with no error messages and likely requiring the machine to be rebooted. Despite having compiled cleanly with no errors or warnings. I even asked the team "Is it really possible for a high level language to crash and die like this". How green I was, they just smiled at me like I was an idiot.

You see, I had been introduced to programming in BASIC. Then later used Algol in uni. They did not just go belly up on you with no explanation or randomly produce wrong results for no obvious reason. I though that is what high level languages were for, for goodness sake.

Luckily, when we had been taught BASIC we were also expected to become pretty familiar with assembler. When I realized I should write C as if I were writing assembler I got on much better.

In short I think Rust is a much better starting point for someone new to programming than C. Things would have been much easier for me back in the 80's if that project used Rust rather than C.

To bring things to the modern times it is arguable that someone totally new to programming should be introduced with Python or JS or whatever, not BASIC. Just so they quickly get to know what a program eve is and concepts such as variables, expressions, conditionals, loops, arrays etc.

But given that Rust is not crashy, crashy like C/C++ perhaps that intermediate interpreted language step is not required.

Oh, and all programmers should have at least some familiarity with assembler. Even just a simple one like ARM, MIPS, RISC-V running inside an emulator.

1 Like

I've often heard of C being referred to as a "Cross-Platform Macro Assembler". I've even heard many C programmers consider that accurate and what makes C useful.

And they would be wrong (In my opinion).

Firstly C is clearly in a different class than Macro Assembler. It allows creation of portable code that can be compiled to run on almost anything. "Cross-Platform Macro Assembler" does not even make any sense, except as witty remark. That makes it a high level language.

Secondly C does not even get you close to the "metal". Apart from the fact it can't make use of many features of a modern processor it represents a machine to the programmer that has not existed for decades. Which is nicely explained here: https://queue.acm.org/detail.cfm?id=3212479

All I was getting at with "write C as if I were writing assembler" was that it helps to understand what is going on in C if you have used assembler, about memory, stack, heap, function calls etc. And hence why it can crash and burn so easily and demands as much attention to detail as assembler to avoid that.

I am myself learning Rust, but coming from outstanding C++ knowledge and working Python and Java experience.
At my level I am actually finding Rust easy, but personally I would not recommend it as a first language.
Nor you should learn a difficult language before Rust.
I would recommend Python as a first language (way easier than Java to get productive).
And when you get sufficiently annoyed by slowness and errors coming from type mixup, then turn to Rust. You will appreciate much more Rust features.

And very important, something I read earlier on my career on Stroustrup’s book : focus on programming techniques, not language features. That will help you to learn any programming language and even to switch later if you will

2 Likes

That is no doubt good advice.

But our OP is just starting out: "recently I decided to get more into programming".

As such I feel such abstract notions as "programming techniques" are bit premature to deal with for people in that position.

Let's start with the basics, what actually is a "program"? Of any kind?

As young teenagers, at a time when most people had never seen a computer let alone have one at home, this was a big thing for us. With a high school level of algebra behind us we had something to connect to in BASIC, with it's variables, expressions and assignments.

Then came the whole notion of sequence, selection and iteration. Then subroutines. This was all magical. It's the basis of most programming as we know it today. Even in OOP only language like Java or the esoteric world of functional programming.

Given all the above, I have the feeling that one could introduce programming to someone who had zero experience of it with Rust as easily as they did with BASIC for us back in the day.

The caveat being that this would require tutorials and documentation that is easily understood and followed by someone starting from knowing nothing about programming.

The Rust documentation is great and all, as is the Rust Book. But it is already at such a level as to be impenetrable to the rank beginner.

Of course it clearly is to you because you have a certain idea of what that means. Not everyone has the same interpretation.

Well, I would argue that that is exactly what LLVM/LLVM IR is and is intended to be. C is barely a level above that.

Neither does assembler. After all, you're not manually toggling switches and reading out the results with a logic probe. Saying, "It doesn't get you close to the metal," is pretty much useless unless you carefully define what you mean by "close".

Assembly does not represent in any meaningful way the actual architecture of the CPU. For example, on x86 the registers can be renamed by the micro-code independent of the actual register being addressed. You can't specifically ask for register renaming, it just happens. Also, there are no meaningful instructions that permit you to directly manipulate the CPU cache in a substantive way. The cache is, for the most part, opaque to the assembly instructions.

This is why saying C is not close to the metal,, but assembly is is pretty much not meaningful. Everything in C has a straightforward and direct translation to assembly (ignoring optimization). It is one of the reasons it is available everywhere. It is relatively simple to create a C compiler for any architecture.

And many would argue that is because C is not much more than a Macro Assembler (which isn't a negative).

That question must lead to opinions as answers and different people are entitled to differing opinions. In my book Python is the best language to start off with. It seems much better in terms of strictness and error messages then JavaScript and you have an interpreted language with a REPL, there is no waiting for the compiler, lots of good books and good advice on the net. Great for starters.

(I like Racket very much for a first language but you neither have the choice of books nor the "real-world-use" of Python. But as a first language with the idea of wanting to learn not just one language in your life -- it's worth consideration. And it comes batteries included.)

However, learning to program will come with tears and times of desperation no matter which language you start with. Sometimes it's hard as you feel you did everything right and the computer must be wrong -- which it never is. You will need something to drive you to go on and not give up. If for you this energy flows from Rust and from nothing else, then go with Rust. It can be learned as a first language. It's not my recommendation, but some of our fathers learned programming by punching holes in cards and they were successfull even with that.

1 Like

I would be interested to hear what other interpretations there are?

Call me old fashioned but in my world an "assembler" converts human readable mnemonics and such to actual machine instruction opcodes. It is totally machine ISA specific. Not portable between architectures. Having macros is a bonus for orchestrating this.

C programs are not machine architecture specific. They are portable. I call that a high level language. Not an assembler.

Did the definition of "assembler" change since I last used one?

I know nothing much of LLVM/LLVM IR. Surely that is just an implementation detail of a compiler? Are you really suggesting writing programs in LLVM/LLVM IR is akin to writing them in C?

Part of what I meant by "close" was that a C compiler cannot even generate a lot of instructions in modern CPU's. That is why we have intrinsics and inline assembler after all.

Yes. we agree.

As I said "C represents a machine to the programmer that has not existed for decades". Since the PDP/11 and the like it was developed on, as the article I linked to points out.

Turns out that today things like the x86 ISA also misrepresent what is actually going on in the processor.

True. But a "Macro Assembler", like MASM for example, allows one to create libraries of macros that expand to many mnemonics. This allows creating fairly high-level concepts. C isn't much different from that.

No, I'm suggesting that if one were to manually write LLVM IR (with Macros) it would be as cross-platform as C and nearly, if not equally, as high-level.

How far away from mnemonics or mnemonics wrapped in a macro do you consider intrinsics to be be. I would call them nearly equivalent (and equivalent for all practical purposes).

All of this being said, I think I (we) should perhaps open a separate thread if we wish to continue this line of inquiry as I believe we have inadvertently strayed off-topic for this post. My apologies for the divergence.

[Moderator note: Getting into the weeds about the comparative role of C and assembly is starting to stray from this topic. Let's redirect this to responding to the new user's original question rather than each other.]

3 Likes

Thank you for the input, others also say learning C to make learning Rust easier isn't a very good idea.

Thank you for the response, I see many others also recommend starting with Python or JavaScript and I think it might be a good idea. I am not sure if Python or JavaScript is the better start, you've stated that you recommend Python, but I've seen some people suggest learn nothing but JavaScript first due to the job opportunities.

I'd like to give my opinion as a 100% self-taught software developer that first learned to program at 13 on TRS-80/Z80, Tandy COCO/Motorola 6809, Atari 800/(I believe)Motorola 6502, Apple II/Motorola 6502, Mattel Aquarius/Z80 (btw, first computer I actually owned and to me at 14, the most expensive thing I had ever owned - I had to save paper-route money for months to afford the $100.00 cost at Kaybee Toys) etc.

All of these I initially learned to program using BASIC; however, with peek/poke (and hand assembling from mnemonics, to hex, to decimal), and later purchasing/obtaining assemblers, I rapidly moved into assembly programming.

I've heard many say that BASIC was a high-level language akin to Python, JS, etc. That is just not the case in my experience. First, BASIC was STRONGLY TYPED. For the most part, in most dialects, there were 3 types: Numbers (which were floating point or sometimes BCD behind the scenes), Strings, and Arrays. There were no other types and a variable was a specific type designated by a sigil/suffic ($ for Strings, nothing for numbers, or arrays). It mostly worked like assembler in that you had "goto" which was equivalent to "jmp" instruction, "gosub" which was equivalent to "longjmp/ret", simple loops, simple conditionals, etc. which all mapped very directly to the underlying CPU instructions. Line numbers were nothing more than equivalent to assembler labels that could be jumped to. Also, with peek/poke/call you could effectively do anything the hardware supported. This was the equivalent of "inline assembler" that easily permitted you to create the equivalent of "intrinsics" and there wasn't anything the hardware could do you couldn't access from BASIC.

With that being said, if we, as children could learn programming and even the low-level details of CPU's, the intricacies of different bases of numerical representation, graphics, etc., with NO ASSISTANCE AT ALL (other than the library) using those tools, there is absolutely no reason whatsoever that one cannot learn to program, from scratch, using Rust (especially given all the resources available without even having to get out of your chair).

I 100% believe (know) that a motivated, reasonably not dumb talented adolescent (or even a somewhat more than above average pre-adolescent) can, and should, learn to program and learn about computers using something like Rust. It ticks all the necessary boxes. The ONLY think that is needed, is a gentle tutorial with some motivating, simple examples and explanation for such a child to follow, which include:

  • How to say, "Hello Word!"
  • How to print your name
  • How to print your name repeatedly with line-wrapping such that it creates interesting patterns as the screen scrolls
  • How to do some basic arithmetic operations (along with a short tutorial/explanation of number-bases, binary, hexadecimal, and octal representation)
  • How to define and user variables
  • Integer and String types (later other primitive types, then types in general)
  • Basic loops (for over ranges for the most part to start)
  • Basic conditionals (like if/else)
  • Defining simple functions (using only Integer/String Types)/Calling them and getting the return value (equivalent of BASIC gosub)
  • How to use a simple graphics library and draw some basic 2D graphics with some color
  • How to play some basic sounds or music through an API (something like putting note names in a string along with durations for each note, passing it to a simple API call and having it play asynchronously) along with optional parameters for things like attack, decay, etc.
  • Some pointers on where to find more information and resources (like this forum, the "Book", other tutorials, exercises (age appropriate), etc)
  • How to do some simple inline assembly and how to use intrinsics

That's it. That is all that is needed. From there, the sky is the limit for anyone who really wants it. Most (if not all) of it already exists.

The notion that Rust can't, or shouldn't, be ones first language is a non-starter in my book. I believe (strongly) that not only can it be first, but it should be first.

3 Likes

I'm inclined to agree.

Those simple steps of computing we learned via BASIC can just as easily be learned via Rust.

Those more complicated thing we got into with PEEK and POKE and assembler can also be done more easily with Rust.

And then of course there is an ocean of stuff to learn on top of that. Which Rust is prepared for.

In a way the notion that those new to programming should learn with some other "lesser" language and then progress to Rust is as weird as suggesting young children in England should start out by learning some other language than English because it's too hard. Well, English is complicated and hard, that does not mean kids can't do useful things with it from a very young age.

Please substitute "English" for whatever other language you have, I think the argument holds.

1 Like

When I was a graduate student circa 1970, I was a teaching assistant for Astronomy 10, a course for science and math majors. Computing was new, and we wanted our students to learn programming. Fortran was the lingua franca of scientific computing, so that's what we taught.

Things didn't go well. Compiled languages have a lot of cruft to deal with. You have to learn the compiler commands, how to read the rather cryptic error messages from the compiler, debug from core dumps. Even getting output to the console involved learning how to format text. All that was even harder before we got teletypes and had to use punch cards.

Given all that, we decided to teach Basic first. Week 1 the students did a least squares fit to 10 points by hand. The next week they did the same problem in Basic. That got them over the hump of knowing what a program is. By week 3 they were able to write the program in Fortran and were off and running.

Things are better today, with smart editors and IDEs, but you still have to learn a lot just to use those tools. I'm a firm believer that it's easier to learn the basics (pun intended) of programming with a scripting language that has a simple run time environment.

That is a whole other question.

I would be very wary of those who say such things. I get the feeling there are thousands of people desperately trying to learn JS or whatever in the hope of "job opportunities" and that is the current hot thing. Sadly most will be wasting their time.

Perhaps I think like so because typically in my career I pretty much had to learn a new programming language for every project I got engaged in.

I don't think I could apply my mind enthusiastically and put the time and effort in to learn a programming language, or anything else for that matter, on the vague notion of "job opportunities".

But given a problem to solve, I'm all in to tackle whatever it takes. The financial incentive helps of course.

Outside of that I need to be curious, to have a passion, to study a thing. Rust has my attention in spades that way.

3 Likes