Live data from Hacker News

The faster you unlearn OOP, the better for you and your software

dpc.pw

161–170 of 252 posts

Re: The faster you unlearn OOP, the better for you and your software

#161
OOP is successful because it's very good at modeling the world that surrounds us. As much as people like to hate on inheritance and recommending composition instead (a reasonable advice), the bottom line is that you will encounter the pitfalls of inheritance only on very rare occasions.

And inheritance enables so much flexibility and ease of maintenance that nothings comes close to it, not even FP.

Specialization and polymorphism(s) are the reasons why OOP is around, successful, and will remain so for a while. Anyone pretending it's bad or broken is just click baiting and does not understanding the fundamental issues.

Re: The faster you unlearn OOP, the better for you and your software

#162
post #93

Earlier quoted context omitted.

New to OOP programming. Could you explain what sort of arguments are presented against using OOP? I am genuinely curious.

I've been programming for 15 years (so I was around for the rise of OOP). There's nothing fundamentally wrong with OOP. I still write a lot of classes. But what I haven't written in a almost a decade: code with inheritance, encapsulation or polymorphism. Nothing has exploded. Also, objects are best when used to represent actual objects (i.e. collections of data rather than collections of functions). This is OK User u…

Excellent examples. Minimalist OOP can be beautiful, but over-abstraction e.g. `FactoryObserverFactory` is absolutely disastrous.

Re: The faster you unlearn OOP, the better for you and your software

#163
post #61
post #2

>The vast majority of essential code is not operating on just one object – it is actually implementing cross-cutting concerns. Example: when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a cl…

> when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a class Weapon involved? Do we pass it as an argument to isHitBy or does Player has a currentWeapon() getter? I don't see how this is a pr…

Good example, I think that's why people struggle with OOP, they do think that "programming objects correspond with physical objects". This is the same reason they struggle with storing states in databases because they try to map OOP to tables.

Re: The faster you unlearn OOP, the better for you and your software

#164
post #40

I've never liked classical OOP much, but multiple dispatch is a lovely paradigm. One doesn't define _classes_ per se, but rather just plain old boring structs. struct Player xp::Int end struct Monster hp::Int end function hit(p::Player, m::Monster) p.xp += 10 m.hp -= 20 end The nicest thing is how one one doesn't need inheritance to "add a method" to an object. One just defines my_function(s::String) to be whatever,…

> One doesn't define _classes_ per se, but rather just plain old boring structs. in which language are there differences between classes and structs ?

Above example is from julia. Julia structs have C layout and have no member functions.

The analog of "classes" in julia are "abstract types"; e.g. `AbstractArray{T}` is anything that implements the AbstractArray interface and holds objects of type T. Abstract types have no instances (all objects have a concrete type, that may be a subtype of an abstract type).

Binary compatibility between class and superclass is a cool feature in many OOP languages. This allows fast dynamic dispatch via vtable and lots of shared binary code for non-virtual methods (you can always memory pun from class to superclass). Julia does not support that feature: your different methods can share source code, but they get compiled separately. This is good for performance (more aggressive inlining) and bad for compiling small shared libraries (it is very painful to create julia apps/libs that work without invoking the JIT-compiler at runtime; can be done via custom sysimg). In some sense, julia is not very well suited to closed source business models.

Re: The faster you unlearn OOP, the better for you and your software

#165

Earlier quoted context omitted.

New to OOP programming. Could you explain what sort of arguments are presented against using OOP? I am genuinely curious.

The best arguments against OOP, as it is done in most languages today, are made by Alan Kay, the creator of Smalltalk and the term "object-oriented". Alan should have used the term "message passing" so people wouldn't miss this component of Smalltalk that made it so great. "I invented the term object-oriented, and I can tell you that C++ wasn't what I had in mind." - Alan Kay, Source: https://youtube.com/watch?v=oKg1…

It's not an argument against OOP, it's an attempt to redefine the term to be more in line with something that Kay invented.

And the world has moved on. OOP is not about message passing.

Re: The faster you unlearn OOP, the better for you and your software

#166
post #26

> The vast majority of essential code is not operating on just one object – it is actually implementing cross-cutting concerns. Example: when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a c…

Great point... but doesn't it continue to prove the author's point that this is needlessly complex? It strikes me as bad design if something as simple as an action (hit) now needs to become it's own class that is instantiated merely to execute a single function and then have to delete itself. That just feels like insane overhead/boilerplate, no? The argument here is that it's far better to have player and monster be…

> The argument here is that it's far better to have player and monster be simple data structures, and a single function hit(player, monster, weapon).

Naturally it's better to be simple if the logic involved actually is simple, but surely the point of the example is that game logic typically isn't. Hits in games don't just change a hit-point value, they tend to play animations, trigger events, work differently depending on this or that piece of global state, etc.

Re: The faster you unlearn OOP, the better for you and your software

#167
post #9

Earlier quoted context omitted.

> What probably is true however is that a lot of people should unlearn the OOP they learned in school. Can you provide references for proper OOP?

Smalltalk does "OOP" properly because it focuses on message passing, the real benefit of "OOP". Any OOPL that isn't based on message passing is degenerate.

Right. Because Objective C and Smalltalk are such resounding successes, uh?

Re: The faster you unlearn OOP, the better for you and your software

#168

Earlier quoted context omitted.

> It does read kind of nicely IMO... And this one line is why you're willing to setup all these crap boilerplate supporter classes and take a huge hit in runtime performance?

I'm pretty confused by how you perceive this. I don't see "crap boilerplate supporter classes" – I see objects that encapsulate events and actors for all the usual OOP reasons. I wonder if some of this disagreement is down to the way that different people abstract this problem in their heads.

   // player.hits(monster).with(weapon)

   add to class Player {
       // XXX: Bad coupling Player -> Monster
       // XXX: Bad coupling Player -> PlayerMonsterHit
       method hits(Monster monster) {
           return PlayerMonsterHit(player, monster)
       }
   }

   class PlayerMonsterHit {
       member Player player;
       member Monster monster;

       construct PlayerMonsterHit(Player player, Monster monster) {
           this.player = player;
           this.monster = monster;
       }

       method with(Weapon weapon) {
           doTheActualFrigginHit(this.player, this.monster, weapon);  // this line is all we REALLY need
       }
   }
I guess 15 lines (that do NOTHING) was not an overestimation.

Re: The faster you unlearn OOP, the better for you and your software

#169

Earlier quoted context omitted.

Refactor, with the right IDE this should take minutes. OOP witbout something like intellij or VS.NET is not fun.

What does OOP has anything to do with your IDE. I think you are referring to typings

OOP is often excruciatingly verbose and boilerplate which an IDE can help with.

You can do LISP in vi or emacs just fine, but for java some kind of IDE to handle the sheer data processing load of source editing is necessary.

Re: The faster you unlearn OOP, the better for you and your software

#170
post #26

> The vast majority of essential code is not operating on just one object – it is actually implementing cross-cutting concerns. Example: when class Player hits() a class Monster, where exactly do we modify data? Monster's hp has to decrease by Player's attackPower, Player's xps increase by Monster's level if Monster got killed. Does it happen in Player.hits(Monster m) or Monster.isHitBy(Player p). What if there's a c…

Eric Lippert discusses this here (2015):

https://ericlippert.com/2015/04/27/wizards-and-warriors-part...

Post reply on HN