• AlmightySnoo 🐢🇮🇱🇺🇦@lemmy.world
    link
    fedilink
    arrow-up
    5
    arrow-down
    2
    ·
    edit-2
    1 year ago

    I know the guy meant it as a joke but in my team I see the damage “academic” OOP/UML courses do to a programmer. In a library that’s supposed to be high-performance code in C++ and does stuff like solving certain PDEs and performing heavy Monte-Carlo simulations, the guys with OOP/UML background tend to abuse dynamic polymorphism (they put on a pikachu face when you show them that there’s also static polymorphism) and write a lot of bad code with lots of indirections and many of them aren’t aware of the fact that virtual functions and dynamic_cast’s have a price and an especially ugly one if you use them at every step of your iterative algorithm. They’re usually used to garbage collectors and when they switch to C++ they become paranoiac and abuse shared_ptr’s because it gives them peace of mind as the resource will be guaranteed to be freed when it’s not needed anymore and they don’t have to care about when that is the case, they obviously ignore that under the hood there are atomics when incrementing the ref counter (I removed the shared pointers of a dev who did this in our team and our code became twice as fast). Like the guy in the screenshot I certainly wouldn’t want to have someone in my team who was molded by Java and UML diagrams.

    • ForegoneConclusion@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      1 year ago

      Depends on the requirements. Writing the code in a natural and readable way should be number one.

      Then you benchmark and find out what actually takes time; and then optimize from there.

      At least thats my approach when working with mostly functional languages. No need obsess over the performance of something thats ran only a dozen times per second.

      I do hate over engineered abstractions though. But not for performance reasons.

      • Ryan@programming.dev
        link
        fedilink
        arrow-up
        6
        ·
        1 year ago

        You need to me careful about benchmarking to find performance problems after the fact. You can get stuck in a local maxima where there is no particular cost center buts it’s all just slow.

        If performance specifically is a goal there should probably at least be a theory of how it will be achieved and then that can be refined with benchmarks and profiling.

      • Aceticon@lemmy.world
        link
        fedilink
        arrow-up
        2
        ·
        1 year ago

        In my experience we all go through a stage at the Designed-Developer level of, having discovered things like Design Patterns, overengineering the design of the software to the point of making it near unmaintainable (for others or for ourselves 6 months down the line).

        The next stage is to discover the joys of KISS and, like you described, refraining from premature optimization.

      • CanadaPlus@lemmy.sdf.org
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        1 year ago

        Writing the code in a natural and readable way should be number one.

        I mean, even there it depends what you’re doing. A small matrix multiplication library should be fast even if it makes the code uglier. For most coders you’re right, though.

    • magic_lobster_party@kbin.social
      link
      fedilink
      arrow-up
      1
      ·
      1 year ago

      I think many academic courses are stuck with old OOP theories from the 90s, while the rest of the industry have learned from its failures long time ago and moved on with more refined OOP practices. Turns out inheritance is one of the worst ways to achieve OOP.

      • fidodo@lemm.ee
        link
        fedilink
        arrow-up
        1
        ·
        1 year ago

        I think a lot of academic oop adds inheritance for the heck of it. Like they’re more interested in creating a tree of life for programming than they are in creating a maintainable understandable program.

      • einsteinx2@programming.dev
        link
        fedilink
        English
        arrow-up
        1
        ·
        1 year ago

        That’s the problem, a lot of CS professors never worked in the industry or did anything outside academia so they never learned those lessons…or the last time they did work was back in the 90s lol.

        Doesn’t help that most universities don’t seem to offer “software engineering” degrees and so everyone takes “computer science” even if they don’t want to be a computer scientist.

        • magic_lobster_party@kbin.social
          link
          fedilink
          arrow-up
          2
          ·
          1 year ago

          OOP can be good. The problem is that in Java 101 courses it’s often taught by heavily using inheritance.

          I think inheritance is a bad representation of how stuff is actually built. Let’s say you want to build a house. With the inheritance way of thinking you’re imagining all possible types of buildings you can make. There’s houses, apartment buildings, warehouses, offices, mansions, bunkers etc… Then you imagine how all these buildings are related to each other and start to draw a hierarchy.

          In the end you’re not really building a house. You’re just thinking about buildings as an abstract concept. You’re tasked to build a basic house, but you are dreaming about mansions instead. It’s just a curious pastime for computer science professors.

          A more direct way of building houses is to think about all the parts it’s composed of and how they interact with each other. These are the objects in an OOP system. Ideally the objects should be as independent as possible.

          This concept is called composition over inheritance.

          For example, you don’t need to understand all the internals of the toilet to use it. The toilet doesn’t need to be aware of the entire plumbing system for it to work. The plumbing system shouldn’t be designed for one particular toilet either. You should be allowed to install a new improved toilet if you so wish. As long the toilet is compatible with your plumbing system. The fridge should still work even if there’s no toilet in the house.

          If you do it right you should also be able to test the toilet individually without connecting it to a real house. Now you suddenly have a unit testable system.

          If you ever need polymorphism, you should use interfaces.