Enhancing foreach

bearophile bearophileHUGS at lycos.com
Wed Jan 9 18:19:51 PST 2013


Jonathan M Davis:

> I would argue that the mistake is that iota(5) works. That's 
> not at all clear,

Clarity is not an absolute property, it's also correlated to the 
frequency of usage and commonality. A symbol like a cross "+" 
doesn't have much of intrinsic meaning, but most people know what 
it means from their study of mathematics.

Unlike the "+" symbol the word "range" has some meaning, suggests 
an interval or range. range() is used all the time in Python, 
almost in every loop, it's extremely common, so all Python 
programmers learn the usage of range() (newbies need a bit of 
time to learn the meaning of the optional third argument, but as 
far as I know they don't stumble on range(5) once they know all 
things in Python start from zero unless told differently).

In my code iota() is common, even if it's surely not as common as 
range() in Python. I think it's common enough that you remember 
that iota(5) is a range of five items. And D too is 0-based. (and 
iota in APL accepted one argument).

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list