Something Go and Scala syntax

bearophile bearophileHUGS at lycos.com
Thu Dec 30 04:05:32 PST 2010


Peter Alexander:

> but val is far too vague. It does not suggest that the value is immutable at all.

In Scala you tag assignments with "val" or "var". "var" means variable, and "val" means value, it's not mutable. I agree that "immutable" is a bit more explicit than "val", but I think "val" is acceptable...


> > An alternative is to use Go syntax, and use the Pascal-like ":=" to denote a value assignment (function signature can't use := ).
> > Here there is another idea from Go syntax: if the "then" clause of the "if" uses {} then the () around the test can be omitted:
> 
> Maybe I'm missing something, but what problem is this solving?

The same as "val". Instead of writing "immutable" you use ":=" (as in Go).

I agree all this post is just about three bits of syntax sugar, it's not Earth shaking stuff :-) But while writing D2 code I have felt a bit of resistance in writing "immutable" all the time, and this is bad, because D has to *encourage* the programmer to use immutable values where mutables are not necessary. This is why I have suggested possible ways to shorten the syntax.

Bye,
bearophile


More information about the Digitalmars-d mailing list