DEV Community

Cover image for Getting familiar with Rust's Syntax

Getting familiar with Rust's Syntax

Francesco Ciulla on July 31, 2024

So, you've decided to learn Rust. Good choice! Rust is an awesome language that combines the power of systems programming with modern language fea...
Collapse
 
silvesterwali profile image
silvesterwali

thank you for sharing ...simple and easy to understand

Collapse
 
francescoxx profile image
Francesco Ciulla

That was the goal of the article: simplifying the rust syntax. Of course, it's not exhaustive, but it was more about lowering the complexity barrier. Thank you

Collapse
 
dung_truong_9dc5b43380474 profile image
Dung Truong

:)

Collapse
 
ezpieco profile image
Ezpie • Edited

I was going to learn rust, this is a good starting point. Especially the ownership and borrowing part, I can assure you that I have missed up a lot of C code... mostly skill issues as always.

Collapse
 
francescoxx profile image
Francesco Ciulla

glad it helped

Collapse
 
igor_vasilchikov_d1f4b6a5 profile image
Igor Vasilchikov

Beautiful, thank you . It feels like rust is Somewhat similar to scala and golang ...

Collapse
 
kerkg profile image
kerkg

Gonna implememt life times To my language, thanks

Collapse
 
francescoxx profile image
Francesco Ciulla

lifetimes is a concept specific to the rust programming language

Collapse
 
kerkg profile image
kerkg

Im sure they wont mind me using as well

Thread Thread
 
francescoxx profile image
Francesco Ciulla

gl

Collapse
 
jim_dunstan_5e3d97186c0a7 profile image
Jim Dunstan

What a great article.. Rusts pattern matching is really clever. I'm bored to death with C#, and Rust seems to inspire me again

Collapse
 
nikunjbhatt profile image
Nikunj Bhatt

Very inconsistent, irregular, weird and illogical systax. 🤦

Collapse
 
ken-preston profile image
Ken • Edited

It really is, no wonder Rust programmers make $30k/year more than us "lowly" C++ programmers at my company, no one can tell if what they're doing is right or not🤦🏼‍♀️ But here I am learning it since it's the only way I'll make over $200k without scoring a senior role...

Collapse
 
francescoxx profile image
Francesco Ciulla

interesting take, it seems the opposite to me. Can you elaborate on each point?

Collapse
 
nikunjbhatt profile image
Nikunj Bhatt
  1. Weird: In Rust, Variables are not variables, they are constants by default! And one has to use mut to define a variable variable! While most of the programming languages require to define constants by some other specific way.
  2. Irregular/Inconsistent: In Rust, a function's statement without semicolon is considered a return statement. It would be considered an error in other programming languages as the statement is missing a semicolon.
  3. Weird: Why there are "ownership" and "borrowing"!? (Or I think the example provided here for "borrowing" is not enough to understand "borrowing".)
  4. Illogical: In the Pattern Matching, there is 6..=10. Is .. one operator or ..=? If .. is an operator then other match/switch cases should also be prefixed with =, for example: =1 => println("One!"). Otherwise = in ..= seems extra.
  5. Weird: Error handling is also weird, or I am not able to / this post has failed to make me understand it.

Plus, I have some questions/doubts:

  1. The example of lifetimes is unclear. What are the meanings of single quote and "a"?
  2. The pattern matching example has a comma after each statement, why not a semicolon? Why the last default _ statement has a comma too?
  3. From the error handling and the ? operator examples, it looks like the code is returning Ok or Err. What does returning Ok or Err means?

It's fine if you don't make any changes to the post to make me understand or explain anything here. I don't know Python language but I have read its documentation for beginners and I liked its syntax. Python seemed most logical than most of the programming languages.

Thread Thread
 
dotsilas profile image
Silas Duarte

Immutable variables are not constants, since their values ​​are not known at compile time, constants are values ​​written to the binary during compilation; immutable variables can be assigned during program execution and immutable from there. There are several compression errors like this in all your criticisms, but I think the main one is that you think Rust has to look like the languages ​​you know and there is absolutely no reason for that. All languages ​​are different!

Thread Thread
 
thiagomg profile image
Thiago Massari Guedes

@nikunjbhatt I think you are complaining that Rust does not look like some languages you know.
Many of those weirdness you cited come from SML. If you are curious, see how to implement binary tree in SML. It's super easy. The pattern matching and algebraic datatypes came straight from there (or some other language of the SML family)

Collapse
 
thiagomg profile image
Thiago Massari Guedes

Why? I am curious now

Collapse
 
sairamthedev profile image
Sairam Mangeshkar

Indeed!