Get the latest tech news

Code in Database vs. Code in Application


In which we address the perennial question of when it’s appropriate to push domain logic into database stored procedures and triggers versus keeping it at the application layer.

To prepare for writing this, I went around the web and looked through the top blog posts and Stack Overflow threads that I could find to see what other people say, and was surprised by the size of the gap between many of the recommendations and common practice. You’ll be printf debugging at best, and you almost certainly won’t have access to powerful development tooling like code-completion through LSPs (an LSP implementation would have to be actively talking to your database to know what relations and fields are available, which sounds like a configuration nightmare). Sure, you can disable them temporarily, but then you’re losing their ostensible benefits, and it might be not be obvious that things are slower than they should be because the triggers aren’t easily visible (see “opaque side effects” above).

Get the Android app

Or read this on Hacker News

Read more on:

Photo of database

database

Photo of Code

Code

Photo of application

application

Related news:

News photo

GitHub's Copilot lies about its documentation. Why would I trust it with my code

News photo

It's hard to write code for computers, but it's harder to write code for humans

News photo

Infosys scores deal to write code for EV-maker Polestar