Write code that is easy to delete, not easy to extend (2016)
programmingisterrible.com
Write code that is easy to delete, not easy to extend (2016)
1–10 of 113 posts
Re: Write code that is easy to delete, not easy to extend (2016)
#2Re: Write code that is easy to delete, not easy to extend (2016)
#3I have to confess, I was a solid halfway through before I realized it was satire.
It's at least good satire, it's so close to the real kind of article it apes.
Re: Write code that is easy to delete, not easy to extend (2016)
#4I have to confess, I was a solid halfway through before I realized it was satire.
Re: Write code that is easy to delete, not easy to extend (2016)
#5I have to confess, I was a solid halfway through before I realized it was satire.
Is it? I agree with almost all of it.
Re: Write code that is easy to delete, not easy to extend (2016)
#6I have to confess, I was a solid halfway through before I realized it was satire.
You missed the Sarte quote about programming in C at the top then. It's at least good satire, it's so close to the real kind of article it apes.
Re: Write code that is easy to delete, not easy to extend (2016)
#7Had a good laugh when I was starting out.
Re: Write code that is easy to delete, not easy to extend (2016)
#8Earlier quoted context omitted.
You missed the Sarte quote about programming in C at the top then. It's at least good satire, it's so close to the real kind of article it apes.
Not satire so much as an ironic dialectic - a progress through a series of (decreasingly?) daft ideas
Re: Write code that is easy to delete, not easy to extend (2016)
#9I have to confess, I was a solid halfway through before I realized it was satire.
Worth digesting
Re: Write code that is easy to delete, not easy to extend (2016)
#10I think that "modularization and abstraction is always and uniformly good" 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.
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.
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/_index.ts file that just included routes/users/_index.ts for /users, routes/blog/_index.ts for /blog, and so on (recursively: you would have routes/blog/comments/_index.ts too). routes/*.ts would be just that, declaring routes. Code was cleanly separated and implemented in controllers (controllers/users/_index.ts, and so one). Of course the controller didn't directly used the ORM, there was intermediate DAO classes to do that.
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.
I discarded everything. Most of the code now lies in /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.
Loccount on my "ugly, not modular" backend, which, incidentally, has many more features (that the client wanted for months but the previous contractor couldn’t implement for a reasonable price/time). And ~1/3rd of those lines are just some CSS assets moved from the frontend to the backend because we needed them for the mailing list:
all SLOC=2284 (100.00%) LLOC=0 in 13 files
Loccount on the "very clean" backend of the previous contractor:
all SLOC=12507 (100.00%) LLOC=0 in 262 files
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.
I just wish school taught me that, or that my younger self could have been clever enough to see it by himself.