4 ms·
It always strikes me that the top voted answer in this type of discussion just replaces one adjective (elegant) with other adjectives (simple, succinct, readabl
by zwieback 15y ago
It always strikes me that the top voted answer in this type of discussion just replaces one adjective (elegant) with other adjectives (simple, succinct, readable). "Elegant" appears to be a combination of other, more fundamental aspects which need to be defined to know what elegance means.
So how do we define "simple" and "readable" and what tools do we use, other than years of experience, to achieve simple and readable code. I think that's the more fruitful debate.
- jerf 15y agoAidan Cully's answer has some meaningful content: http://programmers.stackexchange.com/questions/97912/how-do-you-define-elegant-code/97973#97973 http://programmers.stackexchange.com/questions/97912/how-do-... It's also pretty close to my answer, except I would say that he gets bogged down in visual complexity and I'm more interested in the more empirical concerns of information content. Assuming "good" style, a solution that is minimal, contains only essential complexity, and nothing more, is elegant. Languages differ in their general elegance by virtue of their ability to separate essential complexity from accidental complexity. For instance, C is hobbled in the contest to create truly elegant code, because in its capacity as "portable assembler" you can't ever really ignore memory management, which is in the accidental complexity domain for the vast bulk of problems.
- buro9 15y agoAgree here too. It always makes me think of Hemingway and his ability to never use more words than necessary to say something, and at that, always the words that say it best. Someone else picked up on the similarity between the Hemingway rules for writing well and parts of the UNIX philosophy: http://unix-simple.blogspot.com/2011/03/unix-and-hemingway.html http://unix-simple.blogspot.com/2011/03/unix-and-hemingway.h... It should be noted that Hemingway's fifth rule "5. Write one page of masterpiece vs. 91 pages of garbage." doesn't infer writing complex sentences, but emphasises not using 10 words when 1 will do.
- BruceJillis 15y agoAgreed, there is a pretty good discussion over on the portland pattern repository that echoes your take: "Elegance" really just means "has a lot of nice properties". So, when someone claims 'elegance', you should stop them and ask for clarification on the precise properties or features they are examining. source: http://c2.com/cgi/wiki?ArgumentByElegance http://c2.com/cgi/wiki?ArgumentByElegance
- zwieback 15y agoAhhh, thanks for the link. That page brings back two cherished memories: the C2 Wiki and the indefatigable TopMind!
- joe_the_user 15y agoThe thing I'd say about "elegant" is that elegance achieves some combination of desirable characteristics so well that it stands out as a noticeably better solution. If you can use three somewhat obscure lines to do what someone else take five readable pages to do, you're elegant even the code isn't that readable. That said, since true elegance is kind of exceptional, it probably shouldn't be the criteria for acceptable code - "clear, readable and reasonably" is a better standard to have.