in reply to Beautiful code I wrote ;-)

It *is* beautiful! Symmetry seems to be a powerful attractant visually; I am always fascinated by it. Nice job!

Spending most of my time applying Perl to my real-world problems sledom leaves me much opportunity to appreciate some of the eye-pleasing constructs, obfuscated Perl or not, that pop up. I would, of course, agree with moritz and kalium that I wouldn't want your construct in my work code...nightmare to try to maintain...especially by someone other them myself if I put it there. But I'm presuming you would already know that and just found the construct beautiful.

Thanks for giving me a moment to just "stop and smell the roses" (so to speak) and see code through different glasses.

ack Albuquerque, NM

Replies are listed 'Best First'.
Re^2: Beautiful code I wrote ;-)
by Skeeve (Parson) on Jul 12, 2008 at 07:52 UTC

    To be honest: It's still in there.

    I don't see why this code should be "obfuscation". Yes. It might be difficult to tell the precedence of << and >> (which is equal) or the associativity. But that's the same with any operator.

    Just because it's seldom used doesn't make this a valid argument.

    And I think bitshifting is more appropriate to the task at hand than multiplication. After all: I have to set one bit.

    The only way I can think of making it clearer is either (1<<$_)>>1 or 1<<($_-1) The later I think is a bit unclear as one has to know that shifting left by a negative amount is in fact shifting right.


    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

      You know, I've thought about this post for several days and I think it is not nearly as 'obfuscated' as I had originally thought.

      The shift operator is one we actually us a lot in our work and I got to thinking and wandering how much we used it. That thinking got me curious and I looked back at various test modules we've written to see just how often it does show up (I even wrote a little Perl script to go through our current stock of modules and actually count how many times it shows up...my associates now think I'm totally crazy). It shows up even more than I had remembered.

      More importantly, I actually found your very constuct in one of our modules. It had a bunch of parentheses around to try to 'make it clearer'...it actually now looks much more obfuscated that your more eye-pleasing construct.

      Out of curiosity about how my more seasoned test module programmers would see your construct, I showed a couple of them your construct and the one in our code (neither of them was the author of our version). Both of them said (I paraphrase) "Wow! Much cleaner!"

      So I would have to back off from thinking yours was 'obfuscated.' Depending upon one's perspective and needs I can see how one might say your construct could be perceived as 'obfuscated' (certainly I did at first); I wouldn't begin to argue...I'm not that experienced. But I, for one, have revised my opinion in those terms.

      But independent of whether one sees your beautiful construct that you put forth, it still remains very beautiful to me.

      ack Albuquerque, NM