Want to read Slashdot from your mobile device? Point it at m.slashdot.org and keep reading!


Forgot your password?

Ask Slashdot: What Do You Consider Elegant Code? 373

lxrslh writes: "Since the dawn of computing, we have read about massive failed projects, bugs that are never fixed, security leaks, spaghetti code, and other flaws in the programs we use every day to operate the devices and systems upon which we depend. It would be interesting to read the code of a well-engineered, perfectly coded, intellectually challenging program. I would love to see the code running in handheld GPS units that first find a variable number of satellites and then calculate the latitude, longitude, and elevation of the unit. Do you have an example of a compact and elegant program for which the code is publicly available?"
This discussion has been archived. No new comments can be posted.

Ask Slashdot: What Do You Consider Elegant Code?

Comments Filter:
  • Duff's Device (Score:5, Informative)

    by smittyoneeach ( 243267 ) * on Wednesday March 26, 2014 @05:05AM (#46582153) Homepage Journal
    Duff's Device [wikipedia.org]
  • Re:Duff's Device (Score:3, Informative)

    by Anonymous Coward on Wednesday March 26, 2014 @05:25AM (#46582219)

    Uh... that Wikipedia article shows 3 lines of code, which it describes as "straightforward":

    Straightforward code to copy items from an array to a memory-mapped output register might look like this:

    do { /* count > 0 assumed */
            *to = *from++; /* Note that the 'to' pointer is NOT incremented */
    } while(--count > 0);

    Then this reference implementation of Duff's device:

    send(to, from, count)
    register short *to, *from;
    register count;
            register n = (count + 7) / 8;
            switch(count % 8) {
            case 0: do { *to = *from++;
            case 7: *to = *from++;
            case 6: *to = *from++;
            case 5: *to = *from++;
            case 4: *to = *from++;
            case 3: *to = *from++;
            case 2: *to = *from++;
            case 1: *to = *from++;
                    } while(--n > 0);

    Then this penny drops:

    When numerous instances of Duff's device were removed from the XFree86 Server in version 4.0, there was an improvement in performance

  • by Anonymous Coward on Wednesday March 26, 2014 @05:26AM (#46582221)


  • GPS code (Score:4, Informative)

    by tlambert ( 566799 ) on Wednesday March 26, 2014 @05:39AM (#46582275)

    http://www.gpstk.org/bin/view/... [gpstk.org]
    http://www.rtklib.com/ [rtklib.com]
    http://gnss-sdr.org/ [gnss-sdr.org]

    Next time do your own google search.

  • by jonwil ( 467024 ) on Wednesday March 26, 2014 @07:11AM (#46582587)

    As someone who has a copyright assignment on file with the FSF for GCC and actually tried to write an implementation of the Visual C++ __declspec(thread) keyword for GCC-on-windows (i.e. proper OS-provided thread-local-storage support) and got lost somewhere deep in the code that actually converts the intermediate representation into assembler (I needed to do stuff to it so it would correctly access the thread-local-storage data when an access to a thread local variable was made) I question your statement that GCC is well-written, elegant or easy to understand...

Don't tell me how hard you work. Tell me how much you get done. -- James J. Ling