“Simplicity is the ultimate sophistication.”Leonardo da Vinci
Hi all, I really should start blogging again. It truly has been a while. Apologies for that. I will try to blog more regularly from now.
In my current return to blogging, I will discuss on what non-techy people (PM, BAs, Marketing, etc) should know about ‘Simple’ coding.
Why should you know this? Because simplicity is one of the goal that we all are trying to achieve in our job. I believe most organisations have this conversations with their team every now and then, on how can they make this simpler.
Unfortunately however, I believe the discussions often only look into how to make the processes simpler. It often neglects to simplify the code that is used to generate data, or calculation or information.
So here it is, a very simple way to simplify coding.
How to identify complexity in codes?
First of all, let me define complexity. Complexity in coding is when there is too much unnecessary code. Or in another word, if with less code, it can achieve the same result, then that code is overly complex.
Think about a document or report. Think of its purpose. If it is unnecessary long, then that is a overly complex document, right? It’s the same way for code, if it can be written less to achieve the same purpose, then it must be too complex.
One way to detect this is by looking at the number of lines (minus the comments). If it can be reduced by a thousand lines or more, there must be an area to improve.
Another way to see complexity in coding is when there is unnecessary nested ifs or nested loops.
Loop and if are fundamental blocks of any programming languages. They are the first things we learn in any programming courses. ‘Nested’ is when there is if/loop conditions inside another if/loop, and so on. The more it is nested the more difficult and complex it is to understand.
At university, we are often forced to learn how to use and implement nested ifs and loops, which is very advance and very complex method. However, in life, this are not necessary in most cases.
Think about a Word document again. A document can have multiple sub-heading, right? If a document has sub-headings of too many levels, then it is a complex document, right? The same way with coding, if it has nested loop or nested if, it is difficult to understand, and that is complex. The question to ask is then, is that really necessary? Can it be done simpler?
The third way is about using functions and repeatable code. Functions is when you have repeatable code or similar code. You then put them into a function, so that you use less code, less lines, less complexity. Imagine when your database have 100 similar tables and you need to append them together. Writing 100 SQL statements and union in between is unnecessarily complex. Instead writing one SQL statement and a function that append them together is much simpler.
The last thing is about structure. Again, let’s compare to a Word document. Every section should have a sub-heading and a clear purpose of what it is written about, right? It is poorly written if Introduction is written in the middle of the document, for example. Or if some analysis is written at the conclusion, then that is poorly written, right?
In coding, the structure should be that each section aims to do just one or maybe two things. It should have a comment block explaining what it is trying to achieve, and that’s it.
Why does this matter?
So you might ask? Why does this matter? Should we care if it does what it supposed to do anyway?
It’s because a complex code is difficult to peer-review. Difficult and take longer time to audit. It also more difficult to handover should someone resigned.
I hope this helps, my two cents on coding simplicity. Contact me if you need help in designing controls around your coding team.
If you think this blog is helpful, a small donation goes a long way.
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.DonateDonate monthlyDonate yearly