Rant after trying Rust a bit

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Fri Jul 24 03:15:37 PDT 2015


On 7/24/2015 3:06 AM, ixid wrote:
> On Thursday, 23 July 2015 at 20:09:34 UTC, Walter Bright wrote:
>> On 7/23/2015 7:49 AM, ixid wrote:
>>> If we had a clean sheet wouldn't it be better to have if return a value and
>>> ditch ternary?
>>
>> Then we'd start seeing code like:
>>
>>     x = 45 + if (y == 10) { while (i--) z += call(i); z; } else { switch (x) {
>> case 6: foo(); y; } + tan(z);
>>
>> I.e. the embedding of arbitrary statements within expressions. We already have
>> some of this with embedded anonymous lambda support, and I've discovered one
>> needs to be very careful in formatting it to not wind up with an awful
>> unreadable mess.
>>
>> So I'd be really reluctant to continue down that path.
>
> As opposed to:
>
>      auto n = {
>          if (y == 10) {
>              return {
>                  while (i--)
>                      z += call(i);
>                  return z;
>              }();
>          } else {
>              return {
>                  switch (x) {
>                      case 6: return foo();
>                      default: return y;
>                  }
>              }();
>          }
>      }() + tan(z);
>
> You can already do that, it's even uglier.

Nope. As opposed to:

     int r;
     if (y == 10) {
             while (i--)
                 z += call(i);
             r = z;
     } else {
             switch (x) {
                 case 6:
                     r = foo();
		    break;
                 default:
		    r = y;
	            break;
             }
     }

     x = 45 + r + tan(z);


More information about the Digitalmars-d mailing list