Broken Window Theory

Broken Window Theory is an academic theory proposed by James Q. Wilson and George Kelling in 1982. It uses broken windows as a metaphor for describing disorder within neighbourhoods. This was mostly applied to crime to serve as inspiration to bring down crime in US cities. The broken windows theory of policing suggested that cleaning up the visible signs of disorder — like graffiti, loitering and street crimes — would prevent more serious crime as well. Prior to the development of this theory, the US police were mostly concentrating on big, serious crimes but after this theory became popular, the US police realised that in order to bring down, larger crimes, they had to take care of the smaller crimes first.

Even though this theory was applied to only crime, it can be applied in other areas as well including software development. One broken window (a bad piece of code) when left unrepaired (modified/refactored) for any amount of time, will slowly lead to more deterioration of code. Even one small piece of bad code instils in programmers a sense of “this code is already bad. I don’t have to bother about writing good code.” So the programmer writes even more bad code and slowly with time, every other programmer who works on the project writes more bad code and slowly at the end, all that is left is a bad project which is completely ignored by everyone. It is thus very important for programmers to practise writing good code from a very early stage of their career. We should fix every bad code as soon as it is discovered because even though it might take some time today to fix this bad code but in the long run, it saves a lot of time and even increases the life of the program. If we don’t have any time to fix it, we should probably comment the part of code that needs attention so that other people in the team know that we are on top of the situation and will fix it as soon as possible (even though comments are bad).

Fix one bad window today to prevent the entire neighbourhood from becoming a ghost town tomorrow.