The stupid question is the question not asked | |
PerlMonks |
Re: How do you define "elegant"?by BrowserUk (Patriarch) |
on Aug 17, 2006 at 00:23 UTC ( [id://567805]=note: print w/replies, xml ) | Need Help?? |
Elegance, in code, is when it's syntax reflects the semantics of the high level operation being performed, not the operational construction of how to perform it. A simple example, showing how syntax has evolved to do this (using half remembered FORTRAN & C). This
became this
became this
I worked under C coding standards for a while where the trinary* operator was prohibited as "too advanced"; maintenance programmers wouldn't understand it. Another, Perlish, example is;
versus
The syntax clearly and concisely captures the operation without the extraneous noise of scope levels, temporary variables or the need to push code off into a subroutine somewhere else in the file; much less a different file. And a final example from an earlier extended discussion:
This can also be written as
Yes, it forces the programmer to know what xor does and it's precedence; but I first used this expression in 1978/9 in Basic Plus, where xor was known as EQV. Encounter it once, look it up, use it and it will become a part of your lexicon. Elegance in fashion is often associated with things like "the simple black dress". A simple, unadorned black frock devoid of frills, bows or other extraneous accouterments that flatters it's wearer. Understated is the keyword. The secret of the simple black dress is in the hidden details. The precise cutting and expert tailoring that make it appear simply refined, whilst hiding the knowhow and detail that allow it to fit perfectly and so flatter. I would define elegance in code as concealed detail and hidden refinement. Concise syntax that completely captures the semantics of the high level operation whilst concealing it's mechanics. *Then trinary, now ternary--though I don't think that our kids ride terncycles; or play ternangles in school bands; or learn about ternceratops; or that the French flag is known as the terncolor; or that some gladiators fought with terndents; Nor do they eat ternfle for pudding :) Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
In Section
Meditations
|
|