From: Chad Perrin Date: 2007-10-02T15:51:19+09:00 Subject: Re: Can you please help to make decision? On Tue, Oct 02, 2007 at 04:58:10AM +0900, Chad Perrin wrote: > On Mon, Oct 01, 2007 at 03:25:37AM +0900, 7stud -- wrote: > > Here's a simple test for the op. Which of the following do you think is > > easier to understand? Can you guess what each program does? > > > > language1: > > -------- > > > > colors = ["red", "blue", "green"] > > > > colors.each {|color| puts color} > > > > > > language2: > > --------- > > colors = ["red", "green", "blue"] > > > > for color in colors: > > print color > > In the case of someone who has never programmed before, I rather think > "colors.each {|color| puts color}" might be less confusing than "for > color in colors:\n print color". I have never in my life seen anything > in plain English that even began to look like "for color in colors", and > the meaning of that clause is non-obvious. Meanwhile, "colors.each" at > least looks like it's saying something about each of something, with the > "each" attached obviously to the "colors", suggesting that it's saying > "for each element of the colors array". > > The only way the Python one looks anything like "more intuitive" to > someone who has never encountered Ruby or Python before, as far as I can > tell, is if that person is familiar with C. . . . and while I'm at it, I think this might be even more easily understood (ignoring for a moment the variable sigils): @colors = ("red", "blue", "green") print foreach @colors; On the other hand, I doubt you want to advocate Perl -- particularly if you're a Pythonista. Also, as others have pointed out, the Ruby iterator could just be replaced with `puts colors`. -- CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ] Patrick J. LoPresti: "Emacs has been replaced by a shell script which 1) Generates a syslog message at level LOG_EMERG; 2) reduces the user's disk quota by 100K; and 3) RUNS ED!!!!!!"