• squaresinger@lemmy.world
    link
    fedilink
    arrow-up
    5
    ·
    9 hours ago

    The one good principle. And I now I can see why: it was invented by people who knew their maths — type theory in this case. In lay terms it’s simple: anything you can observe about the base class, remains true of its derived classes. That way you can pretend instances of the derived classes are also instances of the base class, without any nasty surprise.

    On the one hand, duh: that’s just subtyping. But on the other hand, very few type systems enforce it — Java and C++ do not. That makes it very easy to make a dumb mistake like overriding a stable sort() method, and make it not stable for the derived class.

    Javas immutable lists are an example of that right in the standard library.

    The super type List has mutability. When you call any of these methods in the immutable list, you get an exception.

    So if you have an arbitrary List object, you have no idea whether calling any method that mutates the object will work or not.

    And this is doubly bad with the linter demanding you use Stream.toList() (which returns an immutable list) instead of Stream.collect(Collectors.toList()) (which returns a mutable list).

    Horrible, dumb design.

  • onlinepersona@programming.dev
    link
    fedilink
    English
    arrow-up
    4
    ·
    15 hours ago

    Just like all “principles” they shouldn’t be blindly applied. Simply forcing SOLID upon a codebase won’t magically make it better. In fact, I’ve seen codebases that “strictly follow SOLID principles” being terrible to understand, debug, follow, and optimise.

    There will always be blind and zealous followers who will vehemently “protect” a codebase (or anything really) from impure modifications. They are the worst to deal with.

    • calliope@retrolemmy.com
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      8 hours ago

      The author actually mentions this in the article and finds no irony in it.

      Okay, so the “principle” is now a judgement call

      No shit. That’s the entire idea of every coding “principle”. For decades now! That’s actually what makes experience important… maybe that’s what this author is missing.

      Not to beat on [a] dead horse, but [the rambling] alone should have been enough to make any competent programmer sceptical of anything [this author] has to say about programming.

      They don’t lack confidence though!