I’m currently learning Rust through rustlings. After completing one task, I asked myself a question. Does Rust plan to continue pushing its message of accessibility, understandability, simplicity, and zero-cost abstractions? What I mean.
After completing some task, I saw the following code I wrote.
It seems that we have practically no semicolons and quotation marks here. It is clear that quotation marks and semicolons separate our lines of code into logical steps. However, I was surprised that my code compiled with a minimum number of these logical symbols.
I would like to immediately note that I am not an ardent opponent of Rust syntax. It would seem that if you don’t like it, write in Python. Here is an interesting moment in the development of Rust. With the release of new versions, Rust seems to be becoming simpler and simpler in syntax, more and more understandable. It seems to be trying to syntactically disassociate itself from the syntax of C/C++, in which any operations are defined at a very low level, which prompted the creation of high-level languages - Java, Python, and so on. However, Rust, as I see it, takes this problem into account and adds convenient abstractions, so I like to write in it like in Python. How wonderful the for loop is 🙂
However, why am I picking on these semicolons and quotes at the end? This is not interpreted Python. However, Rust allows you not to write this at the end and in the loop, which is already hinting – hey, this is not C, I use what fits in my head and go through the loop as simply as possible.
And so I wanted to ask the Rust guru programmers, who also wrote in other languages before, for example Python. Do I understand correctly that Rust could ideally go over indents like Python???
What’s the question? Well, look, what’s stopping me as a programmer from writing all my Rust code in one line? It’s okay, and the code will compile. Unless the developer next to me just stops working with me. It would be cool to add this strictness at the language level, not the style checker.
What does this give us? Strictness, structure, clarity, compactness, uncompromisingness, and less code. After all, everyone already knows that code is read more than written.
Why should you even care about this? Well, look, anyone who studied Python programming from Mark Lutz’s books Learn Python
and Programming in Python
will understand. Namely, he writes that
He is tired of writing the same thing every time to do a simple thing
A large code in C and even a small part of it simply does not fit in the head because each operation, function in which primitive logic occurs is written in a bunch of lines of code
Also, these semicolons and {} just clutter the code and make it already smeared
There were many comparisons with other languages and other reasons why you need to learn Python. Of course, I could have messed up something or left something out. Correct me if anyone readed Mark Lutz’s books Learn Python
and Programming in Python
.
And I repeat, Rust is trying not to classify itself as C and does everything possible from the best practices of languages by adding zero-cost abstractions, automatic dereferencing of pointers, automatic type detection based on the passed argument (let num = 1;) and so on.
I liked this post where the author of the comment discusses the need and compromises when adding generators to Rust. And indeed, generators are necessary, they are very simple in the mind and their implementation is very non-trivial.
Comment
byu/desiringmachines from discussion
inrust
And each such innovation makes Rust simply beyond competition for system programming and even web programming with extreme loads, because it is compiled and written just like Python.
I have a rough idea of what Rust developers must go through to satisfy the needs they have set their sights on (simplicity, performance, security, some kind of hybrid of Python and C++). I understand that all this is complex and ambiguous and it is easier to change nothing at all and write in Golang without generics and if error else. However, I think Rust has a very big potential to become a second language to help Python, besides Python itself of course.
And still, what do you think – is changing the syntax to indents like Python in theory better than the existing syntax in the long term or not and why?
fn vec_loop(input: &[i32]) -> Vec<i32> {
let mut output = Vec::new();
for element in input {
output.push(2 * element)
}
return output
}
user26560400 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.