There’s an interesting post on Reddit in which Dracony speaks his mind about decoupling your application code from the framework. That is, about why it’s not too clever to do so.
In a nutshell, he argues that the use case for switching a framework mid-lifecycle for an app is unheard of, and that we should stop coding solutions for problems that aren’t there. By adding in abstractions, we waste valuable time that could be better spent otherwise, and there’s a high chance that even if we get to a point where we do have to change frameworks, we’ll find out we haven’t done a good enough job of abstracting our app, and will have to refactor a big part of it regardless. Time and effort completely wasted, then.
To many, this sounds too extremist - we all know that, for example, Laravel has some helper methods that look “native”, i.e. one might be tempted to think they’re native PHP functions when skimming through the code. Using them in services and components then tightly couples said services and components to the framework, so we should, naturally, decouple and abstract as much as possible. That’s not what Dracony is talking about, however.
In the above case of Laravel’s tentacles latching onto a project, most people who are decent at coding avoid this - we isolate our components into encapsulated packages with no holes through which such infections could spread. What Dracony is talking about, however, is trying to abstract absolutely everything in an app to be completely oblivious to a framework. Have a templating engine? Abstract it with a TemplateEngine interface. Have a MySQL database? Abstract with PDO. Using PDO? Abstract with yet another layer, and another, and another. All in the name of not tying your app to anything concrete. That’s abstraction hell.
The position I agree with is this commenter’s - most frameworks out there are “front end” in that they deal with templates, controllers, routes, forms, validation, while there are few “back end” ones. He suggests we should “couple” the front end stuff - because that all usually belongs in a specific framework anyway - and decouple everything for the back end - our services and other components that provide logic for the front end.
What are your thoughts on this? How much decoupling do you or don’t you do?