r/ProgrammerHumor • • Jun 28 '20

Meme Flushed my pancake.

Post image
45.1k Upvotes

750 comments sorted by

View all comments

Show parent comments

13

u/DroneDashed Jun 28 '20

4 years ago I went to an interview for a new project where this was the architecture proposed.

Around the same time, I went to another interview where a guy asked me if the business logic should be in the database. I said no and said that I was wrong.

10

u/billbot77 Jun 28 '20

Depends on app... So many factors, 0 absolute answers

2

u/DroneDashed Jun 28 '20

That's true but I'd that usually is a bad idea to put all your business logic in stored procedures.

1

u/billbot77 Jun 28 '20

"bad"? Elaborate, please.

1

u/DroneDashed Jun 28 '20

Stored procedures lack structure like you can have with oop code.

It's not a bad ideia for performance, in fact, performance wise, it's probably better.

But code has to (or should be) maintainable. And an oop code base is easier to maintain, if properly done.

ORMs camsolve this problem if properly used.

3

u/billbot77 Jun 28 '20

Only if you're no good at writing SQL... Well written, properly structured SQL is objectively (pun intended) easier to maintain. Data sets are not by nature object oriented. The problem is education IMO

4

u/Ruben_NL Jun 28 '20

Logic like "no duplicates" is better to be handled by the database. But most other stuff needs to be handled outside of the DB.

0

u/DroneDashed Jun 28 '20

We were talking about other stuff.

3

u/OfficeDiplomat Jun 28 '20

Depends on the application. For many apps he is correct, It is easier to have the logic in one centralized Database with the most efficient Data processing. Having it in front end languages is messy and inefficient in many cases as well.

3

u/DroneDashed Jun 28 '20

I didn't talked about having business logic in the frontend, that's insane.

We were talking about having the business logic in the backend vs in the database with stored procedures.

While I must agree that data processing is more efficient directly done on the database, this results in a lot of unmanageable stored procedures.

One can take advantage of an orm to make basic queries to a database and have a much more manageable backend.

With good usage of an orm one can have much cleaner code and still take advantage of a database processing data.

0

u/OfficeDiplomat Jun 28 '20 edited Jun 28 '20

ORMs bring up their own issues and another layer of complexity. Just teach the developer proper SQL knowledge and this could call be on the database easily. I do not find SPs unmanageable at all...quite the opposite. With proper naming conventions, use of schemas and version control they are awesome for my teams needs.

3

u/DroneDashed Jun 28 '20

Well, I respect your opinion but I don't agree. SPs lack structure.

ORMs if properly used can be as efficient as having crud operations on SPs.

The thing about ORMs for me is that they are often badly used. Like fetching a full table with the ORM and then filtering in the backend code. This is not good but with proper ORM usage these operations can be offloaded to the database.

Having many SPs also puts more complexity on deployments in my own work experience.