Of broken windows and IDEs

Few weeks ago, my latest padawan and me were having our weekly mentoring/1:1 meeting at work. I had asked him to do some "homework" and he said one thing that has made me think a lot about. He told me that we have some old files at work that do not conform to the coding standards, questioning why then we didn't fixed them, if was mostly a matter of some scripts/replacements, and we could avoid the "broken windows" theory.

A small lesson first. The Broken windows theory states:

Consider a building with a few broken windows. If the windows are not repaired, the tendency is for vandals to break a few more windows. Eventually, they may even break into the building, and if it's unoccupied, perhaps become squatters or light fires inside. Or consider a sidewalk. Some litter accumulates. Soon, more litter accumulates. Eventually, people even start leaving bags of trash from take-out restaurants there or even break into cars.

Now think about an untyped, case insensitive and scripted (not compiled) programming language.

Nothing prevents you from having case typos, the code will still execute correctly, or you can mix tab and space based indentations... But the real problem comes due to the scripted nature. If you have dead methods, not being call from anywhere, most scripted languages will only complain about the basic syntax errors (like "php -l"). Calling a PHP method with more parameters than it accepts? No problem, just will ignore the redundant ones! A typo in a catch (xxxException)? Don't worry, will only break if the flow reaches that lines of code! Unused variables here? Bah, let the GC clean them! Unassigned variable being used? No problem, sir, I'll create it at once!

See where I'm going?

The broken windows effect can spread like a plage with scripted languages if you don't take care, because at least PHP tends to hide all but the most dangeours errors from the developers. And here is when we come to the second part of the post, the cure for this illness.

Do yourself and your colleages a favor. Install a proper IDE for coding, or spend enough effort so that your editor works as efficiently as one.

You can feel you are superior for using a more than 20 years old text editor, but unless you tune it up to do automatic syntax checks and advanced greps ("refactoring" sounds too advanced but Vim might allow something...), you are risking your reputation as a good engineer. And probably opening multiple doors that all lead to errors due to wrong manual refactorings.

Even simple tasks like documenting the methods are too frequently outdated or wrong and there are IDEs that automatically notice you where the problem is (even hint the solution).

I have a personal crusade with PHPStorm to leave all the files my team owns in green (0 errors/warnings), because I'm stupid and I like the IDE to autocomplete my method signatures, the mocking options I have in PHPUnit, or simply because I hate to open a 600 lines file that contains 100 lines of unused code, some times even with errors of no longer existing classes.

Stop being cool and be pragmatic. And if you still want to go the hard path, be a real tought guy and go until the end, setting up syntax check and similar plugins.


Posted by Kartones on 2013-01-03