If someone ask me who is my Guru for Java, I would say 'Sun Microsystem' and 'Apache Foundation'.
I am from a generation, where most of the programming learning was by reading Java source code. Internet was not a big store of many rich blogs or forums, and hence reading through code was the best resource. Moreover, kind of components we built, were not possible without understanding the behavior of system we are extending. Hence reading through code was almost mandatory for building right extension, and the products.
One notable thing, I still remember and admire about Java and Apache kind of products source code is, clarity of code constructs and rich documentation, code which speaks its intention very clearly. That made the code reading experience enjoyable and easy like a story book. I remember reading tons of code of Swing, Concurrent library, Collections and Apache Axis etc like a novel. Much of the credit of reading such large codebase was to that effective coding and documentation style, which developers followed to write such code.
Fast forward today, we are in era where doing more by writing lesser code is sought after style. With availability of functional language, many abstract language constructs and lambada expression kind of support, it makes all the sense and makes code less bulky too.
Yesterday or today, then or now, basic principles of writing clean code are same and equally required. Ultimately it is all about art of writing readable code, clean code, a code which speaks of its intention clearly, where it is hard for bugs to hide, a code which can tell about any dysfunction loudly.
What is clean code:
Any fool can write code that a computer can understand. Good programmers write code that humans can understand - Martin Fowler
- A code which can be read easily by anyone and everyone other than its original author.
- A code which speaks of its intention clearly, either with write naming convention or with documentation as relevant
- A code where it is hard for bugs to hide
- A code which can tell about any dysfunction in system loudly itself
- Let us talk in brief about some of key enabler principles for clean code.
Meaningful Names - Names which reveals intention
If I need to choose one most important thing for clean code, I will pick this. That is its importance for code readability and maintainability.
Picking right name, which can reveal its intention of existence is very important. It takes time to pick right name, however, that effort and time are worth it as it could save hours of efforts later to understand the code or any issue.