24 Jul 2013

Avoid complexity, simplify your code.

Over the years i have written a bunch of codes that function inside other applications or independently and in all my doings, i keep one thing in mind, simplicity.

There are a lot of people who write complex codes and think by doing so, it makes them look very good, and the fact that others can't read their code makes them superior. Is that true? well i can tell you for sure that a lot of those programmers cannot come to manage, fix or even read the code they wrote 2 years ago. Einstein once said "If you can't explain it to six year old, you don't understand it yourself", this brings us down to a serious series of questions!
      1. Do i really know what i am writing?
      2. Can i explain it to a kid and he will understand what i am saying?
      3. Do i know what every line in my code does?

Well if you can answer does questions and they turn out to be positive, then you really know your shit.
Talking about simplicity, are the use of third party softwares/libraries good or bad? this is a very difficult question and has multiple response depending on the scenario.
One, if you need a function from a library to integrate into your source code and that function happens to be one out of say two or three functions, definitely it is a good idea to just use that library instead of trying to reinvent the wheel. But what if a library contains hundreds of features and you happen to need only one feature, is it wise to integrate this whole system into your software and cause complexity and inefficiency because of one single feature? why not just write the feature from scratch and make the job a whole lot easier for future managers of your work, who knows it might be you, and at that point, the failure of one single feature in your system which is likely not what you use will cause you time, energy and productivity.

Another point to this is modular development, i am a fan of modular development and currently writing my thesis on it. What is the idea? simple, break your project into independent pieces that communicate with each other and function as a whole system i.e. each module performs a particular function. Why is this important? well lets take for instance, you have a system that monitors the weather and logs the information to the database and also to an online cloud storage. Now, the easiest modular way to do this, is to break it into modules, one module gathering information, another module logging in a database and another uploading to the cloud. So at this point you have three modules communicating together, if one module fails, lets say the one responsible for uploading online, your system is not a total failure, still it can gather info and store in the database, and all you have to do is to fix the module responsible for upload to the cloud.

Lastly, the idea of Object Oriented development is great, but a lot of developers tend to abuse this paradigm in the sense that, this days you will find an application with a lot of classes which could have been easily written into two small functions. Even though the idea of reuse is good, but if it is not necessary, do not write dormant classes in the hope that there will be need for it in the future, you can simply write it when you need it and avoid the whole complexity.

Well i hope developers will start simplifying their systems and make the job of managing, extension and debugging much more easier to those who will likely work on their codes in the future.