Sunday, January 29, 2012

10 Things I do to code better

After being into the software development career for more than a year now, I feel I understand what is expected from a "Software Developer". There are a lot of things that need to be done, and they need to be done with care. I see everyday that a lot of developers around me take software development as a job-to-be-done and not as a passion. Anyways, I'm here to talk about what I, as a software developer do to write better code everyday. Here's the list:
  
Keeping my code clean
Clean code could be described as code that is easily readable, and at the same time quite understandable. Stuff like proper indentation of code and the related comments can make your code look delicious.
 
Writing comments
Clean code and better comments make everyone's life simpler. Good comments are those which describe the 'WHW' (what, how and why) you do a particular thing in your code, in the simplest possible way. I call it "The expected WHW". Explaining this shouldn't be like writing an essay. Comments should be highly precise.
 
Writing Pre-conditions
Your code doesn't always stay with you. Everyone in your team should understand the pre-conditions and context when invoking a particular method that you might have written. The method which is being called should clearly describe it's pre-condition. Pre-conditions can be something like "The Person object should be initialized by calling the Person.Init() method" or something like that. Here, if the object 'Person' wasn't initialized, it may result in errors when other developers use methods that use the 'Person' object. This step helps other developers to use your code effectively.
 
Loose coupling
I always use this design principle to stay on the safer side with regards to scalability and maintainability. Loose coupling enables you to define boundaries within your code structure, and helps make easier the testing of the code and handling later changes in the code. This is one thing a developer's architect or designer might have a say in, but as far as I am concerned, I do have the liberty to suggest better coupling structures, however, they are happily trashed if we foresee any problem.
 
Knowing your programming language well
I'm always stuck in this conquest of mastering the programming language I use for coding. I keep switching from C++ to C# and vice versa but, I don't really understand which one to choose as they both have their own supernatural powers. I love C# for its simplicity and it's always a pleasure to work with it on Visual Studio. I came across a guy (who has always been working in C++) lately who was using C# .Net and was doing some kind of string processing. He had written around 10 lines of code for splitting strings (the C++ way, character by  character) based on a few characters but, never did he know that there is already a method called String.Split() that was readily available for use. It is difficult to know everything in the very huge .Net Framework, but the more you know the better your life becomes.
 
Learning Tips and Tricks
I always try and learn new tips and tricks to use my development IDE (Visual Studio) in the best possible manner. These tips and tricks help you to perform faster. Consider using keyboard shortcuts rather than moving your hand to the mouse and then searching for the respective button to be clicked in the IDE. This reduces the time in interaction with the IDE and would give you more time to think about your code. I learn tips and tricks in coding i.e. how something could be done in the best possible way.
 
Using Source and Version control software effectively
Source and version control software sound like an unnecessary nightmare to a low-on-experience software developer. I've had great times with Rational ClearCase. It's annoying ways help me learn more about it. Although a merge always screws up my code, I love the concept of source and version control because it enables me to code without the fear of losing my previously written code by mistake. I'm still in the process of taming this wild animal called "ClearCase".
 
Following coding guidelines
I always try my best not to be cursed by my fellow developers for not following the coding guidelines. Adherence to these guidelines helps developers to understand the "The expected WHW" of your code. This in turn helps you keep the code clean.
 
Reviewing my code
I always perform a self review of the written code before sending it for a review to the other team members. Reviews help you identify defects in the code at an early stage. Defects might miss out ones attention but, it might get caught by someone who would look at the code in a different manner or it may be easier for someone who has been working on the same thing for a long time to point out the possible defects in the code.
 
Knowing the context
Last, but never the least, it is a must to understand the entire context of usage of your code especially when you are adding particular functionality to existing code. There's always a chance that your changes could affect and break other's code. Always consult the original developers who had written the earlier code and get your code reviewed from them to avoid unexpected and vexing results.
 
This is a compilation of some things that I think help me in learning to code better. Opinions may vary, and if you’re still reading, I would like to hear your opinion on this. What do you think are other things that developers need to take care of?

No comments:

Post a Comment