I often review code; not just within my team, but as a part of cross-team initiative as well. The exercise is both refreshing and exhausting. At times I find a totally new and innovative approach to solve the problem at hand, but that isn’t always the case. Most of the time the code is plain and simple and often lacks basic sanity.
Developers often miss the point of writing clean code and the importance of it. The code is written in a manner as if no one will read the code ever again, as if it is written to be obsolete in a moment. I have seen some very large method definitions, one line methods that just make a call to a utility class and return, overloaded methods with the entire content duplicated and much more to be expressed here.
Writing code and writing clean code are two very different things. It is one thing to write it for the compiler to understand and totally different for a human to understand it.
While it is important that the code works correctly, it is also important that it is readable because if it is not then it is asking for trouble. A working code isn’t always the most readable and easily understandable. On an average it takes more time to read and understand someone else’s code that to write it on your own.
We must ensure that our code is written in a manner that at least we can understand it without difficulty, when we read or work on it again.
Code that is not clean is not efficient, while it might look so at first. There are many small but significant changes that can be introduced to ensure clean and readable code. Some of them are listed below.
1. Method name should describe its intent
2. Methods should always perform a single task
3. No more lengthy methods, with many things crushed into one
4. Use expressive variable names
5. Pass object(s) as argument(s), if possible
6. Write comments to express complex logic
7. Use interfaces to avoid coupling
These are just a few ways to write clean and efficient code, there is much more to learn in this context and introduce to the code as a general practice. Considering that we start with a few of these and make it a habit we can transform our code to a great extent in no time.
Full Article: Lalit Mehra @ CodeX
Mobile App Development Best Practices – 03.10
iOS MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming How to build a Tuist plugin and publish it using...
How to make and use BOM (Bill of Materials) dependencies in Android projects
By using a BOM dependency, you can avoid specifying the versions of each individual library in your app, and let...
Telegram turns 10 years old and revenues stagnate
Telegram seems to want to grow not only through messaging but also through communities, which pretty much means it wants...
MetaCodable – Supercharge Swift’s Codable implementations with macros meta-programming
Supercharge Swift‘s Codable implementations with macros. Overview MetaCodable framework exposes custom macros which can be used to generate dynamic Codable implementations. The core of the framework...
How to get started with Swift Concurrency 🧵 (Beginner Tutorial)
Swift has built-in support for writing asynchronous and parallel code in a structured way. Asynchronous code can be suspended and resumed later,...
Mobile App Development Best Practices – 02.10
Data.ai has summarized the interim results of the year – and once again we have a record. Annual consumer spending...