This post explains what is eloquent code to me and why. Note that I am still within my first year of learning to code when writing this so take it with a mountain of salt.
Before learning how to program I kept hearing about the concept of eloquent code.The word eloquent by itself vague so understandably it will mean different things to different people. Most commonly, it can mean readability, maintainability, pretty (aka syntactic sugar), well commented, efficiency (code that executes a function the fastest), or having the least lines possible to run a program.
During my bootcamp the class had algorithms to solve and we would present our answers. This gave us a chance to see how each person thinks, represented by their code. When comparing my answers to others I noticed mine was simple and straightforward, maybe that’s because I’m simple minded. I have a tendency to minimize the amount of methods already available within the language, didn’t include regex (regular expressions), and didn’t get fancy with manipulating attributes, though I understand these are needed to complete certain tasks more efficiently (time to code and runtime).
My concept of eloquent code derives from understandability. It is as follows understandable->readable->well structured->maintainable.
- Understandable code is:
- Readable: A person should be able to look at the code and understand what is trying to be accomplished. Preferably, this is by reading the actual code instead of just the comments.
- Well Structured: To obtain readability overtime the code base must be well organized. This means a person can find what they are looking for within a code base.
- Maintainable: Because the code base is readable and well structured it is going to be more maintainable (updating/editing current code base).
Well, that wasn’t vague at all (/sarcasm). This is my general concept of eloquent code. What it means to be understandable and its derivatives will be up to each person and company to define. Just make sure to document so people don’t forget.
There are definite limitations to this concept. For instance, maintaining legacy code millions of lines long. This concept will only work when starting out or if the person/company have the ability to re-write the entire code base.
A friend once told me great code will look like only one person has written it, no matter how many people collaborated. There’s a lot of information in that one statement, and hopefully I unpacked it well in this post.