Perfect score

Perfectionism in Programming

Updated: 2 June 2021 16:04 - 7 min read

First of all I would like to welcome you to my blog where I will be sharing my experiences in the software engineering world. Hopefully you will learn something new every time you read one of my blogs :).

A perfectionist is a person who refuses to accept any standard short of perfection. I consider myself a perfectionist and a competitive person. In this blog I will discuss my coding experience from a perfectionistic person’s view, the upsides and downsides of having a perfectionistic mindset and some tips for avoiding getting trapped in trying to reach this unattainable ideal.

I want to be the best at anything I decide to put effort in. I don’t settle for anything less than perfect or being the best. It can be requiring myself to be the best at my sport table tennis or winning a simple game of Monopoly. Sometimes winning a point is not even enough. I could have won the point earlier or maybe I was just lucky the opponent made a mistake. I tend to have a similar mindset for most things in life including programming. And let’s not forget about this blogpost. Needs to be great as well. I always try to get things right the first time. Needless to say, this blog has been a long time in the making.

For starters, being so demanding of yourself will make you have to deal with disappointments quite a lot. Especially in sports. Only one person can be the best. If I am not winning, I am losing. Being second or last is in that regard the exact same thing. It’s not first place.

public class Calculator {

    private int x;
    private int y;

    // Method for adding two numbers
    public int add(int a , int b) {
        return a + b;

    }

    // method for subtracting two numbers
    public int  subtract(int a, int b){
        return a - b;    
    }

    public int Multiply() {
        return this’s + y;
    }

}

I would see many imperfections in this code and would feel the urge to ‘fix’ all the code’s imperfections. I get the same urges when I encounter this code during my daily work. Inconsistent spaces, braces, new lines and capitalization, would be examples of the things I would fix. When I look at a piece of code or when I’m coding, I almost look at it as a painting. I would shuffle around code to make it symmetrical, balanced and simplistic, ensuring the code looks its best. The code should paint the perfect picture for when other people eventually read it. In my opinion the following code would look more elegant and readable:

public class Calculator {

    private int x;
    private int y;

    // Method for adding two numbers
    public int add(int a, int b) {
        return a + b;
    }

    // Method for subtracting two numbers
    public int subtract(int a, int b){
        return a - b;    
    }

    public int multiply() {
        return this.x * this.y;
    }
}

This is of course a small and isolated example since the code does the same thing and performs no different. Other people can also have a different perspective on how ‘perfect’ code looks like. Maybe some people didn’t even see a difference in the two pieces of code. This can be frustrating when you work in a project with many different programmers that all have their own coding style. Perfectionists could feel other programmers were lazy and didn’t do a good enough job. This obviously does not have to be the case.

It becomes most evident when reviewing PRs. I often feel that the naming of variables and methods and the layout of the code could be improved. Naming is of course very personal and is very much up to debate. However, I feel that code can be improved significantly by making the code look more ‘elegant’, which will make the code more readable. Readability is important because code is more often read than written. Adding whitespaces and blank lines to separate logical blocks of code will in my opinion improve the code and will make it easier to understand for the reviewer and the programmers that will inevitably read the code later.

Advantages

Being a perfectionist comes as mentioned with both its advantages and disadvantages. Advantages include not being easily satisfied with a solution, high level of ambition, increased motivation, perseverance, attention to detail and striving to be the best version of yourself.

Perfectionists often will be quite ambitious in life. They will set goals for themselves and do everything they can to reach those goals. Often sacrificing other things to make sure they will not fail. They do this to get an edge over the competition who are not willing to work as hard. An example of this could be spending a couple of hours outside work hours to apply the finishing touches to a solution.

Setbacks are also not likely to impact perfectionists. They will still put in the effort and persevere through difficulties they encounter

Attention to details is something perfectionists pride themselves in. Finding little mistakes is a strength and raises the quality of work of their teammates as well as their own. This translates to programming in writing high-quality code. Not just writing code that works, but code that is maintainable and follows best practices.

Disadvantages

All these advantages come at a cost. One of the -obvious- disadvantages is that developing solutions takes more time. By continuously perfecting the solution, the solution will never be done. There is always be something to improve. There comes a point where the programmer should move on to the next feature. This point will come later in time for a perfectionist

Another disadvantage is that perfectionism can also have a quite severe effect on your mood or state of mind. Since you never have the feeling that a task or solution is done, you will not often have the satisfactory feeling of completion. You will be worrying about small mistakes and put yourself under unnecessary pressure.

Tips

To manage having a perfectionistic mindset and feel the urge to refactor ten different services, I like to consider the following:

  • Will these changes make any significant difference in the performance of the code? Is it worth my time? This can be a question for the long-term or the short-term. If there isn’t a clear answer, I set a deadline for myself and if I feel I won’t make this deadline anymore, I will move on.
  • I often like to ask a coworker/teammate what he or she thinks of the current solution and whether it needs to be improved or is sufficient as is. Pair programming is often a good way to lessen the perfectionistic effects, due to the instantaneous feedback on the written code.
  • Try to be satisfied with a good working solution instead of a perfect solution. Which is always easier said than done 😊.

In the end I would say you are a good programmer if you are able to choose the right moments to be perfectionistic. You can call them selective perfectionists. They have a good understanding in which code needs to be absolutely spot-on and which code isn’t that important.

Over time I learned being a perfectionist doesn’t mean it has to be perfect. You can still strive to be perfect, but if circumstances do not allow it to be perfect, it does not mean it is not a good solution.

In my next blog I will be talking about how to handle poison pills in Apache Kafka. Until then.