Beehaw
  • Communities
  • Create Post
  • search
    Search
  • Login
  • Sign Up
freddo ( freddo@feddit.nu )  to Programmer Humor@programming.devEnglish · 9 months ago

OOP at home:

feddit.nu

message-square
25
link
fedilink
197

OOP at home:

feddit.nu

freddo ( freddo@feddit.nu )  to Programmer Humor@programming.devEnglish · 9 months ago
message-square
25
link
fedilink
alert-triangle
You must log in or # to comment.
  • tatterdemalion ( tatterdemalion@programming.dev ) 
    link
    fedilink
    arrow-up
    53
    ·
    9 months ago

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

    • AudaciousArmadillo ( AudaciousArmadillo@piefed.blahaj.zone ) 
      link
      fedilink
      English
      arrow-up
      14
      ·
      9 months ago

      It works great for technical constructs. E.g. A Button is a UI element. But for anything business logic related, yeah it’ll suck.

    • Valmond ( Valmond@lemmy.dbzer0.com ) 
      link
      fedilink
      arrow-up
      3
      ·
      9 months ago

      That’s wild. What did you use it for?

      • tatterdemalion ( tatterdemalion@programming.dev ) 
        link
        fedilink
        arrow-up
        2
        ·
        9 months ago

        Some legacy Python code that already used inheritance. I had to extend it, and it was pretty infeasible to refactor the whole thing to not use inheritance. Not sure if I technically regretted that decision, but it was definitely painful, since Python inheritance makes it really hard to follow program control flow.

        • Valmond ( Valmond@lemmy.dbzer0.com ) 
          link
          fedilink
          arrow-up
          1
          ·
          9 months ago

          Non typed inheritance, what could go wrong eh. You can just ‘add’ a function to a class dynamically in python, that is so bad.

          Done any C++ classes & inheritance?

          • tatterdemalion ( tatterdemalion@programming.dev ) 
            link
            fedilink
            arrow-up
            1
            ·
            9 months ago

            It was actually typed. Python had type annotations at the time.

            I only wrote C++ very early in my career so I don’t remember much, but I’m sure I at least tried some inheritance in toy games I would write. All of that code was trash though by my standards today.

            • Valmond ( Valmond@lemmy.dbzer0.com ) 
              link
              fedilink
              arrow-up
              1
              ·
              9 months ago

              Still does, but you don’t have to.

              So you haven’t had much experience with oop?

              • tatterdemalion ( tatterdemalion@programming.dev ) 
                link
                fedilink
                arrow-up
                1
                ·
                9 months ago

                I have used OOP design patterns many times, but that doesn’t mean I use inheritance a lot. I almost always reach for interfaces instead.

                • Valmond ( Valmond@lemmy.dbzer0.com ) 
                  link
                  fedilink
                  arrow-up
                  2
                  ·
                  9 months ago

                  Well then I understand why inheritance isn’t your thing, I yet have to see an interface in need of inheritance.

    • kalpol ( kalpol@lemmy.ca ) 
      link
      fedilink
      arrow-up
      3
      ·
      9 months ago

      This applies to firewall rules too

    • Supercrunchy ( Supercrunchy@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      3
      ·
      9 months ago

      It might be nice to use in some very specific cases (e.g. addition-operation is a binary-operation AST node which is an AST node).

      In most of the cases it just creates noise though, and you can usually do something different anyway to implement the same feature. For example in rust, just use enums and list all the possible cases and it’s even nicer to use than inheritance.

    • wewbull ( wewbull@feddit.uk ) 
      link
      fedilink
      English
      arrow-up
      1
      ·
      9 months ago

      Do you include “traits” and “interfaces” under the title “inheritance”?

      • tatterdemalion ( tatterdemalion@programming.dev ) 
        link
        fedilink
        arrow-up
        1
        ·
        9 months ago

        No because those are different things.

  • jenesaisquoi ( jenesaisquoi@feddit.org ) 
    link
    fedilink
    English
    arrow-up
    36
    ·
    9 months ago

    Composition over inheritance every day, all day

  • kibiz0r ( kibiz0r@midwest.social ) 
    link
    fedilink
    English
    arrow-up
    32
    ·
    9 months 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.

    • bleistift2 ( bleistift2@sopuli.xyz ) 
      link
      fedilink
      English
      arrow-up
      10
      ·
      9 months ago

      Should’ve listed the source. Bad commenter.

      • kibiz0r ( kibiz0r@midwest.social ) 
        link
        fedilink
        English
        arrow-up
        17
        ·
        9 months ago

        Source: https://wiki.c2.com/?ClosuresAndObjectsAreEquivalent

        (Sorry dude, my time was limited by how long I could spare poopin in-between meetings.)

  • Flipper ( Flipper@feddit.org ) 
    link
    fedilink
    arrow-up
    24
    ·
    9 months ago

    Deref is for smart pointers and not for inheritance.

    • jenesaisquoi ( jenesaisquoi@feddit.org ) 
      link
      fedilink
      English
      arrow-up
      2
      ·
      9 months ago

      Also sometimes newtypes

  • NigelFrobisher ( NigelFrobisher@aussie.zone ) 
    link
    fedilink
    arrow-up
    13
    ·
    9 months 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?

    • ulterno ( ulterno@programming.dev ) 
      link
      fedilink
      English
      arrow-up
      8
      ·
      9 months 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.

    • jason ( jason@discuss.online ) 
      link
      fedilink
      English
      arrow-up
      7
      ·
      9 months ago

      Yeah… Wheres the AbstactAnimalFactoryManager?

      • Eufalconimorph ( Eufalconimorph@discuss.tchncs.de ) 
        link
        fedilink
        arrow-up
        2
        ·
        9 months ago

        I always knew Mondrian was painting cow production machines.

  • Hirom ( Hirom@beehaw.org ) 
    link
    fedilink
    arrow-up
    3
    ·
    9 months ago

    Separating data structure from implementation has benefits.

    In languages with classic OOP classes and objects, it’s often necessary to write wrappers or adapters to allow new operations on existing objects. This adds overhead and require more code.

  • [object Object] ( panda_abyss@lemmy.ca ) 
    link
    fedilink
    arrow-up
    2
    ·
    9 months ago

    I wish I could take go’s interfaces and drop them into zig, and that’s all the object oriented concepts I need.

  • Ada ( Ada@chatgptjailbreak.tech ) BannedBanned from community
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    9 months ago

    Removed by mod

  • Draconic NEO ( Draconic_NE0@chatgptjailbreak.tech ) BannedBanned from community
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    9 months ago

    Removed by mod

Programmer Humor@programming.dev

programmer_humor@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmer_humor@programming.dev

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

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics
    • If the mod doesn’t find it funny, you’re banned. Ha-ha!.. For real: do not use the community for “statements”. There are other places for such content. Keep it chill and funny.
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 786 users / day
  • 3.54K users / week
  • 5.04K users / month
  • 8.2K users / 6 months
  • 463 local subscribers
  • 33.8K subscribers
  • 1.61K Posts
  • 26.7K Comments
  • Modlog
  • mods:
  • Feyter ( Feyter@programming.dev ) 
  • adr1an ( anzo@programming.dev ) 
  • BurningTurtle ( BurningTurtle@programming.dev ) 
  • Pierre-Yves Lapersonne ( pylapp@programming.dev ) 
  • BE: 0.19.15
  • Modlog
  • Legal
  • Instances
  • Docs
  • Code