|
|
|
|
|
by chrismorgan
4376 days ago
|
|
I came from a primarily-Python background; that the last value in a block is the outcome of the expression seemed to me a gimmick when I first started writing Rust (just under a year ago)—I, as you appear to be doing, only saw it as relevant at the end of a function, thus saving only half a dozen letters. I quickly discovered that it is not a gimmick; the fact that it applies to any expression is marvellously useful in Rust code, with its everything-is-an-expression doctrine. (For a language like Python, without this orientation, it would be just a gimmick.) That the last value in a block is the value of the expression is something that makes a lot of code much more readable, as it frequently obviates the need for additional temporary variables. I was sceptical until I actually used it. Now I’m converted; though I still also like Python’s pure statement-oriented approach in various ways, I prefer Rust’s model. |
|