19 points · by geekydev · 4y ago · 60 comments
I really don't have these kinds of problems; it's likely due to experience. It's not that I don't use inheritance, encapsulation, polymorphism, etc. I do. And when I do, it works exactly as it's supposed to. I don't over-use it, I don't use it when it's not appropriate. This is the same with functional concepts as well.
Object-oriented programming is the most successful programming paradigm in history. But you don't get to the front page of hacker news with that information.
I don't think it is. The vast majority of code is imperative, with sometimes classes here and there, and these days with sometimes higher-order functions here and there, and with sometimes declarative programming (SQL and stuff like that). But the core is imperative code.
Wrong. Imperative is NOT functional. You cannot have both functional and imperative. They are literally opposites.
You CAN technically have both functional and OOP. However removing mutation from OOP removes the concept of setters and many associated "Design patterns" that are part of OOP.... so it's like removing the ignition from all car engines and still saying that the car is a car.
Many people don't understand what functional programming really is. Allow me to elucidate. Whatever program you can write on a single expression. That is a functional statement. If you write multiple functional statements... the code becomes imperative.
A functional program is an imperative program with ONE expression total. To write a functional program is to place your entire program ON ONE line. That's what functional is.
Now you may have heard that all you need to do is make everything in an imperative immutable for the program to be "functional." This is true. Turns out an immutable imperative program is isomorphic to a functional program. See this:
A = 2 + 2
C = A + 4 (immutable + imperative)
is equivalent to:
C = 2 + 2 + 4 (functional)
However if you add mutation the isomorphism is lost. A = 2 + 2
C = A + 4
A = 3
You can no longer do the substitution above. Because of this isomorphism; to have any real linguistic meaning and differences between the words "functional" and "imperative" means that imperative programs MUST include reassignment. You can reassign a new value to an old variable in imperative programming and such a concept is literally impossible in a functional program because functional programs are just one line expressions.in FP all variable names are simply aliases or macro shortcut expansions. In imperative programs variables are mutating entities.
No it's not. Likely the most popular paradigm. Not the most successful. It's like saying Null is the most successful concept in all of computer science.
But you're just saying that's merely popular and not successful? That seems extremely flippant.
See: https://www.reddit.com/r/AskComputerScience/comments/bhgtzp/...
People in general are stupid. They get onto hype trains they develop biases and they vote for Trump and try to invade the Whitehouse.
Programmers are people. Hence why stupid concepts can propagate throughout the community.
(Not saying OOP is stupid, just saying that something being popular doesn't negate it from being placed in the stupid bucket.)
Update: The way I figured this out is that I mod a subreddit called OOP Is Bad. I usually jump the gun on new articles, and then I have to roll back my posts when I realize they're duplicates. Anyway if you want to read up on the subject, you could do worse. http://reddit.com/r/oopisbad
Thank you for letting me know, and apologize for sharing it
A better approach is probably to implement the code reuse model as an implementation of a public interface, which the subclass then implements and delegates. The cause of the brittle base class problem is likely that the interface between the base class and the subclasses is often not defined very well so it tends to not get engineered very well, and then external code can depend upon the implementation of the base class creating the brittleness.
So instead of having Banana and Orange that inhert from Fruit and having a container like a List<Fruit> if you use composition instead you get Banana and Orange that implement IFruit through delegating to Fruit and your containers are List<IFruit>'s now (you can't see the details of how Banana and Orange implement IFruit they just promise to implement it). You are now free to create FruitV2 which is a snazzy new implementation of IFruit, and you can inject it into Banana and Orange without breaking anyone who depends upon IFruit. It also becomes more apparent when you are making breaking changes because you wind up editing IFruit. You can also use DI or a DI Container (if you must) to control injection of behavior into objects.
And really inheritance is just delegation to another class dressed up and made simple to use. It is the exposure of that base class publicly and without good interface design that makes it bad.
Implicit in what I just wrong there though is that encapsulation is a very good thing and you should only depend on interfaces. I don't know why the author argues that encapsulation is bad. I've lived in the ruby land for 10 years with no encapsulation and in the long run it is literally fucking horrible since anything can have been accessed by some user somewhere with tools like `send()` and any change can potentially be breaking, and users will whine about SemVer even though you certainly never documented what they were doing and would have yelled loudly at them for attempting it if you'd ever known. Fences and neighbors and the tragedy of the commons and all that....
I can easily jump into a more functional oriented codebase and reason about functions with clear input/output and no side-effects. The realtime REPL compiler in my brain can track the private state of functions. And while not all functions can be 'pure', most can be. With OO? Forget about it. Side-effects everywhere, that often aren't obvious when you are new to a codebase.
And when I say "new" I mean it as in "not currently very familiar with". Which includes code I had written myself - years ago - that I have to relearn.
I certainly don't use OOP or FP. I write it as a list of procedures.
From this common use case we can know that Procedural programming is the default way humans think.
Two of the most popular modern programming languages that just came out within the last decade eschew OOP all together: Golang and Rust.
A lot of people will argue about the semantics of OOP and whether golang or rust fits the paradigm in terms of the definition. Let's just make it simple. Whatever OOP methodology python, java or C++ is doing... golang and rust are not doing it.
It is NOT. If you're talking dumb developers it is their problem.
Golang is strictly corporate language with very defined goals and using it it as a hammer is just as dumb. Along with Golang Google using other languages just fine. For example they have huge pile of C++ which supports many paradigms, OOP including.
I do not understand these holy wars where everyone has to adopt "THE ONLY TRUE style, practice, language etc". I think this is really near sighted.
I am not using Rust at all so can say little how good it is "hammer wise"
It VERY MUCH IS. I am not talking about dumb developers. I am talking about basically every developer. The pattern is so ubiquitous that it's basically required knowledge. FP is NOT required knowledge.
>Golang is strictly corporate language with very defined goals and using it it as a hammer is just as dumb.
Golang was invented by Rob Pike who has THIS to say about OOP:
"object-oriented design is the roman numerals of computing"
So is golang a corporate language with very defined goals? Maybe from certain angles sure you can think of it that way. But Did Rob Pike not include OOP in the language because of this? No. From the quote, OOP was eschewed from golang because "it's the roman numerals of computing.">I am not using Rust at all so can say little how good it is "hammer wise"
Rust shares largely the same story and philosophy as golang when judging the OOP pattern.
https://cscalfani.medium.com/goodbye-object-oriented-program...
The other thing most OO practitioners quickly realize: real world things often don't make good object hierarchies or even classes.
OO has not delivered on its promise to partition large scale problem domains effectively, especially for statically typed languages, but maybe in the age of webapps and microservices it doesn't matter as much. The problems we struggled with in the 90s are not as relevant today.
OOP is just a tool within a toolbox. You need to know how to use that tool.
I'm tired of reading this cookie cutter opinion. Can we go deeper?I want to discuss why someone like linus hates C++. The extremities of these opinions are what's worth discussing here because we all can easily get behind the whole "Apples and Oranges" argument. The extreme arguments are the ones that are harder and more interesting. It takes more depth and understanding to develop an opinion beyond the cookie cutter one we see everywhere.
Do you love OOP and think it's better than FP and Procedural programming? Or vice versa? I want to hear your opinion.
Personally reading some of Linus's complaints about C++ seem a little misplaced. And yet, I don't disagree with him either. He says C++ is a terrible language and it's really hard to disagree with that -- not because it's object-oriented but because it's C++.
When I was taught C, we were taught to carefully separate things to avoid trouble. If you're building a linked-list library, you don't export the struct definition you use abstract data type. You prefix your function names to make a namespace. The Linux kernel uses vtables in C to implement polymorphism for various drivers (e.g. different file systems with the same interface). OOP makes these things explicit.
> Bad programmers worry about the code. Good programmers worry about data structures and their relationships.
The problem with dogmatic OOP is that it mixes data structures and code into one. This leads to hard to modify code, unexpected side effects, poor parallelism. Imperative or FP code does the minimum to define what the data should be shaped like and then has a bunch of functions that either modify it or do some IO with it.
That's a lot easier to trace through and reason about. That in turn leads to more malleable code, which lets you evolve it faster as your understanding of the problem domain evolves.