Plato has one saying that, it seems to me, would be especially useful for all software developers to know and take to heart:
The beauty of style, harmony, elegance, and good rhythm are based on simplicity.
This single sentence embodies the values that we, as developers, should admire.
There are a number of things we aim to achieve in our code:
- Readability - Ease of maintenance - Development speed - Elusive beauty
Plato tells us that all these qualities are possible only thanks to simplicity.
What is beautiful code? This is probably a very subjective question. The perception of beauty is heavily dependent on personal experience, just as our perception of anything else is. Those who have studied art perceive beauty differently (at least approach it differently) than those with a technical education. People with a humanities background usually consider the beauty of a program by comparing it to a work of art, while those with a technical education often discuss symmetries and the golden ratio, trying to reduce everything to formulas. In my experience, the arguments of both sides are mostly based on simplicity.
Think about the source code of all the programs you have encountered. If you have never studied code written by others, right now find some open-source code and study it. I’m serious! Look online for code in your favorite language written by a well-known and recognized expert.
You’re back? Good. Where were we? Ah, yes… I’ve discovered that the code examples that resonate with my soul and seem beautiful to me share some common properties. First and foremost, it’s the simplicity of the code. I believe that no matter how complex the application or system as a whole may be, its individual parts should be simple: simple objects performing a single task, and within them, equally simple specialized methods with well-understood names. Some consider it extreme to require methods to contain no more than 5-10 lines of code, and in some languages, this is very difficult to achieve. However, I still think that such conciseness is highly desirable.
The conclusion is as follows: beautiful code means simple code. All components are simple, solve simple tasks, and are connected by simple relationships with other parts of the system. This allows us to facilitate the maintenance of our system’s code, and understandable, simple, easily testable code will ensure high development speed throughout the entire lifespan of the system. Simplicity is the source and an essential attribute of beauty.