in reply to Re^10: Thread on Joel on software forum : "I hate Perl programmers."
in thread Thread on Joel on software forum : "I hate Perl programmers."
Of course, in this particular case, the correct, optimal solution is trivial: my @grid = ( '01' .. '12' ) x 12;
Actually, no. That builds a single dimension array with 144 elements, not a 2 dimension array of 12 elements with 12 elements each.
In the more general case, I prefer another way, because it maintains symmetry: my @grid = map @$_, ( [ '01' .. '12' ] ) x 12;
Let's see.
And after all that, for the sake of "symmetry", you still end up with the wrong thing?
I just read that back and it sounds sarcastic, but it is not intended to be. I relish the opportunity to explain and defend my choices of coding style that so many people apparently find...shall we say eccentric :)
We may never agree on this, but what you are trying to avoid 1 .. 12; in favour of x 12;. Ie. You would like to avoid the generation of a list that doesn't get used except for the side-effect it produces.
But, in your code, you are producing a list of 12 references that only get used for the side-effect it produces! What is the difference between a list of 12 integers and a list of 12 references? Besides the memory consumed.
Whilst I agree that if/when the language supportes an x-like operator that executes it's left argument 12 times rather than executing it once and replicating it twelve times, I would use that in preference.
But until that operator becomes available, all those shinnanagins to avoid generating a list of integers that is only used for the side-effect of the iterations it causes, to me, introduces more obfusication, mis-direction and potential for misunderstanding and errors, than using the list for it's side-effects.
(*)Using the non-block form which even TheDamian agrees with me (in PBP) should be avoided.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^12: Thread on Joel on software forum : "I hate Perl programmers."
by Aristotle (Chancellor) on Nov 30, 2005 at 19:41 UTC |