DEV Community

Discussion on: My First Month (or so) With Rust

jmccabe profile image
John McCabe • Edited on

I don't know your background, but I wanted to share a couple of thoughts..

1) "semicolons everywhere were kinda weird for me, but at least Rust doesn’t require explicit returns (and can avoid semicolons in the last expression too)."

Have you ever learnt Pascal? It also (at least, when I learnt it in 1983) had this. There's differentiation between function and procedures. Both return at the end (i.e. no jumping out in the middle, which was frowned upon at the time as doing so isn't much different to 'goto'), but the return value from a function is set by assigning a value to the function name. Interesting, worth a look! Also semi-colons separate statements, rather than terminate them, so not needed if the next bit of code (end of a subroutine for example) doesn't count as a statement.

2) "Ranges are not inclusive"

I don't know Ruby, but your comment made me look, as ranges are inclusive in Ada (released to the public in 1983), and Ruby has adopted similar 's..e' syntax. However you didn't mention Ruby's 's...e' syntax, which gives you a range that doesn't include the end index (alternatively the ::new(s, e, true) version, where the last parameter is 'exclude_end'). It seems like, essentially, Rust and Ruby have just chosen the defaults to be opposite.

3) "Underscores and numbers"

Yes, Ada (1983) has this. Also various number bases can be easily specified. For example:

16#ABCD_EF01# - - hexadecimal 32-bit integral value.
2#1010_1011_1100_1101_1110_1111_0000_0001# - - same in binary
3#0.1# - - base 3 floating point, => 1/3rd

4) "Rust has no ternary operator"

Neither had Ada originally, but "if expressions" and "case expressions", which are similar to the ternary operator, were added in 2012. It looks like they're also similar to Ruby's if/else expressions, so....

5) "The compiler is my friend"

This is what Ada programmers have known since the early '80s :-)

Thanks for the article. I've had a cursory glance at Rust, but never got very far since a lot of the 'simple' stuff appears to be a reinvention of the wheel, with different syntax for no apparent benefit. Maybe I should try harder :-)

matheusrich profile image
Matheus Richard Author

Thanks for your time writing this. Yeah, much of the things were quite similar between Ruby and Rust. Also, Ada was one of the languages that influenced Ruby, according to Matz.