39 points · by jjuliano · 4y ago · 100 comments
It's probably best to start off a solution with plain old data structures, and plain old functions (ie. procedural style). Build with that until right abstractions or separations emerge.
This can only become a problem if you pay little to no attention to modularization, software architecture, and even encapsulation.
The responsibility of a paradigm and a language is to allow a developer to freely express their concepts. The programming paradigm is not to blame if the developer chooses to express poorly thought-out ideas that are riddled with detrimental consequences.
My point is it’s easier to modularize and encapsulate properly with procedural or functional paradigms because they don’t force you to do that work before you start solving problems. The dev flow is: solve problem, then modularize. With OOP, the flow is: modularize, then solve problem.
I’m simplifying and of course you can architect correctly upfront, it’s just harder because you’re doing speculative generalization (akin to premature optimization).
That's a poorly put-together red-herring. Brainfuck is not one of the leading production programming languages that has been used for decades to write all sorts of applications, from operating systems to web services and specially desktop applications, AAA games, and high-performance computing. Brainfuck is a gimmick "esoteric" programming language used as a challenge.
> My point is it’s easier to modularize and encapsulate properly with procedural or functional paradigms because they don’t force you to do that work before you start solving problems.
The thing is your point does not hold at all. It's trivial to modularize and encapsulate and even isolate components with C++. You only need to want to do it. If you don't want to modularize or encapsulate or isolate components then you get what you want. Don't blame the language for the software architecture you chose to adopt for your project.
I think that "freely" is what GP is complaining about; that OOP practices limit your freedom by encouraging early lock-in and making past decisions hard to revisit in light of new facts.
I'm not sure I entirely agree, mind you, but I do think you're in more agreement than disagreement.
You're giving the textbook example of problems created and solved by putting together a working software architecture. Books like Bob Martin's "Clean Architecture" refer explicitly to needs to accommodate changes to business and application layers, and the need to design components to accommodate changes, and the book is language-agnostic.
I've tried everything but my favored approach these days is just to stream of conscious psuedocode in main() to get the shape of what needs to happen, and then backfill until there's something working. Once I know what I want, only then do I break things up so that everything is in the right place. It seems to end well every time.
tl;dr: bottom-up, and top-down are too extreme!
You could apply TDD at this point. Doesn't have to be before you write a single line of code.
But eventually a junior developer realizes that a Triangle is an PolygonalOpenFrameMetallicPercussionInstrument and it now has 4kb of private state, 307 inherited member functions, and floods your console when its logged.
I love OOP, but caution is indeed warranted.
In fact "composition over inheritance" is a thing in the OOP world.
Inheritance x composition is orthogonal to OO.
Even though I once took a highschool C++ course long ago that talked about OOP and made us do a few things with it.....
I still have no idea what OOP really is, and why I need it. Unless I'm using it without knowing, I have a feeling I'm either dumber than I think or people have lost their minds. I can't tell.
The downside of being self-taught is well-known - you might end up convincing yourself that for loops don't work, strings with more than 10 characters are unreliable, numbers can only reliably be added using BigDecimal, etc.
The general answer seems to be that OOP starts really helping when many people/teams are involved.
Being self taught and a one person team I suppose hasn't forced me into it yet.
Then I read some articles. And I read forum posts. And I read comments. And I read OOP doesn't need this or that. I read multiple people define OOP in many different ways. Now I don't know how to define OOP.
I thought I could "know OOP if I saw it". And then I wrote code. I wrote in procedural languages. I wrote in functional languages. I wrote in declarative languages. I wrote in languages that like to blur the lines between them. And now I don't really know where the lines are. It all is just "programming".
Answering the question: "What is Object-Oriented Programming" used to be so easy. Now I don't know.
Doesn't mean that you're dumb or that other people lost their minds. My guess is you haven't given it a serious go, which is fine if you don't have a need for it. I personally find OOP fantastic for large codebases with multiple people working on them. Makes code a lot more maintainable and easier to reason about. The downside is that folks without a strong sense of architecture can get carried away with enterprise patterns and end up with abstractions on top of unnecessary abstractions. The basic tenets of OOP should be easy to understand if you just spend some time on it, though benefits can be hard to see if you haven't experienced procedural spaghetti code.
The whole abstract factory generator class iterator thing I see in other languages scares the bejeezus out of me.
My issue with `this` and things like it is that the first argument (the 'object') is usually the most important thing, and it's easier to read methods if they have a name.
Ok, you can call this deixis but do you need to? Clearly not.
I think it's fair to skip over a comment using terminology you find tiresome, be it because you aren't familiar, or you find it irritating for some reason, or for any reason; it's your time. I think it's unnecessary to insist we all use the same terminology, as that just limits what conversations can be had and who can have them. One of the things that makes HN feel magical is when people from a weird discipline jump in to give their two cents, and they add value to the community when they bring their terminology with them.
Terms?
"I think you meant 'words' which I also find annoying, but don't feel the need to dress that up in fancy words."
I don't feel the need to blunt precise terms down to imprecise terms.
If I did find "fancy terms" annoying, I wouldn't be proud of nor advertise that.
It's nonsense though because this/self is barely more than syntactic sugar for what C programmers do anyway - in fact languages with UFCS let you choose arbitrarily. Writing free functions with `this` as the first parameter doesn't really change anything.
Concurrency, syntactic sugar, object oriented, monotonic clock, these all sound like babble to someone uninitiated as well.
0. https://www.tech.dmu.ac.uk/~mjdean/notes/modules/education/E...
Of course this was inevitable given the place orientated von Neumann architecture (the tape, with its distinct locations). Much as OO practitioners like to think OO is special or deep in some sense, it is in fact just a conceptual hack to accommodate the inherent clumsiness of our particular adding machines, dressing their flaws in fancy clothes to hide our shame. If it wasn't for C pointers, programmers would think OO was some sort of nightmare fuel from another dimension.
Isolating some kinds of state in more manageable units can be very handy while remaining maintainable.
Even inheritance can be nice under the right circumstance.
Object oriented programming? An unmitigated disaster.
As for the handwaving about simulation & modelling and We Must Design The Matrix and all that nonsense... not applicable to most programming.
OOP helps encapsulate state to make it more manageable.
I am starting to reject OOP because I find working at reducing state is much more fruitful than encapsulating it.
NB: I am from California and I like object oriented programming.
Programming to an interface, composition, immutable classes and objects as fancy closures that can do more than one thing: Drake-yes-please.jpg
Inheritance for code sharing: Drake-no-thanks.jpg.
One thing I really miss from my Java days, and which I don’t really think has anything to do with OOP, is the concept of package visibility. Private data for the class itself. Protected data for inheritors if you dare have them. Public for anyone using your library. And package level visibility for me and my team to have special privileged access to these things in the same module, but which one outside of it is allowed to touch. It’s a great feature for large groups of programmers.
C++ has that in the form of internal linkage. You can have all the symbols you want that are only visible within your own translation unit.
Without OOP, we quickly get into codebases much like JavaScript where every new framework attempts to reinvent the same thing in even more contrived ways.
The only place where OOP style doesn't make sense is in stateless programs, which a lot of web backends are (but even there, it's often useful to hold connections and to create good interfaces).
Don't let your code in any language go down the JavaScript framework path.
Traits and type classes are a much better solution that offer far more flexibility, yet still allow the programmer their own balance of expressiveness and rigidity.
Of course data can have defined behavior. Don't try to marshall it into genetic lineages of parents and ancestors. That's an orthogonal and entirely made up problem.
Just pick a modular language like Modula-2, and add the capability to store module instances into variables, and extend them from there.
Polymorphism and dynamic dispatch at their root are plain function pointers, and anything else is just syntax sugar to avoid manually dealing with them.
Languages like Oberon or Lisp show how minimal the language has to have native support for OOP features, while still supporting most of its concepts.
The Actor model seems to fit well with OOP also.
0. http://lists.squeakfoundation.org/pipermail/squeak-dev/1998-...
Simula was the first language to have objects but Alan Kay's Smalltalk was what really caused it to take off and is what most OOP languages today were derived from. Today he feels he mis-named it and that he should have called it Message-Based Programming, which is what he feels should be the primary focus of languages with objects.
Most OOP languages today are not message-based and do not offer the full benefits of message-based programming. A few that do are Self, Ruby, and Erlang.
The reason OOP seems like a buzzword with no clear meaning is because there are so many languages that implement OOP only partially and not always the same parts.