foreach syntax

Jonathan M Davis jmdavisProg at gmx.com
Fri Jun 29 07:51:54 PDT 2012


On Friday, June 29, 2012 16:34:33 bearophile wrote:
> Timon Gehr:
> > foreach(x in y,data)
> 
> There is no way to avoid all possible mistakes, but it's easier
> to mistake a ";" for a ",", than mistake a "in" for a ",".
> 
> "in" is used for this purpose in Python, C#, and probably other
> languages because it's more readable than an arbitrary symbol
> like ";".

And in Java, they use : rather than ; or in. This is completely subjective. I 
see _zero_ benefit in using in over ;. ; is nicely consistent with for, and is 
probably why foreach in D uses it. But regardless, it's purely a subjective 
choice. Walter picked what he picked. C# and python picked what they picked. 
Java picked what they picked. I really don't think that you can objectively 
argue that one is better than the other - not unless one is objectively easier 
to write the grammar for. Anything involving whether a person thinks in is or 
; is easier to read or will cause fewer mistakes or whatnot is going to be 
purely subjective.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list