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.
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.
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
“Every time you write a comment, you should grimace and feel the failure of your ability of expression.”
This doesn’t mean that you should never write comments, but for the most part they can be avoided and instead we 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 us 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 we 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 we trust that the comment is telling us the truth?
It’s a pickle, so it’s best to avoid it as much as possible.
5: Always know what our code is supposed to do before we start writing it
It seems obvious, but it isn’t.
How many times have we sat down to write code without fully understanding what the code we 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 we literally have to know what the code is going to do before we write it, but it still doesn’t stop us from creating the wrong thing, so it’s still important to make sure we absolutely, 100% understand the requirements of the feature or functionality we are building before we build it.
6: Test our sh—code before we ship it
Don’t just toss our code over the wall and have QA pound on it only to send it back to us so that we 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 ourself, before we call our code done.
Sure, we won’t catch every bug before we pass our work on to QA, but we’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.
w
7: Learn something new every day
If we didn’t learn something new today, we 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.
The little advances we make each and every day add up over time and will greatly shape our future. But, we have to start investing now if we want to reap the rewards later.
Besides, today technology is changing so rapidly that if we aren’t continually improving our skills and learning new ones, we are going to be left behind very quickly.
8: Writing code is fun
That’s right. We 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 we became a software developer, because we love wirting code. So, we don’t forget that we are doing what we love.
9: We can’t know it all
As much as you learn, there is still going to be a lot you don’t know.
It’s OK to not have all the answers.
It’s OK to ask for help or to speak up when we don’t understand something.
In many cases, we can learn what we need to know pretty darn close to when you need to know it—believe me, I do it all the time.
10: Best practices are context dependent
Is test-driven development, the best way to write code?
Should we always pair program?
Are we a scrub if we 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 our throat and they’ll try to tell us that they always apply—that we 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.
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.