Rant after trying Rust a bit

Ziad Hatahet via Digitalmars-d digitalmars-d at puremagic.com
Thu Jul 23 13:47:54 PDT 2015


On Thu, Jul 23, 2015 at 8:41 AM, Jonathan M Davis via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> Maybe, but the ternary operator is a lot less verbose
>

The ternary operator becomes much harder to read the moment you have more
than the simple if/else case. As it was mentioned elsewhere on this thread,
you can do the following in Scala:

val x = if (condition_1) 1
           else if (condition_2) 2
           else if (condition_3) 3
           else 4

Having expressions be "built-in" extends beyond the simple if/else case,
which can be emulated with the ternary operator as you said. You can assign
the result of match expressions for instance, or the result of scoped
blocks, .e.g.

val x = {
    val ys = foo()
    ys.map(...).filter(...).exists(...)
}

, and from some other comments in this thread, it sounds like the way they
> implemented it in Rust forces you to use braces for single line statements,
> which would be a _huge_ downside IMHO.
>

On the other hand, Rust does not require parenthesis around if conditions:

let x = if some_condition { 1 } else { 2 }


> I'm inclined to think that it would need a use case that's a lot more
> compelling than if-else chains to be worth it.
>
>
I provided examples above.



--
Ziad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20150723/b77e3b54/attachment.html>


More information about the Digitalmars-d mailing list