Rant after trying Rust a bit
Andrei Alexandrescu via Digitalmars-d
digitalmars-d at puremagic.com
Thu Jul 23 06:30:51 PDT 2015
On 7/22/15 5:36 PM, jmh530 wrote:
> On Wednesday, 22 July 2015 at 20:43:04 UTC, simendsjo wrote:
>> When "everything" is an expressions, you can write things like
>> auto a = if(e) c else d;
>>
>> In D you have to write
>> type a = invalid_value;
>> if(e) a = c;
>> else a = d;
>> assert(a != invalid_value);
>>
>
>
> I prefer this example from one of the various Rust tutorials
>
> let foo = if x == 5 {
> "five"
> }
> else if x == 6 {
> "six"
> }
> else {
> "neither"
> }
>
> You're basically using a conditional expression as an rvalue. You can do
> the same thing with a { } block.
I used to be quite jazzed about the everything-is-an-expression mantra,
but it's not all great.
1. Inferring function return types when everything is an expression
(i.e. last expression there is the return type) may yield WAT results.
2. Defining a result type for loops is awkward.
At the end of the day everything-is-an-expression is natural for
functional languages, but doesn't seem it makes a large difference to an
imperative language.
To OP: thanks for your rant! Instead of getting defensive we'd do good
to derive action items from it.
Andrei
More information about the Digitalmars-d
mailing list