3

When I look at numerous websites. Some use object-oriented programming and imperative programming interchangeably whilst others say that they are different.

I would like to know what is the difference between object-oriented and imperative and how these paradigms differ. Or if their is no difference at all.

attachPost
  • 75
  • 1
  • 1
  • 10

2 Answers2

9

This is a tough one because the terms involved often mean different things to different people.

Roughly speaking (although some would say "strictly speaking") imperative is the opposite of declarative.

Strict OO proponents would likely say that OO is declarative. See the "Object Thinking" style of OO in David West's book of that name and this blog: http://www.yegor256.com/.

OO as it is commonly practiced often "devolves" (again, others will sharply disagree) into a very procedural and imperative style where you start telling the computer what to do rather than describing and modeling the real world (in some sense) with your objects.

(Here's a video that might be useful. It contrasts procedural programming and OO, and for our purposes here "procedural" is roughly a synonym for "imperative".)

I know that's not a great answer, but maybe it's useful.

NQA
  • 315
  • 1
  • 3
  • 11
  • 1
    So is OOP almost metaphorically like a man-in-the-middle between procedual and imperative paradigms? – attachPost Jul 22 '16 at 14:30
  • @attachPost, please edit your question, or ask a new one, rather than starting a discussion in comments. – jaco0646 Jul 22 '16 at 14:36
  • 1
    Not exactly sure what you mean @attachPost, but I would say that OOP can be considered either imperative or declarative depending on how you define OOP. For full disclosure, I'm moving right over to the view that "good" OOP (OOP properly understood) is fundamentally declarative. The more imperative or procedural it becomes the more you're missing the point. And there ideally shouldn't be much (if any) mixing of the two approaches. This view won't go down well with many people. But you should at least be aware of the two "extremes". :) – NQA Jul 22 '16 at 14:38
  • Ah, sorry @jaco0646. What are the comments for then? (That's a genuine question, in case it comes across snarky!) Cheers. – NQA Jul 22 '16 at 14:41
  • http://meta.stackexchange.com/questions/95937/why-must-we-avoid-discussions-in-comments – jaco0646 Jul 22 '16 at 15:23
  • Thanks @jaco0646. Those answers though seem about off-topic stuff, or about not being about the post. "attachPost" and I were talking about the post. This conversation, though, _is_ perhaps off topic. So I'll leave it there... – NQA Jul 22 '16 at 15:31
  • 1
    @JohnPage _I know that's not a great answer, but maybe it's useful_ I think it is a great answer. This is common source of confusion for people comparing OOP and FP – rahulaga-msft Oct 22 '18 at 07:50
2

Coming from top to down, there are two main subtypes of imperative languages.

  • Procedural languages (e.g. BASIC, FORTRAN) - where code and data are treated as completely separate, and have a simple code-operates-on-data paradigm.

  • Object-oriented (OO) languages - where data and code (in the form of methods) are bundled together into objects. In OO languages, additional structure is imposed to a greater or lesser degree by metadata (such as class information).

vtor
  • 8,989
  • 7
  • 51
  • 67
  • 1
    Do not confuse programming languages with programming paradigms. Most modern languages support multiple paradigms. – jaco0646 Jul 22 '16 at 14:29