1
$\begingroup$

Is object oriented programming considered to be a declarative programming approach?

On Wikipedia, it is said that OOP tries to extend the imperative programming paradigm to a somewhat declarative programming approach, but what precisely makes OOP imperative or declarative?

$\endgroup$
1
  • $\begingroup$ The distinction between imperative and declarative has always been a matter of degree based on a context of comparison, and somewhat a wooly distinction even then in my opinion. I would treat the term as effectively meaningless in the abstract. $\endgroup$ – Steve Feb 13 at 16:02
1
$\begingroup$

When you write an OO code, you describe object features (attributes, properties, methods) and implement them. This may be seen as declarative: you do not have an imperative approach giving the sequence of operations to reach a given goal; you have a declarative approach describing features of objects, in a sense characterizing them.

To be more precise, let me take an example. When one says that an image has a filtered version, a blurred version, etc, this may be seen as declarative; these are features of any image. When one implements a procedure to filter or blur an image, then this is imperative: the code is thought of as a sequence of operations aiming at transforming an image, not a description of what the transformed image is.

I am not an expert, though, so I hope someone will correct this if needed.

$\endgroup$
1
  • 1
    $\begingroup$ Yes, I don't think this approach would bear much weight. Certainly, OO code is still concerned with explicitly sequencing operations. Member methods are written imperatively, and if the resulting method when taken as a whole (that is, when reduced to its descriptive name, and the implementation innards treated as a black box or subject to change) is considered "declarative", then so is every subroutine in any language. $\endgroup$ – Steve Feb 13 at 16:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.