Ten years ago, I wrote the most beautiful, clever, over-engineered piece of code ever. I was building a REST API for a startup, and discovered lots of

Don't be clever

submited by
Style Pass
2023-06-03 06:00:06

Ten years ago, I wrote the most beautiful, clever, over-engineered piece of code ever. I was building a REST API for a startup, and discovered lots of repetition between controllers: I was building the same kind of actions and copying code over and over again. So I came up with a solution: The CRUDController™.

It was a beautifully complex, abstract class that integrated with Doctrine (the ORM that I was using back then). It had every possible CRUD operation you could think of — not just for entities, but also for child- and has many relations; there were automatic overviews, filtering, pagination, validation, data persistence, routing, and what not.

And the only thing I had to do was to create a new controller, extend from my amazing CRUDController™, provide an entity class, and be done.

Expect, of course: exceptions started to emerge. Not the programming kind, but the business kind. Some controllers had to do some things a little differently. It were small things at first: different URL schemes, different kinds of validation; but soon, things grew more and more complex: support for nested entities or complex filtering, to name a few.

Leave a Comment