Do you think if statement as expression would be nice to have in D?

Walter Bright newshound2 at digitalmars.com
Sat Jun 4 09:56:52 UTC 2022


On 6/3/2022 11:33 AM, Jack wrote:
> Rust does support it like that:
> 
> ```rust
>      const limit:i32 = 30;
>      let n = 10;
>      let mut r = if n > limit { "big" } else { "small "};
>      println!("{} is {} than {}", n, r, limit);
> ```
> 
> do you think would be nice that in D as well? I find it can increase code 
> reability...

D has:

     auto r = (n > limit) ? "big" : "small";

which is more readable than Rust's :-)


More information about the Digitalmars-d mailing list