I just saw a Post on the Facebook which one of my ex-colleagues shared which got me little pensive and thought of sharing my thoughts on this Blog.
So, Writing Good Code has anything to do with the problem its intending to solve? Does it have any impact on the Requirement changes? Do we know of any defined rules? Do we know a way to measure it?
Or it is more than all these?
Ok, so what is this “Good Code” all about?
Let’s assume we are writing code to calculate Average of “n” numbers.
Now, that being the Problem statement, how would we go about writing code?
One might say, "..are you kidding me? It’s the simplest Code to write, just write the legendary “main” function, accept command line parameters, and calculate the Average and Display the result. As simple as that, get Real man!!!! ".
OK…, let’s see.
Oops! Wait a second, who told us to create a Console Application? That is not what the Requirement says. Who told us to accept command line parameters? Who told to display the result on the Console?
The requirement is to calculate the Average of n numbers. There is no mention of where to get the input from, what is the constraint on the number of “Numbers” that should be handled, where to get the Formula from, and where and how to “show” the Result.
Fine, so what do we write now? Let’s park this here and turn tables.
Let’s talk a little about who is trying to write Code, THE HOLY DEVELOPER!! – Whom I always Love and Respect.
So, does it all depend on the Developer who is writing the code? What information the Developer has? Does it depend on the time given to him to complete the Task? Does it depend on the degree of grip, the Developer has on the relatively “cutting-edge” Concepts [Big Data, Cloud scenarios, Social Concepts etc.]?
Hmm…seems like all of them play a very vital role in influencing the Developer to write “Good” Code. So the word “Good” here is actually associated with the above mentioned factors (timelines, Cutting-edge concepts, various experiences the Developer has had in the Past, the Patterns of scenarios etc.).
Is that all?
Well, we all know that the Developer has no control over the Timelines given to complete a given Task. But how about the rest? What controls the remaining factors?
So the Developer has to know the Patterns of scenarios that fall into this bucket, needs to be aware of Cutting-edge concepts, needs to interact with “Community” to learn experiences and this list goes on.
Sounds too difficult. But if one likes what one does then it is not burden, it is happiness. Is there any word that describes this whole concept of learning eternally and still be happy?
Hmm…let me try a few words:
These are not satisfying me, how about, “PASSION”.
Yes, sounds great, so if one has this inner zeal or Passion or Love to learn things, it is no more Baggage to carry and it does not matter how long one does, because, its happiness, you love it, it’s Passion.
Cool!! So, this seems to be most important factor that drives and controls the Developer to get in touch with the “Community” and learn new things and amass the needed ammunition to churn out Code. Sorry, Good Code.
So can we safely say that “Passion or Love” creates the right Attitude that in turn influences the Developer to create what is called the “Good code”?
So the Developer with Passion (Love) will always Create Good Code?
Hmm…may not be, it’s like the Soldier has the right Ammunition, will the Soldier win his Task yet? May be one needs little icing on the cake, may be some Presence of Mind? Some Strategy? Use the right ammunition in the right logical scenario and proceed towards the finish line. What controls all this? My take on this is, unless, one is Calm and focused or unless one is at Peace, one’s mind will not open up multiple avenues to handle a given situation. So if I map this to our “Business”, writing the right Logic forms part of “Good Code” too. So one needs to think peacefully to strategize around the Problem.
Ok, sounds like we drilled too deeper now, let me sum it up and put it all at one place.
So a Developer who is:
Will most likely be able to produce what is called “Good Code”!!!
And seems like this has nothing to do with “What” the Problem is. It is mostly to do with what is called the “Attitude” of the person writing the Code.
So, next time you write you write CODE, beware that your Attitude actually reflects in Your Code!
This does not end here there is a lot to talk but, shoot, time's running out, got to catch up with some really serious Project Work and see you next time and till then,
PEACE, LOVE and GOOD CODE !!
Very thoughtful and perfect elaboration of your punch line! Good GOING Kris!
How about motivation? How about having the right tools, clear upfront requirements and adequate time for coding?
The context is sometimes very important in development projects, and can affect the way we write code.
There are intrinsic factors (attitude of the programmer toward coding, state of mind) and extrinsic factors (resources and constraints related to the context) that affect good coding.
Thank you Adrian for reading the Blog and putting Comments. While all your points are pretty much valid, my intention of this Blog is more like a Prologue for any Developer to swing into action. Motivation and Right tools are more part of Passion and reaching out to the "Community" (the Internet or other Blogs). This Post handling the needed basic mind-set for a Good Developer, hence the Context of the Problem, its technical constraints come later in the game. Trying to Write Good code is more like having the right Attitude first and I was just trying to bring that point out. Thank you again for your Comments !! Appreciate it.
That's a cool secret behind how we end up writing
Good code, Most people are logical enough with brains but
Not having the right attitude which you mentioned is the real
Killer which delays projects and even cause failures.
Thanks for sharing your experience really helps every developer.
Your tag line has great intent and will help many.
Very good article Kris. Loved the Tagline "PEACE, LOVE and GOOD CODE !!".