Comment Elegant code is... (Score 2) 373
Elegant code is...
- Simple -- leveraging the "natural" way to use the programming language
- Compact -- not cluttered with special cases and boilerplate
- Logical -- like secondary documentation, acting as a clear description of how to solve a problem
- Modular -- functions or classes should be clearly grouped as modules
- Easy to understand -- not full of stupid hacks and "clever" tricks
- Reasonably efficient -- performing reasonably well, not at the expense of simplicity
- Maintainable -- any decent programmer could pick up the code without fear and trepidation
- Commented -- some comments should be present, but not too much
- Correct -- it should do what it is meant to do, and only this
There are also some languages that I view as inherently elegant, and others that I consider not to be so. C, Python, and Ruby all allow breathtaking elegance in their own way. C with its spartan manner of managing the machine, Python with its ridiculously readable pseudocode-like syntax, and Ruby with its pure object system and powers of abstraction. On the other hand, some other languages like C++, Java, Haskell, Javascript, PHP, BASIC, and Erlang will never be languages that lend themselves to true beauty and elegance. All of those languages either have serious flaws, or they do not allow programmers to express their ideas eloquently in code. In a good language, your ideas should pop out as the most important thing, not the language itself.