3 ms·
I strongly disagree that Rust syntax is ugly, in absolute terms, even for the worst-case scenario presented in the article. Rust syntax is derived from a few ve
by zamalek 4y ago
I strongly disagree that Rust syntax is ugly, in absolute terms, even for the worst-case scenario presented in the article. Rust syntax is derived from a few very simple rules/concepts/themes. After observing how one set of operators/keywords combine, you should be able to make strong assumptions about how another set will combine.
Once the syntax sinks in, it's significantly easier to read than most other mainstream languages because there are significantly fewer rules/concepts/themes to comprehend.
As an extremely simple example, after learning what this does:
let a = loop { break 1; };
you can bet the programmer can figure out what's going on here:
let a = if true { 1 } else { 0 };
A language serves three purposes: it must be easy to write, it must be easy for a human to read, and it must be as unambiguous as possible (so that a computer can understand it). From a purely syntactical standpoint, Rust does great on all three. Most modern languages barely manage two.
* Form follows function. *
- kazinator 4y agoA binary file is derived from a very simple rule: (0|1)* There: now you know everything from SVR4 UNIX executable format to H.264 video wrapped in MP4 container! Go forth and decode ...
- Donckele 4y agoOK… So what does the first line of code do? You might as well say what the second line of code does - will save me time replying again ;)
- deleted 4y ago[deleted]
- doctor_eval 4y agoI have never written a line of rust in my life but I assume that a statement that terminates with a value can be used as a rvalue in an assignment or other expression. So (I guess) both examples set the variable to 1.
- metaltyphoon 4y agoYes
- Donckele 4y agoThanks for that. That logic of the “break” keyword given a parameter is unusual compared to to other languages. Maybe it was a bad example to use.
- at_compile_time 4y agoRust is an expression-based language, so a loop block is just an expression. Break exits the loop and returns the expression following the keyword, which is the integer 1 in this example, but it could also be nothing if the loop returns nothing (aka unit "()", aka void in some languages), or any other expression as well.
- friendzis 4y ago> must be as unambiguous as possible (so that a computer can understand it) A nitpick. Unambiguity (and other language features) is extremely important not that a computer can understand the language (it can), but rather that the understanding (or interpretation) of a program by programmer and computer are the same. Bugs like off by one, use after free and similar issues quite often stem from this misunderstanding.
- estebank 4y agoSource code is mainly a communication tool for other people, and less importantly, instructions for a computer. At the same time, compilers are an error reporting tool with a code generation side-gig.