Seeing that Uncle Bob is making a new version of Clean Code I decided to try and find this article about the original.

  • Lysergid@lemmy.ml
    link
    fedilink
    arrow-up
    12
    arrow-down
    4
    ·
    4 months ago

    Folks really trying to argue about example code. Even created “global state” straw man. Here is secret - if you are using global state then code is shit in the most cases.

    • BatmanAoD@programming.dev
      link
      fedilink
      arrow-up
      8
      arrow-down
      1
      ·
      4 months ago

      It’s not a strawman, though, because Martin’s actual example code in the book is like this, including a full module he rewrites toward the end.

    • FizzyOrange@programming.dev
      link
      fedilink
      arrow-up
      2
      ·
      3 months ago

      When they say global state here it’s not really global state, it’s class members - global to the class. “Why are they calling it global state then, idiots?” you might think. It’s because it prevents local reasoning in the same way as global state does (and most people get the implications of “global state” because of experience, so it’s a kind of shorthand).

      Of course, not many people would recommend “no class variables” (in a classic OOP language anyway), but the point is they have similar downsides to global variables in terms of understanding code (and testing, etc.) so recommending to always use them - even when passing state in and out of functions is perfectly ergonomic - is clearly bonkers.