Unobtrusive Programming - The Art of Clean Coding
Chigozie Orunta
Senior WordPress Engineer @ X-Team | Enterprise WP, Plugin Development.
Programming has been around for years and most of our software and mobile apps run huge lines of code needed to enable us do most of the things we enjoy doing such as chatting, blogging, sharing, liking and so much more.
One of the things I came across a while back as a young engineer was the concept of clean coding, which suggested a set of standards that enabled programmers effectively write & communicate code in a way that made it easier for other programmers to understand what the code was doing with or without the help of its author. For full measure, you might want to go through the book titled Clean Code by Robert Cecil Martin, it does a good job of explaining the basic tenets for good programming.
Simply put, if your code needs to be explained to other members of your team in your absence then its obtrusive and getting in the way of relevant team work and seamless delivery. Another definition to this would be, if your code doesn't quite scale well in terms of performance for a large data set, then its most likely going take a longer time to process and would require more CPU power and lead to system slow down and therefore by extension get in the way of other system functions or processes.
Good code should never be obtrusive, it should never hinder or hamper understanding of any kind. It should never bring an organization to its knees because some program or function needed more than is necessary to run effectively.
Here are some examples of what I mean:
Clear & Functional Naming
The following are two javascript functions designed to do the same thing:
function solution(A) { let total = 0; for(let i=0; i<A.length; i++) { total += A[i]; } return total/A.length; }
Second function (does exactly what the first function does)
function getAverage(integerArray) { let total = 0; let average = 0; for(let i=0; i<integerArray.length; i++) { total += integerArray[i]; } average = total/integerArray.length; return average; }
I'm sure I don't need to tell you which one looks clearly more readable and understandable at a glance. Even though this function is clearly very elementary, it shows how powerful the concept of appropriate naming conventions can be for variables, functions, arrays, classes, objects and so on.
In other words, programming constructs should be named according to their function within the program (very important) and not just ambiguous names like the case of the first function called "Solution". Obviously the first function (Solution) is getting in the way (its obtrusive).