Write code that is easy to delete, not easy to extend (2016)
I wholeheartedly agree with &quot;don&#x27;t immediately jump on the modularize and abstract everything right away&quot;.<p>I think that &quot;modularization and abstraction is always and uniformly good&quot; is one of the big lies of our profession. It’s easy to see how it’s attractive : programming is intellectual work, and displaying capacity of abstraction is rewarding. I was extremely enthusiastic about that stuff when I was young, too. Then I got to school to get a CS degree, and it only reinforced it.<p>Now that I have some years of experience, let me talk to you about my last job. It’s a web app like most of us (I think) are doing. Backend in node. Frontend in react. The client was extremely unhappy about the delays and cost of their current contractor (weeks and 4-digit invoices for simple features), they wanted us to in charge of the app.<p>As soon as I received the source code, I looked at the backend part. It was incredibly clean for the standards of my younger self and CS teachers. Each class in his own file. You had one routes&#x2F;_index.ts file that just included routes&#x2F;users&#x2F;_index.ts for &#x2F;users, routes&#x2F;blog&#x2F;_index.ts for &#x2F;blog, and so on (recursively: you would have routes&#x2F;blog&#x2F;comments&#x2F;_index.ts too). routes&#x2F;*.ts would be just that, declaring routes. Code was cleanly separated and implemented in controllers (controllers&#x2F;users&#x2F;_index.ts, and so one). Of course the controller didn&#x27;t directly used the ORM, there was intermediate DAO classes to do that.<p>Very clean. Also, changing the slightest things required to go through 5-6 files. May god save your soul if you wanted to change more complex stuff.<p>I discarded everything. Most of the code now lies in &#x2F;app.ts, which contains all routes. Each route is directly implemented in this file (no separate controllers) and directly calls the ORM (no DAO), except one which does complicated stuff and has his own implementation file.<p>Loccount on my &quot;ugly, not modular&quot; backend, which, incidentally, has many more features (that the client wanted for months but the previous contractor couldn’t implement for a reasonable price&#x2F;time). And ~1&#x2F;3rd of those lines are just some CSS assets moved from the frontend to the backend because we needed them for the mailing list:<p>all          SLOC=2284    (100.00%)     LLOC=0       in 13 files<p>Loccount on the &quot;very clean&quot; backend of the previous contractor:<p>all          SLOC=12507   (100.00%)     LLOC=0       in 262 files<p>Now, don’t get me wrong. Abstraction and modularization are not uniformly and always bad. But they have to make sense. Don’t write and organize a 2k LOC project the same way you would write and organize a 100k LOC project — or you’ll end up with a 500% overhead in LOC that WILL translate to a 500% higher burden of maintenance.<p>I just wish school taught me that, or that my younger self could have been clever enough to see it by himself.