On a language level, I miss how many statements became expressions in Rust. For example, I would really love to `if` be an expression in JavaScript. This makes a language so much more expressive.
And no, I don't think that `do expressions` proposal is really great solution.
Ternary operator don't nest very nicely though (they do nest , but it's not very readable). IMO a bigger difference is Rust's match and blocks also being expressions. These have no alternatives in JavaScript.
Nesting multiple branches of ternary operators doesn't work well but if it's a sort of “if elseif elseif else” situation I think this looks pretty nice:
Agreed. There are so many nice little touches in Rust that having nothing to do with it's "safe + low-level" USP. I would love to see a Rust-style language (expression orientation and rust-style enums being top of my wish list) in the javascript/python/ruby/php niche.
There are so many nice little touches in Rust that having nothing to do with it's "safe + low-level" USP.
Exactly this. I generally get met with skepticism when talking about Rust for web dev, because so many people say "you don't need that performance" (which is itself pretty arguable if one cares at all about energy footprint), but it isn't just the performance that makes Rust such an attractive option.
Comments
On a language level, I miss how many statements became expressions in Rust. For example, I would really love to `if` be an expression in JavaScript. This makes a language so much more expressive.
And no, I don't think that `do expressions` proposal is really great solution.
You want a conditional expression in JavaScript ? you could use the ternary operator : you don't have to use it if you don't want to though;
Ternary operator don't nest very nicely though (they do nest , but it's not very readable). IMO a bigger difference is Rust's match and blocks also being expressions. These have no alternatives in JavaScript.
Nesting multiple branches of ternary operators doesn't work well but if it's a sort of “if elseif elseif else” situation I think this looks pretty nice:
But not nearly as nice as:
I actually made a library for that!
It's published on npm and everything. It's small, a bit unpolished, maybe needs more docs, but it works pretty damn well if you ask me!
https://gitlab.com/svartkonst/match
I see what you did there ( ͡° ͜ʖ ͡°)
Agreed. There are so many nice little touches in Rust that having nothing to do with it's "safe + low-level" USP. I would love to see a Rust-style language (expression orientation and rust-style enums being top of my wish list) in the javascript/python/ruby/php niche.
Exactly this. I generally get met with skepticism when talking about Rust for web dev, because so many people say "you don't need that performance" (which is itself pretty arguable if one cares at all about energy footprint), but it isn't just the performance that makes Rust such an attractive option.