• einkorn@feddit.org
    link
    fedilink
    arrow-up
    3
    arrow-down
    3
    ·
    1 month ago

    I can’t find it right now, but there is some explanation in “Clean Code” why switches shouldn’t be used all over the place.

    • djnattyp@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      1 month ago

      Google for “replace conditional with polymorphism”.

      Just checked and it is in “Clean Code” - Chaper 17; Section G23 “Prefer Polymorphism to if/else or switch/case”.

      • FizzyOrange@programming.dev
        link
        fedilink
        arrow-up
        2
        ·
        1 month ago

        This is really terrible advice. Sometimes it’s better to do that, but definitely not in the example from this article.

        If anyone says you should always prefer polymorphism to switches they are a bloody idiot.