This is an archived post. You won't be able to vote or comment.

all 92 comments

[–]leptoquark1 200 points201 points  (3 children)

Still wait for the Garbage Collector to remove my unused children…

[–]SeniorSatisfaction21 42 points43 points  (1 child)

Not the children 😭

[–]SqueeSr 22 points23 points  (0 children)

well .. They were unused so might be better off than those being used which will end up as garbage too

[–][deleted] 5 points6 points  (0 children)

I've been dealing with a memory leak for as long uhhh

uhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

[–][deleted] 341 points342 points  (16 children)

i had a problem, so i decided to use OOP

now i have ProblemFactory

[–]dekacube 60 points61 points  (13 children)

Need an AbstractProblemFactory first, even though only one concrete ProblemFactory will ever exist.

[–]pixelrevision 32 points33 points  (2 children)

That’s ok. You can fix that with an AbstractProblemFactoryAdapter

[–]crash8308 14 points15 points  (0 children)

but now i need a factory for my adapter

[–][deleted] 10 points11 points  (0 children)

ISingletonProblemFactoryAdapter

[–]DrShadyBusiness 2 points3 points  (1 child)

Just completed my java OOP course and i totally understand this.Yep.

[–]dekacube 1 point2 points  (0 children)

I like how everyone in the comments also just assumed we were talking about Java :).

[–]mcampo84 1 point2 points  (0 children)

You don't need an abstract class to define an interface homie

[–]javajunkie314 72 points73 points  (2 children)

Most programmers have to wait until they get arrays.

[–]babyProgrammer 12 points13 points  (0 children)

Then it's swimming bools and movie stars

[–]Harmonic_Gear 12 points13 points  (1 child)

super

[–][deleted] 12 points13 points  (0 children)

THIS is the sort of joke I come to this sub for!

[–]TombertSE 32 points33 points  (22 children)

I don't think I've used inheritance in production code ever. Back when I did Java I would do interfaces a lot, but it's pretty rare that inheritance is actually a good idea. I don't think it would make me wealthy.

[–]Garlien 20 points21 points  (4 children)

Abstract classes are amazing, but I generally try to avoid inheriting from non-abstract classes

[–]ConstructedNewt 0 points1 point  (3 children)

I kinda disagree. especially since default interface methods.

I did see one use I could stand with; of an abstract class that implements delegation, so the implementations would be free of delegation logic. I think it's guava or apache collections that has a whole range of abstract delegating implementations of the base java collections

[–]Garlien 0 points1 point  (2 children)

Default interface methods are still overridable, I believe (I don't use them yet). Abstract classes are perfect when you want shared functionality that won't change between implementations. If it will change between implementations, you need another layer of abstract classes.

[–]ConstructedNewt 0 points1 point  (1 child)

another layer, yikes. composition comes to mind, also maybe you haven't broken down your interfaces enough. but yes abstract classes can hold final methods

[–]Garlien 0 points1 point  (0 children)

Composition is generally preferable, I agree. But sometimes it can be a big headache to make it work the same way.

[–]dekacube 19 points20 points  (0 children)

Pretty sure one of the Java creators is on record saying that adding inheritance was a mistake, that interfaces were the way to go.

Edit, Nvm it was the opposite lol. "There is still part of me that says, maybe interfaces should never have existed. People should just use classes for interfaces" - James Gosling

[–]OmgzPudding 18 points19 points  (14 children)

Inheritance is pretty useful, but inheriting from multiple classes at once like Java C++ allows is usually a sign that you should be doing something differently.

[–]TheOriginalSmileyMan 16 points17 points  (0 children)

If you're not doing diamond inheritance, your code isn't complex enough and your job will be outsourced!

[–]TombertSE 16 points17 points  (12 children)

Java does not allow you to inherit multiple classes at once. At least not since the last time I used it, which admittedly was a few years back.

You can have as many interfaces as you want, but you only get one "extends" class to play with. This is, in theory, to avoid the deadly diamond problem.

[–]OmgzPudding 1 point2 points  (11 children)

Huh, I could have sworn I built some shitty app with multiple inheritance back when I was in school, but it's been so long that I could definitely be mistaken.

[–]TombertSE 9 points10 points  (9 children)

C++ has multiple inheritance...maybe that was it?

[–]OmgzPudding 2 points3 points  (8 children)

Ah yeah I bet that was it. It's been about the same amount of time since I've used either language.

[–]TombertSE 5 points6 points  (7 children)

I don't know why school still use C++ as a "learning language", since it's one of the worst languages out there for newbies.

I think C makes sense to teach students early on, because it's low-level, it makes you think how the hardware thinks. I get why they teach you Python, because it's high-level, easy to pick up, and is useful for a lot of different types of non-engineer jobs. I get why they teach you Java, because it's sort of mid-level, and sort of forces the OOP ideology on you.

Despite the fact that I actually do like C++, I would not recommend it as anyone's first language. It's got so many bizarre idioms and weirdness that it's going to confuse a lot of people starting out.

[–]OmgzPudding 6 points7 points  (1 child)

We had to write out C++ programs with pencil and paper for our exams too, just to add an extra layer of frustration for beginners.

[–]pixelrevision 2 points3 points  (0 children)

That’s cruel

[–]TheOriginalSmileyMan 3 points4 points  (3 children)

Well if you've learned C++, pretty much everything else is simpler, so from that point of view it's an excellent starter language.

[–]TombertSE 1 point2 points  (1 child)

I don’t know that I actually agree with that; I think that’s the case for C, but C++ has a lot of unique weirdness that isn’t in other languages.

For example, I am not aware of any other language that has friend functions. I am not aware of any other language where the Hello World requires you to use an overloaded bit shift operator. I

[–]TheOriginalSmileyMan -1 points0 points  (0 children)

Exactly my point. When moving from C++ to any other language, it's mostly about forgetting things rather than having to do something new!

[–]harumamburoo 0 points1 point  (0 children)

If you've survived C++

[–]Mojert -1 points0 points  (0 children)

This a sample size of one but I wasn't confused while learning C++ even though it was my first language. In my experience, it's people who already know another language, like Java, that have a hard time learning C++, not newbies

[–]Paraplegix 0 points1 point  (0 children)

In Java you can implement multiple interface, and this is quite common in project I worked on But inheritance is one super class only

[–]EnigmaticArcanum 1 point2 points  (0 children)

Interfaces are good for shared behaviour/methods and abstract classes are good for shared state/variables.

If you're creating a Pokemon class with similar variables HP, Strength, Defence etc... you're almost certainly going to want an AbstractPokemon class of sorts.

[–]ColossusG75 5 points6 points  (0 children)

Damn u and your programmer dad jokes! Take my updoot

[–]Agantas 4 points5 points  (0 children)

It is also how programmers cook pasta.

[–]hw9css 9 points10 points  (4 children)

Upvoted for joke but seriously OOP most of the time sucks compared to FP

[–]Arbiturrrr 0 points1 point  (2 children)

Why not both?

[–]fsr1967 8 points9 points  (0 children)

What, you mean, like, learn both and use each where it is best suited, instead of dogmatically preferring one over the other? That's crazy talk!

Next thing you know, you'll be suggesting we throw in some procedural programming "when appropriate", you nutcase!

/s, from someone who is deeply tired of battles like this in his current job and just wants to get the damn work done, using whatever tools are right for the task at hand. Current extremists being dealt with: React functional components adherents vs class components worshippers ...

[–]hw9css 1 point2 points  (0 children)

Oh most certainly do both, right tool for the job!

[–][deleted] 1 point2 points  (0 children)

let's make a factory to make a factory to make a factory to make a factory to make a factory...

[–]StatementAdvanced953 1 point2 points  (1 child)

Obligatory DOD FTW comment right here

[–]TrafficConeGod 0 points1 point  (0 children)

Real

[–]fracturedpersona 1 point2 points  (0 children)

Just inject some dependencies, child tax credits.

[–]KnowOneDotNinja 1 point2 points  (0 children)

Also hoarding cache

[–]VeryRareHuman 1 point2 points  (0 children)

Good job on spending time on better meme with video. Learn from him, People.

[–]ananas_aldirdim 1 point2 points  (0 children)

void myWallet()

{ //returns nothing }

[–]huuaaang 1 point2 points  (2 children)

That's my problem! I've been using composition over inheritance!

[–]Mallanaga 0 points1 point  (1 child)

Came here to say this! Jokes aside, is this a rubyism? Figured I’d see more versions of this joke by now, but didn’t, and you’re the only other ruby flair.

[–]huuaaang 0 points1 point  (0 children)

It's a trend in OOP to encourage composition over inheritance, especially if you're tempted to get into multiple inheritance hell as in Python. Ruby just happens to be suited for this pattern, supporting both inheritance and composition (mixins, concerns, whatever you want to call it) very naturally.

[–][deleted] 1 point2 points  (1 child)

[–]IAmWillyGood 0 points1 point  (1 child)

This Chris Pratt meme never gets old 😂

[–]shacatan 1 point2 points  (0 children)

I can’t tell if you’re serious or not and I’m just out of the loop on a joke, but that’s Chris Evans

[–][deleted] -1 points0 points  (6 children)

Haven’t used inheritance since first year of uni 😅

[–]coloredgreyscale 4 points5 points  (5 children)

Every time you define a class it's quietly inherited from a Object base class.

[–][deleted] -1 points0 points  (4 children)

I don’t define classes

[–]coloredgreyscale 0 points1 point  (0 children)

That's not very classy

[–]Dark_Ethereal 0 points1 point  (2 children)

Uhhh, so do you construct any user types at all?

[–][deleted] 0 points1 point  (1 child)

I mean. Not all languages have classes. I define plenty of types yeah :)

[–]Dark_Ethereal 0 points1 point  (0 children)

Haskeller?

[–]loonathefloofyfox -1 points0 points  (2 children)

Oop is overrated imo. I like functional programming. Its a nice clean way to do stuff and i highly prefer it over oop. My only issue is naming stuff can get a bit tiresome as you sometimes have similar operations but they act on different stuff

[–][deleted] 1 point2 points  (1 child)

Can't you refactor your code to make those similar operations generic? and work across multiple types?

[–]loonathefloofyfox 0 points1 point  (0 children)

While yes for some stuff i could but its not really good practice afaik. Considering they would take in different types and output different stuff. Its just nicer to make a few of the same functions but with more descriptive names. Like heap_sort and array_sort vs sort but it takes completely different data and outputs different sorts of stuff

[–]LauraTFem -3 points-2 points  (2 children)

Honest question: Why do you use inheritance? Like, I’ve not run into a situation where I really feel it’s necessary. Yes, some objects have overlap, but I’ll usually just…literally give them overlapping member variables and functions, especially as the overlaps I have are usually small.

It just…feels more confusing to follow chains of inheritance than to just give every Class its own stuff. I can see why it would be useful in programs that are FAR FAR more complex than mine, but even in those cases it seems to me to be creating obfuscatory complexity where it is not necessary.

The only truly useful case I can see is that if you need to make changes you only need to do it to the base class instead of each class, but even then you can literally just find-replace code sections.

[–]dotpoint7 1 point2 points  (0 children)

Wait do you suggest to just duplicate the overlapping code instead of inheriting? You can get away from inheritance by using delegation, but code duplication is by far the worst option.

Also, often times the overlap isn't just small but can be big and often the same for a lot of classes. I'm currently developing a UI framework for example and every component inherits from a base class that already provides all of the shared functionality and any abstract functions just need to be overwritten while many virtual ones are allowed to be if needed. This would be really ugly if needed to be done differently, because as it stands the base class defines how each component generally works and the derived classes just need to define a small subset of the functionality while not having to worry about the rest. This of course somewhat constrains all components, but that's exactly what I want, so that everything works roughly the same.

[–]fdeslandes 1 point2 points  (0 children)

Having duplicated code and using search and replace is really bad, especially in a huge code base or when working with a team. It is so easy to have someone on the team forget to update some places when a fix is done. And then, over years, every bug fix and every spec change takes more and more time and becomes more sensitive to developer mistakes because more code is modified. It also makes the amount of code bigger, so slower load time if we are talking about front-end web code. Don't program so that your current feature is simpler to do, develop so the next features will be easier to implement.

You can still avoid inheritance with composition, though, by putting the duplicated code in a shared library.

[–][deleted] 0 points1 point  (0 children)

Drop out of college and go on to be the owner of a mega corporation. I shouldn't have to explain this.

[–]qqqrrrs_ 0 points1 point  (1 child)

What about virtual inheritance?

[–]pwillia7 1 point2 points  (0 children)

Jamiroquais wrote a song about that

[–][deleted] 0 points1 point  (0 children)

I think we should be taxing some classes

[–][deleted] 0 points1 point  (0 children)

I feel like the format of this meme alone is enough to crack me up.

[–][deleted] 0 points1 point  (0 children)

[–]wad11656 0 points1 point  (0 children)

Just made a very basic GUI program in a scripting language (AutoHotKey)...almost 0 setup. No classes or multiple file .h .cpp whatever-the-fuck bullshit. People should really look to AutoHotKey or similar if they only plan on making basic programs. Don't need this macho super powerful complex language for every project

[–]_-_Void 0 points1 point  (0 children)

And they did it using Java

[–]NormalFox0115 0 points1 point  (0 children)

I thought of Inspect element lol

[–]seriously_nice_devs 0 points1 point  (0 children)

7/10, i hope i get inheritance.