in reply to How do you define "elegant"?

If we were doing 10 different things to the items in @foo, and some of them depended on what the individual item was, it would be inelegant to use map, and more elegant to use foreach.
Why?
@foo = map { super_complicated_transform ($_) } @foo; sub super_complicated_transform { #stuff goes here }
Isn't that elegant, too?


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: How do you define "elegant"?
by Mutant (Priest) on Aug 16, 2006 at 11:55 UTC
    Well, I guess you've proven my point :)

    I was meaning map would be inelegant if you tried to cram all that logic into the the map block (foreach would be a much better way to lay that out). But obviously your way to do it is also elegant.

    It's fairly easy to give examples of what is/isn't elegant, but I find it harder to come up with an actual definition.
      Wikipedia says
      ... a computer program or algorithm is elegant if it uses a small amount of intuitive code to great effect.
      Pretty much hits the nail on the head, I think.


      holli, /regexed monk/

        Define "intuitive"! We are exactly where we were. What's intuitive?

        IMHO, beauty, elegance and intuitivity (or whatever's the correct spelling in English) are all in the eye of the beholder. What's perfectly intuitive to me is bound to be counterintuitive or plainly a big meaningless mess to someone else.