Code reviews are an essential part of the development process. They help us improve the quality of our code and catch mistakes that we may have missed somehow, even from just having looked at the code for so long.
Personalities and in particular, ego, can be a hindrance to getting the most out of a code review. It's natural for programmers to become attached to their code. To a certain extent, some attachment to your work is fine. In fact, it's necessary. The pride we have in our work is a big part of how we make it better. However, we can't let our pride get in the way of making improvements. When we get attached to the code we write, we can become very protective of it. This can cause us to overlook some of the code's flaws, much like a mother whose baby only she can love. It can also make us very defensive and closed-minded, taking any criticism of flaws as personal attacks and insults, even when that was not the intent behind the critical comment.
Since I love babies in general, I'd like to stay away from that analogy. I'd rather use "much like a pig farmer, whose pigs only he or she can love" instead. This also leads to one of my favorite things to say to programmers about code smells: "Don't be like a pig farmer who loves his/her pigs no matter how much they stink."
I have practiced egoless programming for a while now and I think this has helped me tremendously in getting over my attachment to code that I write. I can be critical of my code's flaws without any qualms but more importantly, I am able to freely accept reasonable criticism of my code's flaws. I accept the fact that I can make mistakes, that I can come up with dumb designs and less-than-stellar implementations. Much like how warriors can go bravely into battle after having accepted that they are already dead, this kind of mindset frees me to refactor my code ruthlessly and relentlessly. I don't care that others might think I'm dumb; I know I'm not. I just care that the code gets better. The code is not me and its flaws don't define me or my competence as a programmer.
As such, I'd like to propose a standard working agreement between everyone who participates in this Code Review forum. I would like for anyone who wishes to participate to agree to be guided by the precepts of Egoless Programming in pursuit of the ideals of Software Craftsmanship. If the latter is a bit much for you, then at least the former.
Can we all agree to this?
If you would, please respond to the following poll:
I think one tricky part to the egoless programming thing, if you read through Jeff Atwood's list of 10 commandments for it, he writes in commandment #10: "... As much as possible, make all of your comments positive and oriented to improving the code."
Now, the "oriented to improving the code" I can certainly do. However, it's tough to spin a code smell in a positive way. The only thought I have around this is to start comments with something positive about the code before going into details of the smell. Oh well, he does say "As much as possible" so I guess that's my escape clause for talking about code smells.
Junilu Lacar wrote:. . . positive and oriented to improving the code." . . .
“It would be a lot better if you refactored the arrowhead code in lines 7465834‑8745786.”
I know you probably meant that with tongue firmly planted in cheek but it does set a good example. I'm the one who always talks about the sensei who tells students "Yes, that's good! That's good! But this is how you can do it better" even when they are struggling with a technique. I should remember my own stories.
I would still struggle with saying "That's good, that's good!" even when it isn't but I can still say "I think we can improve this code/design by addressing the (optional code smell name) issue I'm sensing from it." It's not really positive but then again, it doesn't start with something that people may find a bit jarring like, "That code smells. We should probably refactor that." It takes a certain level of trust and familiarity with each other to be able to be as upfront and direct as that.
The Ten Commandments of Egoless Programming will not only be beneficial to programmers but also to the people who work in other fields which are not related to software programming. It has really great advices essential in human life.