this post was submitted on 30 May 2024
385 points (94.5% liked)

Programmer Humor

32371 readers
753 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
top 50 comments
sorted by: hot top controversial new old
[–] eestileib@sh.itjust.works 70 points 5 months ago (3 children)

Objects are fine.

OOP sucks.

[–] palordrolap@kbin.social 30 points 5 months ago (3 children)

This has bell curve meme vibes. I'm just not sure what the middle guy would be saying.

[–] MajorHavoc@programming.dev 37 points 5 months ago (1 children)

He died of XML factory injection pattern exposure.

[–] xmunk@sh.itjust.works 4 points 5 months ago

If only he had a briefcase of XSLTs to make sure the XML was safe first.

[–] dabu@lemmy.world 21 points 5 months ago

It would say Prototype­Filter­Stub­Facade­Bridge­Decorator­Task­Request­Map­Event­Exporter­Info­Model­Request­Iterator

[–] marcos@lemmy.world 7 points 5 months ago (1 children)

I’m just not sure what the middle guy would be saying

"I hate inheritance! I hate inheritance! I hate inheritance! I hate inheritance!"

But well, inheritance goes brrrrrr.

[–] erp@lemmy.world 4 points 5 months ago

We all get disappointed when we don't inherit anything useful...just a garage full of confusion

load more comments (2 replies)
[–] DriftinGrifter@lemmy.blahaj.zone 59 points 5 months ago (3 children)

you can write oop without inhetitance

[–] parlaptie@feddit.de 10 points 5 months ago

There's the camp of those who say that inheritance is synonymous with OOP. I'm not in that camp, but I'd like to see you duke it out with them.

load more comments (2 replies)
[–] MajorHavoc@programming.dev 50 points 5 months ago (2 children)

Interfaces are great.

Inheritance is often a sign that the previous developer didn't understand interfaces.

[–] scrubbles@poptalk.scrubbles.tech 23 points 5 months ago (1 children)

Broad generic claims like that tell me more

[–] MajorHavoc@programming.dev 24 points 5 months ago

Yep. I'm old, cranky, and prone to broad statements to get reactions.

That said, for any of you all that love inheritance, I'm judging you so hard. So hard. Very judged. I probably hate your code, and your friends' code, and your last teacher's code. Especially your last teacher's code.

[–] deathmetal27@lemmy.world 19 points 5 months ago

Prefer composition over inheritance. Though that doesn't mean inheritance has no place in programming.

[–] cerement@slrpnk.net 45 points 5 months ago (6 children)

Why Isn’t Functional Programming the Norm? – Richard Feldman

  • objects and methods are just structs and procedures
  • encapsulation is just modular programming
load more comments (6 replies)
[–] kibiz0r@midwest.social 39 points 5 months ago (1 children)

The venerable master Qc Na was walking with his student, Anton. Hoping to prompt the master into a discussion, Anton said "Master, I have heard that objects are a very good thing - is this true?" Qc Na looked pityingly at his student and replied, "Foolish pupil - objects are merely a poor man's closures."

Chastised, Anton took his leave from his master and returned to his cell, intent on studying closures. He carefully read the entire "Lambda: The Ultimate..." series of papers and its cousins, and implemented a small Scheme interpreter with a closure-based object system. He learned much, and looked forward to informing his master of his progress.

On his next walk with Qc Na, Anton attempted to impress his master by saying "Master, I have diligently studied the matter, and now understand that objects are truly a poor man's closures." Qc Na responded by hitting Anton with his stick, saying "When will you learn? Closures are a poor man's object." At that moment, Anton became enlightened.

[–] CapeWearingAeroplane@sopuli.xyz 13 points 5 months ago (10 children)

Can someone please enlighten me on what makes inheritance, polymorphism, an operator overloading so bad? I use the all regularly, and have yet to experience the foot cannons I have heard so much about.

[–] Heavybell@lemmy.world 11 points 5 months ago (1 children)

If the only tool you have is a hammer, everything looks like a nail.

That's the only thing I can think to answer your question. There are some problems that are best solved with other tools, like text parsing for example you might want to call out to some code written in a functional language.

[–] CapeWearingAeroplane@sopuli.xyz 4 points 5 months ago

Oh, thanks then! I've heard people shred on OOP regularly, saying that it's full of foot-canons, and while I've never understood where they're coming from, I definitely agree that there are tasks that are best solved with a functional approach.

[–] modeler@lemmy.world 10 points 5 months ago (2 children)

I don't think that the anti-oop collective is attacking polymorphism or overloading - both are important in functional programming. And let's add encapsulation and implementation hiding to this list.

The argument is that OOP makes the wrong abstractions. Inheritance (as OOP models it) is quite rare on business entities. The other major example cited is that an algorithm written in the OOP style ends up distributing its code across the different classes, and therefore

  1. It is difficult to understand: the developer has to open two, three or more different classes to view the whole algorithm
  2. It is inefficient: because the algorithm is distributed over many classes and instances, as the algorithm runs, there are a lot of unnecessary calls (eg one method on one instance has to iterate over many instances of its children, and each child has to iterate over its children) and data has to pass through these function calls.

Instead of this, the functional programmer says, you should write the algorithm as a function (or several functions) in one place, so it's the function that walks the object structure. The navigation is done using tools like apply or map rather than a loop in a method on the parent instance.

A key insight in this approach is that the way an algorithm walks the data structure is the responsibility of the algorithm rather than a responsibility that is shared across many classes and subclasses.

In general, I think this is a valid point - when you are writing algorithms over the whole dataset. OOP does have some counterpoints encapsulating behaviour on just that object for example validating the object's private members, or data processing for that object and its immediate children or peers.

load more comments (2 replies)
[–] ScreaminOctopus@sh.itjust.works 7 points 5 months ago

I don't really think it's any of those things in particular. I think the problem is there are quite a few programmers who use OOP, especially in Java circles, who think they're writing good code because they can name all the design patterns they're using. It turns out patterns like Factory, Model View Controller, Dependency Injection etc., are actually really niche, rarely useful, and generally overcomplicate an application, but there is a subset of programmers who shoehorn them everywhere. I'd expect the same would be said about functional programming if it were the dominant paradigm, but barely anyone writes large applications in functional languages and thus sane programmers don't usually come in contact with design pattern fetishists in that space.

[–] englislanguage@lemmy.sdf.org 6 points 5 months ago (1 children)

Operator overloading is adding complexity, making code subtly harder to read. The most important lesson for code is: It should primarily be written to be easy to read by humans because if code is not trash, it will be read way more often than written.

[–] CapeWearingAeroplane@sopuli.xyz 7 points 5 months ago (1 children)

I would argue that there are very definitely cases where operator overloading can make code more clear: Specifically when you are working with some custom data type for which different mathematical operations are well defined.

load more comments (1 replies)
[–] pennomi@lemmy.world 4 points 5 months ago

Nothing, just use a good tool for the job, whatever that job requires.

load more comments (5 replies)
[–] anyhow2503@lemmy.world 35 points 5 months ago (5 children)

I haven't used TypeScript in a classically OOP way and it never felt like I was being urged to do so either.

[–] Armand1@lemmy.world 11 points 5 months ago* (last edited 5 months ago) (6 children)

I've worked on projects with 10 000+ lines of typescript and maybe 3 classes total.

load more comments (6 replies)
load more comments (4 replies)
[–] Asudox@lemmy.world 30 points 5 months ago (7 children)

OOP is nice. Why do people hate it?

[–] Blemgo@lemmy.world 40 points 5 months ago (3 children)

I think the main problem is that people try to shoehorn OOP mechanics into everything, leading to code that is hard to understand. Not to mention that this is basically encouraged by companies as well, to look "futuristic". A great example of this approach going horribly wrong is FizzBuzz Enterprise Edition.

OOP can be great to abstract complex concepts into a more human readable format, especially when it comes to states. But overall it should be used rarely, as it creates a giant code overhead, and only as far as actually needed.

[–] RandomException@sopuli.xyz 6 points 5 months ago

Oh no, the FizzBuzz EE has evolved since I've last viewed it! 😱 Is it bad if it actually reminds me of my current work project's backend (that I haven't written) a bit?

[–] IsoSpandy@lemm.ee 5 points 5 months ago

Man thanks for sharing the fizz buzz link.

[–] Ephera@lemmy.ml 19 points 5 months ago

Because of inheritance.

[–] Valmond@lemmy.world 12 points 5 months ago (1 children)

People (sometimes) use it far too much and in wrong ways.

Like inherit when you could just instantiate, or use a template.

Or when "everything should be a class" was also a bummer (inhetit "run()"), like I'd instantiate "main" twice (cool if it had worked I guess).

Or old code written by "wizards" where they cast cast cast instances onto other classes to use specific behaviour in crazily dangerous manners. And you're the one to "fix it" because it doesn't work well...

Otherwise OOP is good.

[–] zalgotext@sh.itjust.works 13 points 5 months ago

Just like any software design principle, it's understood at a surface level by tons of bad developers who then try and solve every problem with that one principle. Then slightly better developers come along and say "ugh this is gross, OOP is bad!" And then they avoid the principle at all costs and tell everyone how bad it is at every opportunity.

[–] KingThrillgore@lemmy.ml 11 points 5 months ago

Multiple inheritance

[–] PeriodicallyPedantic@lemmy.ca 11 points 5 months ago

There are common traps and employer don't spend money/time to train their devs to avoid them.

SOLID principles are pretty decent but a surprising number of people don't do any of them

load more comments (2 replies)
[–] Artyom@lemm.ee 13 points 5 months ago (3 children)

Inheritance makes complicated objects that would otherwise be impossible possible, but it only works if you know those objects really well. The problem is people write ridiculously complicated mystery objects in libraries and no one knows what's going on anymore.

load more comments (3 replies)
[–] arisunz@lemmy.blahaj.zone 12 points 5 months ago

Just give me interfaces and composition tbh

[–] olafurp@lemmy.world 10 points 5 months ago (2 children)

Using classes is nice tbh. Using inheritance usually isn't. Inheriting from inherited class should be forbidden.

load more comments (2 replies)
[–] jsomae@lemmy.ml 10 points 5 months ago (1 children)
[–] Alawami@lemmy.ml 5 points 5 months ago (2 children)
load more comments (2 replies)
[–] someacnt_@lemmy.world 7 points 5 months ago

Is OCaml going mainstream, hm

[–] xmunk@sh.itjust.works 6 points 5 months ago (1 children)

Uh... from Caml? Because OCaml's object support is the least surprising part of the language.

load more comments (1 replies)
[–] max@lemmy.blahaj.zone 5 points 5 months ago
[–] HStone32@lemmy.world 4 points 5 months ago (1 children)

I used to think I was just a fanboy. But as time went on and I gained more and more experiences, I've only become all the more sure that ANSI C is the only language I ever want to write anything in.

[–] jeremias@social.jears.at 6 points 5 months ago

I was the same, but I recently gave zig a try, it's lovely to write.

Managed to segfault the compiler though, so maybe not quite ready yet.

[–] JoYo@lemmy.ml 4 points 5 months ago (3 children)

C++ classes are fairly optional but if you're already using cpp then it likely wasn't your choice and neither will the choice of OOP.

load more comments (3 replies)
load more comments
view more: next ›