Something Go and Scala syntax

bearophile bearophileHUGS at lycos.com
Thu Dec 30 09:57:01 PST 2010


Adam Ruppe:

> bearophile wrote:
> > writing "immutable" often is boring and makes code longer.
> 
> im<tab>   ->  immutable

That doesn't shorten the code.


> btw you might say "an editor is no excuse for bad language design"
> but this isn't bad language design, it's just a preference on your
> part. So it should be fixed on your end.

I prefer something like "val", it's shorter to write, uses less space, it's clear enough, it's used in another language (Scala). (Is "immutable" just a preference on your part?). I agree that "immutable" is a bit more clear, but immutable is not a rare keyword, probably it's present every 3-10 lines of my code, so your eye doesn't need to read "val" every time, it becomes a gestalt. The high usage frequency of "immutable" suggests its shortening according to Zipf law (http://en.wikipedia.org/wiki/Zipf%27s_law )...

Lot of time ago I have even suggested to replace "string" with "str" as in Python, I find it better and good enough :-)


> And if those 6 extra characters when reading (which are significantly
> easier to spot than the difference between a 'r' and a 'l' in the
> middle of an otherwise identical line!)

In D there's no "var", so this isn't a problem for D, it's a Scala problem.


> cause length problems, your
> line is likely too long to begin with.

Very recently I have people saying me that using qualified import is bad because it makes lines longer :-) The difference is that "immutable" => "val" is not a semantic change, it's just a name change, while changing how default import work changes semantic a little.
In my opinion replacing "immutable" with something shorter will encourage some lazy typists in using that keyword more often :-)


> That looks awful. It seems Go programmers don't care about tidy code.
> Languages should avoid such special cases.

I agree that special cases are not good. Go designers seem to value code succinctness much more than you and me and Walter :-)

----------------------

Spir:

> (see also http://spir.wikidot.com/create-vs-change -- I would enjoy having Bearophile's critics on this article ;-)

I am able to accept to tell apart update from creation, but the :: syntax doesn't look natural enough to me, I am too much used in seeing an equal sign somewhere there.

Bye,
bearophile


More information about the Digitalmars-d mailing list