-2

I have been struggling to understand programming paradigms.

OOP is a paradigm with sole aim of modeling complex (real-world) systems, and it got me thinking:

  1. is OOP the only programming paradigm that lets us model complex system?
  2. if No, why is OOP Unique or Super Popular?
  3. because, functional programming contains a bunch of function, does that make java a functional language because it contains functions/methods?
2

3 Answers 3

7

OOP is a language with sole aim of modeling complex (real-world) systems

No, sorry, no.

OOP is very good at modeling reality. However, that is not its sole purpose, in fact, we often model very abstract things with OOP.

All those example of “Animal” and stuff you see in OOP courses… probably only make sense in an academic context and in video games (And there we will probably suggest to depart from using inheritance and encapsulation in favor of an Entity-Component-System solution). Still, those example make OOP approachable, even if they focus on the wrong thing.

As any other paradigm, OOP abstracts complexity. Thus, complex systems are not exclusive of OOP either.

And finally OOP is not a language. It is a paradigm. There are OOP languages (plural).


is OOP the only programming paradigm that lets us model complex system?

What if I tell you can implement an OOD (object-oriented design) in language that is not object-oriented? There is a very simple convention: The this pointer is the first parameter of the methods.

So, you make every method a procedure that takes a pointer to a structure "this" as first parameter, and that structure has all the fields of the object.

Everything static goes to global scope...

You can implement your OOD with that.


Yes, there are ways to do inheritance, even virtual dispatch. Look, objects do not exist in the CPU. At some point all the OOP stuff gets converted to instructions. I cannot possibly go over how it is all done here. Yet, know that having a OOP language can cut a lot of work.


You, of course, would not have any of the protections of OOP (visibility levels, for example). That means you need to be extra careful.

OOP is there to both protect you from yourself (It is there so you do not shoot yourself in the foot) and make things easier (it provides useful abstraction). In fact, I am saying that OOP restricts the things you can do! OOP does not allow you to do anything you could not do without, it just makes it easier and safer.


if No, why is OOP Unique or Super Popular?

It is easy. In particular they start teaching OOP before you do procedural or structured. An object is a noun (or that is what they teach you), and a method is a verb, it reads like prose.

We have no intention to go back to procedural or structured programming if we can help it. With those, it is easier to get things wrong, and we are more productive in OOP.


The way I see it is not so much that OOP is popular, it is that the most popular languages put an emphasis on objects and classes. Companies use them, there is demand for talent, people want to learn them, there are courses to learn them, people use what they learned. Once a language dominates the market it is very hard to take down.

I think you will more interesting answers if you start looking up why functional languages, in particular the early functional languages are not as popular. What I see again and again is people saying it they are hard to understand. My opinion is that lack a neat way to introduce the concepts. You know, an "Animal" class equivalent for functional programming. At least the introductory examples I have seen lack an emotive connection (yes, I don’t even connect with cartoony monads, I haven’t seen a floating 2 in my life).


because, functional programming contains a bunch of function, does that make java a functional language because it contains functions/methods?

Java isn't purely OOP. That part is true... You can do functional programming in Java if you want to. You can do fully OOP in Java if you want to. It is worth noting that the functional aspects of Java are relatively new, and the standard library is chiefly object-oriented.

However, having methods is not what makes a language functional. Methods are part of OOP. If having method were enough to declare something functional, then every OOP language would be functional.

Instead, a functional language should have functions as first class citizens. In a functional language, a function is a value. You can have functions that take functions as parameters. Also functions that return functions. In fact, it is not rare to create functions by combining other functions. And if you really want to, you can store a function in a variable.

There is sugar in Java to mimic those things, however behind the scene a lambda in Java is an object of an anonymous class that implements a method that can be called. Java is OOP first, functional second. Nothing wrong with that.

Yeah, Java is multi-paradigm. Java is functional, concurrent, object-oriented and imperative. You will find that all the popular modern languages are multi-paradigm. That just makes it easier for them to remain popular.


Recommended viewing:

4
  • 1
    and don't forget that Java and many other languages can be used as procedural as well. Which is something quite different from functional :)
    – jwenting
    Commented Nov 25, 2019 at 7:06
  • 1
    "OOP is very good at modeling reality" - I think that depends on how you model reality! Every "manager" or "actor" object I've ever seen modelled crucially lacks any notion of human brains or initiative, which is something they possess in reality - OOP is to "reality" what a doll's house is to the workplace.
    – Steve
    Commented Nov 25, 2019 at 10:09
  • 1
    @Steve Well, it models the parts of reality that the system cares about... which is about half of what "modeling" means - if you're modeling the fluid dynamics of pure water, you probably do need to model gravity but you probably don't need to model quantum tunneling - even though it may exist in the system, it's not particularly relevant and modeling comes with some inherent level of simplifying a system to model. If we weren't simplifying, we'd call it simulating the system rather than modeling (its behavior).
    – Delioth
    Commented Nov 25, 2019 at 22:11
  • 1
    @Delioth, my point was simply that OOP is neither a model nor a simulation of "reality" - I thought such software consultant bunkum was discredited in the 90s. A "manager" object is not an essential representation of a human manager, it is some sort of skeuomorph, and it bears more in common with the manager's clipboard and the manager's paperwork, than it does the actual manager. Often, the task of a programmer is to design or redesign that paperwork and the rules for its proper use - to conceive or reconceive a system of administration - nothing so grandiose as "modelling reality".
    – Steve
    Commented Nov 26, 2019 at 2:20
2

Most high-level programming languages provide for functions, because they facilitate functional decomposition, promote well structured code, and encourage reusing code thus avoid to repeat the same fragments over and over again.

But this is not sufficient for making a functional programming language. FP requires at least that functions can be arguments to other functions, and that higher-order functions can return functions as result. Some would argue that FP would also expect lambda functions, but we could argue that this is just a convenience for not polluting the namespace and declare functions as close as possible to where they are used.

A language providing all these features, is said to support the functional programming paradigms. Java, C++ and C# are for example multi-paradigm languages and allow for some level of FP, next to imperative programming, OOP and even other paradigms.

The term “functional programming language” is in general reserved for languages that use FP as main paradigm, such as Ocaml and #F. Such languages are in general more declarative than imperative: you declare functions and data structures, the language does the rest. And one would also expect that such a language has features that encourage referential transparency and discourage side-effects.

Coming back to OOP, it is very popular because it allows to easily create super-modular component-based systems that provide for data and the methods needed to correctly and consistently process this data thanks to abstraction and encapsulation. So in other words, it facilitates the creation and maintenance of very complex systems.

Other paradigms allow for complex system as well. Structured programming is a good example: ADA allowed to build very complex systems since 1980 and objects where introduced therein only in 1995. Also, operating systems are mostly developed without OOP even if some of their design is inspired by OO. We are speaking of systems with millions of lines of code here.

2

Hey there stranger

Welcome.

I have been struggling to understand programming paradigms.

So have I. Since the 80's.

OOP is a language...

No, like you said, it's a paradigm. Java is a language.

...with sole aim of modeling complex (real-world) systems

Or simple systems. Like "Hello world" and "Hey there stranger".

is OOP the only programming paradigm that lets us model complex system?

Nope. I can also model complex systems in imperative, declarative, procedural, functional, symbolic, and even analog.

if No, why is OOP Unique or Super Popular?

Because it's taught in the first year of programing degree programs.

because, functional programming contains a bunch of function, does that make java a functional language because it contains functions/methods?

If your definition of a 'functional language' is that you can write pure functions in it, then yes, absolutely. If your definition is that you can only write pure functions in it, then no.

Java has been getting more an more functional lately but it's still a multi paradigm language. You can use it all sorts of ways. You don't have to use OOP or pure functions when you use it. But there are definite benefits to using these paradigms.

The advantage of a pure functional language is everyone knows what to expect. In Java it's a grab bag. If you go to the trouble of making pure functions in Java I recommend leaving a comment somewhere calling attention to that fact or someone is liable to drop a side effect right in the middle of it and ruin all your hard work.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.