321
OOP at home: (feddit.nu)
top 50 comments
sorted by: hot top controversial new old
[-] FreshLight@sh.itjust.works 34 points 1 day ago* (last edited 1 day ago)

In case anyone is wondering:

The artist is Princess Hinghoi.

[-] Not_mikey@lemmy.dbzer0.com 27 points 18 hours ago

Looks like some circular inheritance, that's going to cause some issues down stream.

[-] ICastFist@programming.dev 1 points 1 hour ago

Trust the vibe, bro, if it was wrong it wouldn't vibe like that bro

[-] FEIN@lemmy.world 20 points 1 day ago

sometimes i wonder what dignity means to certain artists

[-] FreshLight@sh.itjust.works 16 points 1 day ago* (last edited 1 day ago)

My guess is that money overwrites dignity in some cases.

[-] ICastFist@programming.dev 1 points 1 hour ago

Implying that's not their kink in the first place

[-] Gonzako@lemmy.world 10 points 1 day ago
[-] FreshLight@sh.itjust.works 11 points 1 day ago
[-] Gonzako@lemmy.world 8 points 22 hours ago

I'm taking the blonde with the succubus tattoo

[-] DragonTypeWyvern@midwest.social 3 points 16 hours ago* (last edited 16 hours ago)

Everyone that knows what that is is a pervert

[-] Gonzako@lemmy.world 10 points 16 hours ago* (last edited 16 hours ago)
[-] ZILtoid1991@lemmy.world 13 points 1 day ago

Entity Component System all the things!

I might write an XML ECS parser, as a joke. Practical? No! Probably even slower than the XML DOM? Yes! Funny? Yes!

[-] tiramichu@sh.itjust.works 168 points 2 days ago

I'll say this now.

Inheritance is the most misused capability of OOP which programmers think makes their code look smart, but most of the time just makes a giant fucking mess.

[-] Wirlocke@lemmy.blahaj.zone 5 points 16 hours ago* (last edited 16 hours ago)

I've moved away from Classes in general unless it truly makes code more streamlined. The main language I was taught in highschool was Java and it's just so liberating not needing to turn everything into an object.

But recently I've used a Class specifically for Inheritance. I'm making an extension to Pytorch and almost everything in Pytorch uses Tensors as a medium. I made a new kind of tensor that inherits the Tensor class to add specific restrictions on how it behaves. Because of this, this new tensor object can be used with any of the preexisting pytorch functions while also validating the results, reverting to a Tensor if it becomes invalid.

Even in this situation though, all my programming logic rests in it's own static functions, and the class contains functions that call the static version. The only actual logic the inherited object handles is validating the data.

Because of this, I feel like inheritance is most useful when you're inheriting someone else's code to make it compatible with their library. I don't think I'll ever inherit my own objects because that's how you end up with Java.

[-] mesamunefire@piefed.social 45 points 1 day ago

Its the best/worst thing about OOP no matter what language.

We had a rule at work that if you are 3 levels or more down an inheritance tree, then you are too far. The cognitive load is just too much, plus everything stops making sense.

One level can be great (MVC all have great conventions, MCP as well). Two can be pushing it (Strategy pattern when you have physical devices and cant be connected all the time, Certain kinds of business logic that repeat hundreds of times, etc...) But even there you are kinda pushing it.

I need code that I can look at a month from now and know WTF is happening. And sometimes its better to have less DRY and more comprehension. Or maybe im just a forever mediocre dev and dont see the "light". I dunno.

[-] sip@programming.dev 3 points 1 day ago

composition can help with all of that. factories, strategies, injections are all composition patterns that work fine.

business logic that repeats? extract it to it's own thing (class, function, etc) and pass it as a param to the supposed childs.

mvc? controllers don't need to extend anything, just have them accept the framework through the constructor and request and response as args. views? same. models? perhaps only if doing an active record, but a repo pattern with plain objects is a good pattern too.

I never seen a clean inheritance implementation for a decently sized problem. it mostly works for tiny ones.

[-] firelizzard@programming.dev 6 points 1 day ago

When I first started using Go I bemoaned the lack of true inheritance and classes. Now I love it.

[-] Not_mikey@lemmy.dbzer0.com 1 points 18 hours ago

I thought it didn't have classes in name only, isn't a struct with methods basically a class?

[-] firelizzard@programming.dev 3 points 14 hours ago

Depends on what you mean by “basically a class”. If you mean inheritance, overriding, and more generally class/inheritance based polymorphism, no, it does not. Those require dynamic dispatch, which Go does not have (for concrete types, which is what we’re talking about here).

[-] lime@feddit.nu 3 points 17 hours ago

a class can be inherited from, a struct can not.

[-] tiramichu@sh.itjust.works 19 points 1 day ago

This is exactly how I feel too. A little bit of repetition is totally worth it, versus having inappropriate coupling, or code that jumps in and out of parent/child classes everywhere so you can hardly keep it in your head what's going on.

I freely accept that I AM a mediocre dev, but if that lends me to prefer code that is comprehensible and maintainable then I think being mediocre is doing my team a favour, honestly.

load more comments (5 replies)
load more comments (8 replies)
[-] red_tomato@lemmy.world 101 points 2 days ago* (last edited 2 days ago)

Hold on, I’m in the middle of drawing an inheritance graph so I know how Dog is related to AircraftCarrier.

[-] blackn1ght@feddit.uk 76 points 2 days ago* (last edited 2 days ago)
public interface ICanTravelThroughTheAir
{

}

public class Flea : ICanTravelThroughTheAir
{

}

public class AircraftCarrier
{
  private readonly List<ICanTravelThroughTheAir> _aircraft = new();

  public void AddAircraft(ICanTravelThroughTheAir flyingThing)
  {
    _aircraft.Add(flyingThing);
  }
}

public class Dog : AircraftCarrier
{
    public void Woof()
    {
        Console.WriteLine("Bitch I'm an aircraft carrier!");
    }
}

public static class Program
{
  public int Main(string[] args)
  {
    var dog = new Dog();
    
    for (var i = 0; i < 10000; i++)
    {
        dog.AddAircraft(new Flea());
    }

    dog.Woof();
  }
}
[-] ZILtoid1991@lemmy.world 3 points 1 day ago* (last edited 22 hours ago)

Now someone needs to make it an entity component system!

Attempt 1:

public struct Entity {
  bool isDog : 1;
  bool isAircraftCarrier : 1;
  bool isFlea : 1;
  bool canFlyInAir : 1;
  ubyte opt_numOfAircrafts : 4;
  int entityID;
  int opt_parentID;
  static Entity createDog(int entityID) {
    Entity result;
    result.isDog = true;
    result.entityID = entityID;
    return result;
  }
  static Entity createFlea(int entityID) {
    Entity result;
    result.isFlea = true;
    result.canFlyInAir = true;
    result.entityID = entityID;
    return result;
  }
  void addAirCraft(ref Entity aircraft) {
    if (aircraft.canFlyInAir && this.isAircraftCarrier) {
      aircraft.opt_parentID = this.entityID;
      this.opt_numOfAircrafts++;
    }
  }
  void woof() {
    if (isDog) {
      if (isAircraftCarrier) writeln("I'm a motherfucking aircraft carrier");
      else writeln("Woof!");
    }
  }
}

void main() {
  Entity dog = Entity.createDog(1);
  Entity flea = Entity.createFlea(2);
  dog.woof();
  dog.isAircraftCarrier = true;
  dog.addAirCraft(flea);
  dog.woof();
}
[-] a_jackal@pawb.social 4 points 1 day ago

You forgot the component part.

[-] jenesaisquoi@feddit.org 61 points 2 days ago

Needs more AbstractDefaultProxyBeanFactoryFactories

load more comments (2 replies)
load more comments (1 replies)
load more comments (6 replies)
[-] kibiz0r@midwest.social 48 points 1 day ago

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.

load more comments (2 replies)
[-] RustyNova@lemmy.world 60 points 2 days ago* (last edited 2 days ago)

I LOVE TRAITS. YOU'LL HAVE TO TAKE THEM FROM MY COLD DEAD HANDS

[Insert SpongeBob screaming meme]

load more comments (3 replies)
[-] tatterdemalion@programming.dev 77 points 2 days ago

In over ten years of professional programming, I have never used inheritance without regretting it.

[-] kalpol@lemmy.ca 3 points 14 hours ago

This applies to firewall rules too

[-] wewbull@feddit.uk 2 points 1 day ago

Do you include "traits" and "interfaces" under the title "inheritance"?

[-] tatterdemalion@programming.dev 1 points 17 hours ago

No because those are different things.

When it's the right tool, it's incredibly useful. When it's the wrong tool, and it often is, it racks up tech debt at an incredible rate.

load more comments (8 replies)
[-] NigelFrobisher@aussie.zone 15 points 1 day ago* (last edited 1 day ago)

Examples of inheritance hierarchies are always totally useless shit like this - what if a cow is an animal; What if a cow is a mammal, all mammals are animals and all mammals have a lactate() method?

[-] jason@discuss.online 11 points 1 day ago

Yeah... Wheres the AbstactAnimalFactoryManager?

I always knew Mondrian was painting cow production machines.

[-] ulterno@programming.dev 10 points 1 day ago

Because any real life use that might come to mind would probably be related to some NDA protected database in a company.
And it is otherwise hard to think of anything at the spot, so just go with what the first example on the web-search came up with.

[-] jenesaisquoi@feddit.org 62 points 2 days ago

Composition over inheritance every day, all day

load more comments
view more: next ›
this post was submitted on 10 Feb 2026
321 points (95.7% liked)

Programmer Humor

29672 readers
1260 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 2 years ago
MODERATORS