Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming

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:
  • Minimise state (Score:5, Interesting)

    by famebait ( 450028 ) on Wednesday March 26, 2014 @05:54AM (#46582327)

    You always have to keep in mind that code will be changed by serveal peopale, and your 'elegant' intention may not be understood or followed through by the next guy. So go for simple rules of thumb that not only keep your code readable and clear, but can accommodate future change while ramaining so.

    My number one rule for keeping code both readable and robust is this: Reduce state.

    I don't mean everything needs to be purely functional, but consider state a general liability to both correctness, readability, testability and maintainability. Less is more..
    * Whatever state you have should be focused and serve to explain/model the actual problem domain, not just 'keep stuff for later'.
    * Keep state as local as possible - most code is litered with instance variables that should have been locals and params.
    * Just because an object _can_ bundle state with its functions doesn't mean it _should_.
    * If it can be done in a static method and still make sense, do so.

  • FORTH (Score:5, Interesting)

    by Giant Electronic Bra ( 1229876 ) on Wednesday March 26, 2014 @08:55AM (#46583141)

    A complete highly extensible interpreted language with a built-in editor, macro assembler, etc in under 10k lines of code which did everything any modern scripting language does, except they all require at least 200KLOC to do it in.... This is the most elegant piece of software ever written, bar none. It isn't even a contest.

New York... when civilization falls apart, remember, we were way ahead of you. - David Letterman

Working...