From: Ross Bamford Date: 2006-01-04T03:22:58+09:00 Subject: Re: Implicit block parameter? On Tue, 03 Jan 2006 17:26:15 -0000, wrote: >> >> Hmm, I might put together a bit of a proposal and do that. I hope >> you'll comment when you vote no, I'd be interested in your perspective >> on this :) > > I don't like it. I've never felt there was a problem to solve in this > area, since it's so easy to specify an argument list. Having a magic > variable ("it" or $_ or whatever) seems like a step backwards, in > terms of clarity and consistency. > I do agree that from a readability point of view it's potentially confusing, and newcomers to Ruby could look at it and wonder where the hell 'it' came from. I think though that $_ is a different argument (again, no pun intended), since that introduces stuff like: [1,2,3].each { print if ~/.../ } which I couldn't convincingly argue for even were I paid to do so. This kind of 'invisible data' confuses the hell out of me, and is IMHO one of Perl's most evil features. On the other hand: [1,2,3].each { puts it if it =~ /.../ } (again ignoring the TMTOWTDI aspect for the sake of example) at least (to me) implies some relationship between the message sent and the data - it says to me "take each number from the array and output it if it matches this". Granted, it's not vastly different from: [1,2,3].each { |it| puts it if it =~ /.../ } but the extra 'it' (or whatever) in there just grates (admittedly only slightly) on my nerves. It also gets a bit worse when you have stuff like: [[1,2,3],[2,3,4],[3,4,5]].each { |it| it.select { |it| it % 2 == 0 } } [[1,2,3],[2,3,4],[3,4,5]].each { it.select { it % 2 == 0 } } (I've not tested that btw but you get the idea). However I guess with that it's also potentially confusing when using the implicit idea, since it has the same magic variable meaning two different things in the same line. I guess in this case I'd probably declare the argument in the select block anyway (as 'i' or something). -- Ross Bamford - rosco@roscopeco.remove.co.uk