Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jjohn (22)

jjohn
  (email not shown publicly)
http://taskboy.com/
AOL IM: taskboy3000 (Add Buddy, Send Message)

Perl hack/Linux buff/OSS junkie.

Journal of jjohn (22)

Friday April 26, 2002
07:36 AM

A Perl 6 Request: No Duff's Device

[ #4477 ]

Duff's device is a ingenious and nails-on-chalkboard irrating C "idiom" that was designed to move bytes serially into some hardware device (not memory, probably a video card(?)). It exists because a simpler while loop took too long. It is an example of loop unrolling, a technique somewhat unused in Perl because it is only justifiably employed in high performance applications (eg. animation, games). What makes this code so abhorrant is that it looks like the result of a high-speed impacted between a switch statement and a while loop.

Please, please, great Larry and Damian, do not let Perl 6 allow insanity like this. Perhaps this is the reason Perl has no switch statement?

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I just checked tha apocalypse and it is actually allowed!!! I was most surprised. Although you do have to go slightly out of your way to use it, the usual:

        given $foo {
            when "first" { ... }
        }

    Syntax won't allow it (when appears to imply a terminal break), you have to do:

        given $foo {
            if /^first$/ { ... }
        }

    Now there is no implied break. Damned weird...
  • ... what pumpkining does to one's brain: I find Duff's device to be completely fine C.

    • On the other hand, it seems rather pointless to use it in Perl. If you need a tight loop of just a few instructions, why are you running with an interpreted language? If you don't need that tight loop, write the code clearly.
      • But, but, Duff's device *is* clear C...
        • Um, well, ...

          It works well, and I understand it fine, and I like it, but there is an inherent inclarity in having the targets of the switch nested an extra block level below the switch body, inside a different control construct. Imagine putting an else block inside a structure nested within the then block - that's the closest you can come to doing the same thing anywhere else in the language without using goto's.

          Tom Duff (whom I used to play Dungeons and Dragons with before he moved from Toronto to Cali
        • for some values of 'clear', sure. ;-)