foreach syntax

Timon Gehr timon.gehr at gmx.ch
Fri Jun 29 07:47:19 PDT 2012


On 06/29/2012 04:34 PM, 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 ",".
>

I don't think optimizing the grammar for error cases that are not even
compilable code is worthwhile at all.

> "in" is used for this purpose in Python, C#, and probably other
> languages because it's more readable

Probably it is used in those languages because it resembles
mathematical notation, or let var in exp. I doubt there is anything
deep behind it.

> than an arbitrary symbol like ";".
>

Probably, but when I read code, I don't read the ';', it is just a
separator and helps orientation. Making separators 'readable' is imho a
non-goal. But YMMV. Patching the parser so that it accepts both forms
takes 20 seconds.


More information about the Digitalmars-d-learn mailing list