DEV Community

Discussion on: Explain Declarative vs Imperative Programming like I'm 5

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard • Edited

SQL is declarative. You tell SQL your intention:

"I want to fetch all users living in Berlin drinking coffee".

How to best implement this? The nice thing is that you can mostly let SQL figure this out, merely giving him indications that you will use often this index to do searches.

Imperative programming is micro-management: do this, then do that, then do this, then do that.

Collapse
 
khophi profile image
KhoPhi

If

SQL is declarative. You tell SQL your intention

Then ORMs are "Imperative"?

Collapse
 
jmfayard profile image
Jean-Michel πŸ•΅πŸ»β€β™‚οΈ Fayard

Nope, ORM are just a convenience wrapper to make SQL easier to use in your programming language, but apart from them pretty much the same.

If you were to create your own logic on how to fetch efficiently all users living in Berlin, that would be imperative.