Is there any reason to prefer procedural programming over OOP

Started by
35 comments, last by BitMaster 7 years, 9 months ago

Inheritance is a very critical part of OO and I would argue without it you're probably not doing OO. Likewise functional programming with explicit state is really not functional programming.


I disagree. I find that in my modern code inheritance plays a very minor role. Polymorphism is used even less frequently. Runtime polymorphism, that is. Compile time polymorphism happens much more frequently.

Just for kicks, take a look how much inheritance or polymorhism is used in the C++ standard library. There are the streams of course but I would be hard pressed to find another inheritance/polymorphism example quickly. Significant parts of the standard library are intentionally inheritance-unfriendly.

Of course in some domains (for example UI frameworks like Qt) you cannot throw a stone without hitting something polymorphic but that is not true for the general case.
Advertisement

Just for kicks, take a look how much inheritance or polymorhism is used in the C++ standard library.


Not that I disagree with your general point, but I don't know that I would necessarily call the standard library especially object-oriented - in fact, its original designer believes that the C++ standard library (or at least its predecessor) isn't even object-oriented at all, so I would say that the standard library is not really a useful example of "modern OO". Relevant quotation from that link:

Yes. STL is not object oriented... I find OOP technically unsound. It attempts to decompose the world in terms of interfaces that vary on a single type. To deal with the real problems you need multisorted algebras - families of interfaces that span multiple types. I find OOP philosophically unsound. It claims that everything is an object. Even if it is true it is not very interesting - saying that everything is an object is saying nothing at all. I find OOP methodologically wrong. It starts with classes. It is as if mathematicians would start with axioms. You do not start with axioms - you start with proofs. Only when you have found a bunch of related proofs, can you come up with axioms. You end with axioms. The same thing is true in programming: you have to start with interesting algorithms. Only when you understand them well, can you come up with an interface that will let them work.


Note that he's specifically against runtime polymorphism switched on single interface. Most of what he's talking about specifically refers to OOP as pushed in statically-typed Java-like languages as opposed to languages like SmallTalk.

Of course, this topic has been discussed for a while and nobody agrees on what OO is, so I suggest that OP ought to have specifically referenced "which" OOP we're to compare with procedural programming.

I disagree. I find that in my modern code inheritance plays a very minor role. Polymorphism is used even less frequently. Runtime polymorphism, that is. Compile time polymorphism happens much more frequently.


Just for kicks, take a look how much inheritance or polymorhism is used in the C++ standard library. There are the streams of course but I would be hard pressed to find another inheritance/polymorphism example quickly. Significant parts of the standard library are intentionally inheritance-unfriendly.

Of course in some domains (for example UI frameworks like Qt) you cannot throw a stone without hitting something polymorphic but that is not true for the general case.

Lost a long post... :(

Long post made short: I'm sure your code is fantastic, but is probably not true OO.

C++ is a rather poor OO language, lacking virtual constructors and multi-dispatch (amongst other things). Its a multi-paradigm language and any good C++ coder (as I'm sure you are having seen prior posts) leverages multiple paradigms in any non-trivial program. Not using inheritance in C++ simply means you're not trying to use a hammer where a screwdriver would be better.

I think the distinction between paradigms and languages is important, as they serve different purposes.

All right, lets see...

You cannot do procedural programming in Java

You can't do it in C# either yet you use it as an example.

Writing a simple 'Hello World' program in Java isn't contrived OOP as an exercise, its contrived OOP because that's what the language demands.

Yes, thats true because it isn't a language designed to make "Hello world" programs. If all you want is to write short "Hello world" programs I'd recommend something else, like just make an HTML label tag and open it with a browser.

We can agree though, that most early programming habits anyone picks up in any language are best to hit the dustbin sooner than later. Rarely are first habits good habits.
Of course.

it just so happens that among those goals are enforcing a particular and rigid view of OOP best-practices, protecting fully-functioning programmers from themselves, and a misguided attempt to make Java programmers interchangeable by creating a language that forces them into the lowest-common denominator.
And why don't you say the same of say, Python which heavily discourages implementing your own data structures by ubiquitously using their own and having special syntax only for that purpose? Why dont you say the same of JavaScript from which until very recently was confined to be a browser scripting language? Why single out Java as the dogmatic example in the age where all the most used languages, except very few exceptions, are just as opinionated, or even more?

You could say that of most of modern languages. Nevermind the recent wave of people advocating even more religiously opinionated languages in the functional paradigm. Fixating on Java seems such a 90s thing to do. Where the concept was relatively new. Python was new, JavaScript was new. C and C++ were the way of making applications. Nowadays? Makes no sense, but I see people repeating it again and again.

IMO, C# did a much better job achieving Java's technical goals, and was better for throwing off as much dogma as it could.

Have you ever developed an application in .NET? Language is fine, (and practically Java in PascalCase 90% of the time regardless of what most C# purists say) but the ecosystem is centered around Bill Gates butt. I dont even know how could you paint it as the "least dogmatic" of the two.

Yeah, its the "least dogmatic" if you already use Visual Studio all day and deploy to a Windows Server computer every day, and only do fat destkop clients for Windows 7+ in WPF. As soon as you get out of that tiny cage you're thrown to the wolves. GUI solutions for other platforms are broken. Web solutions for other platforms are either broken (Xamarin) or in alpha stage (.NET Core). Nevermind finding tools to help you out in that endeavor because there is like only one half assed IDE out there that manages to understand C# and Linux/OSX at the same time.

Yeah C/C++ are not very dogmatic, but people are constantly trying to replace them with more dogmatic equivalents (Rust, Go among others), and C# is Microsoft's eco system baby and barely knows how to crawl anywhere else, nevermind the fact that C# 7 stuff and above are very, very close into making it a kitchen sink of features like C++ is.

I'm just not seeing your counter examples at all man.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

You cannot do procedural programming in Java


You can't do it in C# either yet you use it as an example.


As far as I was aware, the only requirement to be 'procedural' were procedures (functions, methods, etc). I'm not sure what kind of silly semantic games you guys are playing here...

Are you saying that because you have to define functions inside organizational units called classes, it's no longer a procedure?

To me, procedural/object oriented is a *mentality*:


// procedural mentality
foreach (thing in collection)
{
    DoOperation(thing, additionalParameters);
}

// object oriented mentality
var visitor = new DoOperationVisitor(additionalParameters);
visitor.Traverse(collection);

// functional mentality
collection.ForEach(x => DoOperation(x, additionalParameters)); // But seriously, don't use ForEach
I don't see much dogma in .Net. Dogma in programming means "lack of flexibility". .Net is anything but inflexible...


File.WriteAllBytes, File.WriteAllText // Procedural convenience functions

Stream, FileStream, StreamWriters, BinaryWriters // Object oriented composition

collection.Select(x => x.Name).OrderBy(x => x).ToList(); // Functional pipelining

UIElement // Type hierarchies in WPF with decent polymorphism and data binding; Object oriented and declarative

IAsyncResult // Capable of being used via polling, callbacks, WaitHandles, mixed with async/await, etc.
C# doesn't force you to solve your problem in one way. I think that's what Ravyne meant.

Don't look at me. I think the "but but I have to type "static" and put it in a class file!" complaint is stupid. If it looks like a duck and quacks like a duck... C# has exactly the same requirements thus why I dont see the point.

"I AM ZE EMPRAH OPENGL 3.3 THE CORE, I DEMAND FROM THEE ZE SHADERZ AND MATRIXEZ"

My journals: dustArtemis ECS framework and Making a Terrain Generator

Inheritance is a very critical part of OO and I would argue without it you're probably not doing OO. Likewise functional programming with explicit state is really not functional programming.

I disagree. I find that in my modern code inheritance plays a very minor role. Polymorphism is used even less frequently.
I'm sure your code is fantastic, but is probably not true OO.

I disagree. It is a fundamental rule of OOD that you should use composition by default, and inheritance only when necessary.

In particular, I'd go as far as to say that if OO code uses implementation inheritance extensively, it's probably bad code :lol:

As mentioned earlier, there's a big difference between implementation inheritance and interface inheritance, though. The latter sees some use in OOD code, but really not that much most of the time. The former is frankly a code smell, and doesn't even exist as a concept in "true OOD" (it was added later as a convenience feature by OOP language designers, and overly abused by early OOP adopters).

In order of how common these features should be used in OOD code: Composition > Interface inheritance > Implementation inheritance.

But in "typical C++ bullshit" code, you see: Implementation inheritance > Interface inheritance > Composition... which becomes a straw-man argument for people to use in their ill-informed "OO is bad" debates.

Step 1: agree with Hodgman. Whew. That saved me some mental work and typing.

I'm sure your code is fantastic, but is probably not true OO.


I'd like to add a few comments about that though. Considering the amount of religious wars fought about what OO really means I'd say this statement is rather pointless.

Since it is scheduled to be hot today and I want to finish the work I need to finish with the minimum amount of time wasted allow me to speed up the usual process at this point. So:
Yes, my code is the real true OO.
No, you don't know what you are talking about.
You are also a <mild expletive of your choice>.

Disclaimer: this post may contain irony and/or joking hyperbole below the quote.

Don't look at me. I think the "but but I have to type "static" and put it in a class file!" complaint is stupid. If it looks like a duck and quacks like a duck... C# has exactly the same requirements thus why I dont see the point.


I have to agree here. I have developed a significantly less positive view of Java than I had in the past but I never understood (and still don't) that particular complaint. Procedural style in Java is possible without problems.

Okay, so I have to put my functions in a mandatory namespace and a bit counter-intuitively the namespace is declared with the 'class' keyword. We could add some syntactic sugar and add a 'namespace' keyword which just means 'class with all member functions and data automatically static' but among all the legitimate complains one could have with Java, this feels a bit ... pointless.

Just for kicks, take a look how much inheritance or polymorhism is used in the C++ standard library.


Not that I disagree with your general point, but I don't know that I would necessarily call the standard library especially object-oriented - in fact, its original designer believes that the C++ standard library (or at least its predecessor) isn't even object-oriented at all, so I would say that the standard library is not really a useful example of "modern OO".


He is certainly entitled to his opinion but in my opinion the standard library contains a lot of what I would consider 'modern OO for C++' (while not 'classically taught OO' which nowadays often feels to me like the 'bad OO' anyway).

This topic is closed to new replies.

Advertisement