News for hackers. Stuff that matters.
Re:How true hackers write JavaScript by steveklabnik on Wednesday September 05, 2018 @07:14AM (#17916850)
It does seem strange if you think of it as “return the last evaluated thing from the function.” But that’s not the semantic; the semantic is “everything is an expression and expressions evaluate to a value.” Removing this behavior would make these languages less consistent.

(And yes, in both Ruby and Rust not literally everything is an expression, but almost everything is.)

Re:How true hackers write JavaScript by cyphar on Wednesday September 05, 2018 @07:51AM (#17917060)
I agree that because of common uses of things like match in Rust it makes it consistent to also do it for functions. I don't agree that the reason why it's consistent is because a function body is an expression (though of course you have more expertise than me on this one -- and Rust does actually treat scopes much more strictly than most other languages so you could argue every scope has the smell of a function call associated with it).
Re:How true hackers write JavaScript by steveklabnik on Wednesday September 05, 2018 @09:06AM (#17917507)
Here's the citation: https://doc.rust-lang.org/reference/items/functions.html

> A function consists of a block, along with a name and a set of parameters.

https://doc.rust-lang.org/reference/expressions/block-expr.h...

> Blocks are always value expressions and evaluate the last expression in value expression context.