11 Rules All Programmers Should Live By
i am a person who tends to live by rules. now granted, they are mostly rules i set for myself—but they are still rules. i find that creating rules for myself helps me to function better, because i pre-decide things ahead of time instead of making all kinds of decisions on the fly. should i go to the gym this morning? well, my rule says that on wednesdays i go to the gym and today is wednesday, so i am going to the gym—that settles it. this week, as i was thinking about some of the kinds of rules i impose on myself, i thought it might be a good idea to come up with a set of rules that i think all software developers should live by. now, i’ll admit, most of these rules are more of guidelines, but anyway, here they are: 1: technology is how you get to the solution, it is not the solution we can get really carried away with the latest javascript framework—ahem, angular—ioc container, programming language or even operating system, but all of these things are not actually solutions to the problems we are trying to solve as programmers, instead they are simply tools that help us solve the problems. we have to be very careful not to get too crazy about a particular technology that we happen to like or that happens to be oh so popular right now, lest we run the risk of thinking about every problem as a nail, just because we happen to be holding a shiny hammer we just learned about. 2: clever is the enemy of clear when writing code, we should strive to write code that is clear and easy to understand. code that clearly communicates its purpose is much more valuable than code that is obscure—no matter how clever it may be. it’s not always true, but in general, clever is the enemy of clear. it’s usually true that when we write code that is “clever,” that code isn’t particularly clear. it’s important to remember this rule whenever we think we are doing something particularly clever. sometimes we write clever code that is also clear, but usually that is not the case. if you’re interested in writing clean code i highly recommend you check out the clean coder: a code of conduct for professional programmers (robert c. martin) 3: only write code if you absolutely have to this one might seem a little contradictory, after all, isn’t our job as programmers to write code? well, yes and no. our jobs may involve writing code, but we should still strive to write as little of it as possible to solve the problem we are trying to solve. this doesn’t mean we should make our code as compact as possible and name all our variables using single letters of the alphabet. what it does mean is that we should try to only write code that is actually necessary to implement the functionality that is required. often it is tempting to add all kinds of cool features to our code or to make our code “robust” and “flexible” so that it can handle all different kinds of situations. but, more often than not, when we try to guess about what features would be useful or we try to pave the road to solve for problems that we think might exist in the future, we are wrong. this extra code may not add any value, but it can still do a lot of harm. the more code there is, the more chances for bugs and the more code that has to be maintained over time. good software engineers don’t write code unless it’s absolutely necessary. great software engineers delete as much code as possible. 4: comments are mostly evil i’m not a big fan of writing comments in code. i’m with bob martin, when he says: “every time you write a comment, you should grimace and feel the failure of your ability of expression.” — clean code: a handbook of agile software craftmanship this doesn’t mean that you should never write comments, but for the most part they can be avoided and instead you can focus on doing a better job of naming things. comments should only really be written when it’s not possible to clearly communicate the intent of a variable or method by using a name. the comment then serves an actual purpose that could not be easily expressed in the code. for example, a comment could tell you that this strange order in which some operation was occurring in the code was not a mistake, but was intentional because of a bug in the underlying operating system. in general though, comments are not only evil because in many cases they are necessary, but also because they lie. comments don’t tend to get updated with the rest of the code and this results in the comments actually becoming dangerous, because they very well could steer you in a completely wrong direction. do you check every single comment against the code to make sure the code is actually doing what the comment says? if so, what is the point of having the comment? if not, how can you trust that the comment is telling you the truth? it’s a pickle, so it’s best to avoid it as much as possible. ok, haters, go ahead and leave your torrent of “comments” in the comment section below, but i’m not changing my stance on this one. 5: always know what your code is supposed to do before you start writing it it seems obvious, but it isn’t. how many times have you sat down to write code without fully understanding what the code you were writing was actually supposed to do? i’ve done it more times than i’d like to admit, so this is a rule that i need to read often. practicing test driven development (tdd) can help here, because you literally have to know what the code is going to do before you write it, but it still doesn’t stop you from creating the wrong thing, so it’s still important to make sure you absolutely, 100% understand the requirements of the feature or functionality you are building before you build it. 6: test your sh—code before you ship it don’t just toss your code over the wall and have qa pound on it only to send it back to you so that you can waste a bunch of everyone’s time with unnecessary bug reports and resolutions. instead, take a few minutes to run through the test scenarios yourself, before you call your code done. sure, you won’t catch every bug before you pass your work on to qa, but you’ll at least catch some of the stupid and embarrassing mistakes that we all make from time-to-time. too many software developers think that it is only qa’s job to test their stuff. it’s simply not true. quality is everyone’s responsibility. 7: learn something new every day if you didn’t learn something new today, you just made backwards progress, because i can guarantee you forgot something. it doesn’t take a lot of time to learn something new each and every day. try spending just 15 minutes or so reading a book— i read a whole lot of books last year, just reading about 45 minutes each day on average. the little advances you make each and every day add up over time and will greatly shape your future. but, you have to start investing now if you want to reap the rewards later. besides, today technology is changing so rapidly that if you aren’t continually improving your skills and learning new ones, you are going to be left behind very quickly. 8: writing code is fun that’s right. you probably didn’t get into this profession just because it pays well. i mean, there is nothing wrong with picking a job that pays well, but doctor or lawyer would have probably been a better choice. most likely you became a software developer, because you love writing code . so, don’t forget that you are doing what you love. writing code is a lot of fun. i wish i could write more code. i’m usually too busy keeping this business going to spend much time writing code these days, which is one of the reasons why i so clearly remember how much fun it is. perhaps you forgot that writing code is fun. perhaps it’s time to remember how much fun it is again, by starting a side project or just changing your mindset and realizing that you get to write code and you are even paid for it. (hopefully) 9: you can’t know it all as much as you learn, there is still going to be a lot you don’t know. it’s important to realize this because you can drive yourself nuts trying to know everything. it’s ok to not have all the answers. it’s ok to ask for help or to speak up when you don’t understand something. in many cases, you can learn what you need to know pretty darn close to when you need to know it—believe me, i do it all the time. my point is, don’t get caught up in trying to learn it all, when that is an impossible task. instead, focus on learning what you need to know and building the skills that enable you to learn things quickly . 10: best practices are context dependent is test-driven development, the best way to write code? should we always pair program? are you a scrub if you don’t use ioc containers? the answer to all of these questions is “it depends.” it depends on the context. people will try to shove best practices down your throat and they’ll try to tell you that they always apply—that you should always do this or that—but, it’s simply not true. i follow a lot of best practices when i am writing code, but i also conditionally don’t follow them as well. principles are timeless, best practices will always be situational . 11: always strive to simplify all problems can be broken down. the most elegant solutions are often the most simple ones. but, simplicity doesn’t come easy. it takes work to make things simple. the purpose of this blog is to take some of the complexities of software development, and life in general, and make them simple. believe me, this isn’t an easy task. any fool can create a complex solution to a problem. it takes extra effort and care to refine a solution to make it simple, but still correct. take the time. put forth the effort. strive for simplicity. what rules do you live by? so, those are my rules, but what about yours? what rules do you personally live by? what do you think is important to remember every day? leave a comment below, and also, take a second to join over 10,000 other software developers who are part of the simple programmer community. just click here and you can join for free —you’ll get some of my best content and other free goodies every week.
March 18, 2015
·
16,776 Views
·
3 Likes
Comments
Feb 23, 2016 · Deepak Karanth
Extremely honored to have my book mentioned here and humbled to see it in a list of such great books. Thank you.
Sep 26, 2013 · Tony Thomas
Fantastic. Simple, but so correct.
Sep 26, 2013 · Tony Thomas
Fantastic. Simple, but so correct.
Sep 25, 2013 · Tony Thomas
I actually try to push-through-the-pain in order to get over a typical burnout type of situation.
I know this seems a little counter intuitive, but I've found that motivation waxes and wanes and that sometimes you are just not going to feel motivated no matter what you do.
In those cases I fall back to deciding that I want my mind and not my emotions to decide how I live my life, so I force myself to push through and complete the task I set out to do.
Sometimes this is quite painful, but I often find that when I feel like I can't go on, but manage to do it anyway, I find that on the other side of the wall of struggle there was a refreshing pool of new motivation and purpose.
Early in life I would set out to do things and get 90% done with them, because I would eventually get tired of those things and decide to chase something new. I found that this method of chasing dreams never got me anywhere and that I was putting forth much wasted effort.
In the past 5 or so years, I've adopted a completely different viewpoint where starting what I finish is the highest priority and I've seen much greater successes.
Sep 03, 2013 · Mr B Loid
Great question. I think the best side-project is one that has the potential of generating some income, because then you are improving your skills and building an asset for yourself.
I usually recommend creating an Android application or other mobile application since it is a good intersection of being a small project, possibly profitable, and in high demands skills.
Sep 03, 2013 · Mr B Loid
Great question. I think the best side-project is one that has the potential of generating some income, because then you are improving your skills and building an asset for yourself.
I usually recommend creating an Android application or other mobile application since it is a good intersection of being a small project, possibly profitable, and in high demands skills.
Apr 25, 2013 · Alvin Ashcraft
Awesome! That is a fantastic example. You have identified the problem I am trying to point out in my post.
Apr 25, 2013 · Alvin Ashcraft
Awesome! That is a fantastic example. You have identified the problem I am trying to point out in my post.
Apr 24, 2013 · Alvin Ashcraft
Yes, I agree. That is definitely one good solution.
Apr 24, 2013 · Alvin Ashcraft
Yes, I agree. That is definitely one good solution.
Apr 24, 2013 · Alvin Ashcraft
Yes, I agree. That is definitely one good solution.
Apr 16, 2013 · Stefan Koopmanschap
This is a common misconception about polymorphism.
Overriding is a form of polymorphism, as is generic programming.
You are talking only about subtype polymorphism.
Here is a wikipedia article that explains some of this: http://en.wikipedia.org/wiki/Polymorphism_(computer_science)
Thanks for bringing this up though, it is certainly a point of confusion.
Apr 16, 2013 · Stefan Koopmanschap
This is a common misconception about polymorphism.
Overriding is a form of polymorphism, as is generic programming.
You are talking only about subtype polymorphism.
Here is a wikipedia article that explains some of this: http://en.wikipedia.org/wiki/Polymorphism_(computer_science)
Thanks for bringing this up though, it is certainly a point of confusion.
Apr 16, 2013 · Stefan Koopmanschap
This is a common misconception about polymorphism.
Overriding is a form of polymorphism, as is generic programming.
You are talking only about subtype polymorphism.
Here is a wikipedia article that explains some of this: http://en.wikipedia.org/wiki/Polymorphism_(computer_science)
Thanks for bringing this up though, it is certainly a point of confusion.
Mar 12, 2013 · Mr B Loid
I see your point, but I would much rather optimize for success than mitigating failure.
Mar 12, 2013 · Mr B Loid
I see your point, but I would much rather optimize for success than mitigating failure.