• @FizzyOrange
    link
    13
    edit-2
    2 hours ago

    …for people who refuse to use static types.

    • blaue_Fledermaus
      link
      fedilink
      102 hours ago

      Static types are great, but not exactly what would have helped here, any decent language or at least a linter should catch the use of a not declared identifier.

      • @FizzyOrange
        link
        82 hours ago
        def foo(x):
          return x.whatevr
        

        No linter is going to catch that.

        • @Strykker
          link
          028 minutes ago

          It’s python, just use type hinting already and your linter will catch that.

          Also some winters can look at the use of food and see the type being passed in.

          • Ephera
            link
            fedilink
            316 minutes ago

            Autocorrect got you pretty bad, there.

            I was very confused, why we’re suddenly talking about rationing food during winter. 🙃

          • @FizzyOrange
            link
            17 minutes ago

            Yes you can use static type hinting and the static type checker (Mypy or Pyright) will catch that. Linters (Pylint) won’t.

        • @[email protected]
          link
          fedilink
          -136 minutes ago

          Not with an example that simple and poor, no.

          If you have done the minimum and at least set a type hint, or if your ide is smart enough to check what calls the function and what it passes, then it’ll be flagged.

          • Ephera
            link
            fedilink
            212 minutes ago

            How would you make it non-awful, without specifying static types?

            I guess, a unit test would catch it, but needing 100% test coverage to catch typos isn’t exactly great…

          • @FizzyOrange
            link
            16 minutes ago

            What’s awful about this example? The only thing I do is access an object member. Does your code not do that??

            • @[email protected]
              link
              fedilink
              12 minutes ago

              What’s the purpose of foo? Why an ambiguous single character variable? What if the property was there but the value was null? Why not use (assuming JS) optional chaining?

  • @[email protected]
    link
    fedilink
    English
    42 hours ago

    I spent like 3 hours yesterday deduplicating two functions that were hundreds of lines long and nearly identical. I should probably learn how to use that git command that can diff two files on disk. Luckily I actually enjoy cleaning up code sometimes.

    • @expr
      link
      322 minutes ago

      That’s what the diff tool is for.

    • @[email protected]
      link
      fedilink
      62 hours ago

      If you’re using a decent development system, you’ll have an executable called diff installed already :)

    • @[email protected]
      link
      fedilink
      32 hours ago

      VS Code’s diff tools are killer. Comparison is smarter than most, and you can edit either file as you go.

      • @[email protected]
        link
        fedilink
        English
        22 hours ago

        And if you want to avoid the Microsoft stank, there’s VS Codium that has been de-Microsoft’d, like Chrome vs. Chromium.

    • @FizzyOrange
      link
      22 hours ago

      If you use VSCode, open both files and then ctrl-shift-P “Compare active file with …”

      You’re welcome.