2013/02/28

The importance of SOLID principles

I don't know why it’s not a common practice in my country to apply engineering principles to software development. It's shocking that practically every project manager and programmer I've met thinks that engineering principles are merely an academic matter and, in real life, it’s more important to sprint to deadlines than to waste resources designing the product and applying good development practices. What baffles me is that all those projects I've found where the team didn't follow such principles had a lot of trouble meeting deadlines because adding features became increasingly harder without having to break something already built in. And those involved never even realized why this was. It’s really simple, big projects are more like a marathon than a 100-metre dash, so you can’t be sprinting all the time without losing your breath and failing to keep the required pace in order to arrive on time.



For example, on my most recent project, the team lost their way and eventually dropped almost every good development practice they had started with. When I arrived during the third year of the project, I tried, as always, to produce quality code despite the project manager’s lack of interest on that matter. I managed to DRY the code, introduce test-driven development, create integration tests and came close to applying every single one of the SOLID principles to all my work... all except the last letter (yes, my code was only SOLI). Due the design of the factories that we used I wasn't able to comply with the dependency injection principle. Ok, it didn't matter... Actually it was a pretty good achievement to have improved the product quality, even when that wasn’t my boss’ primary concern, while all my deadlines were being met... Attaboy!

Everything was going smoothly, but when the number of my automatic tests started to grow I started foreseeing some problems: a good portion of my tests overlapped, so the execution time was not optimal for their code coverage; and almost all of them modified the database’s content which caused a deterioration of performance and readability because I had to insert data for the tests and clean up after their execution.

Solution? Mock all DAOs and other dependencies in order to improve the tests’ readability and performance. But how do you mock all dependencies of a unit under test without dependency injection?

Attaboy! :(

2 comments:

  1. That's the point Javi!!! Has relatado muy bien lo que es el lastre de casi todos los proyectos y en especial el último en el que hemos colaborado. Es una pena que se valore más, el que se haya hecho, que el cómo se haya hecho. En fin así nos va!!! Saludos

    ReplyDelete
    Replies
    1. Oye, que hacer haciamos ¡¡¡en tiempo y forma!!! :D

      Mi primer comentario en el blog... ¡Gracias!

      Delete