• rockerface 🇺🇦@lemm.ee
    link
    fedilink
    English
    arrow-up
    150
    ·
    edit-2
    11 months ago

    As a software developer, the less ambiguous your notation is, the better it is for everyone involved. Not only will I use brackets, I’ll split my expression into multiple rows and use tabs to make it as readable as humanly possible. And maybe throw a comment or 2 if there’s still some black magic involved

    • dustyData@lemmy.world
      link
      fedilink
      English
      arrow-up
      46
      ·
      11 months ago

      As a professor said, most programming languages don’t care about readability and whitespace. But we care because humans need it to parse meaning. Thus, write code for people, not for the machine. Always assume that someone with no knowledge of the context will have to debug it, and be kind to them. Because that someone might be you in six months when you have completely forgotten how the code works.

      • zalgotext@sh.itjust.works
        link
        fedilink
        English
        arrow-up
        14
        ·
        11 months ago

        Exactly. You read code way more times than you write it, so it makes all the sense in the world to prioritize readability.

      • rockerface 🇺🇦@lemm.ee
        link
        fedilink
        English
        arrow-up
        4
        ·
        edit-2
        11 months ago

        Yep, if you’re writing code for a machine, just do it in binary to save compilation time (/s just in case). Also, you in six months will indeed be someone with no knowledge of the context. And every piece of code you think you write for one-time use is guaranteed to be reused every day for the next 5 years

    • Quetzalcutlass@lemmy.world
      link
      fedilink
      English
      arrow-up
      41
      ·
      11 months ago

      I had someone submit a pull request recently that, in addition to their actual changes, also removed every single parenthesis that wasn’t strictly necessary in a file full of 3D math functions. I know it was probably the fault of an autoformatter they used, but I was still the most offended I’ve ever been at a pull request.

    • MotoAsh@lemmy.world
      link
      fedilink
      English
      arrow-up
      7
      ·
      11 months ago

      I genuinely hate being human for this stuff. So many things have such crazy computational shortcuts, it’s sometimes difficult to remember which part represents reality. Outside of the realm of math, where “imaginary” numbers are still a touch of enigma to me, so many algorithms are based on general assumptions about reality or the specific task, that the programmatic approach NEVER encapsulates the full scope of the problem.

      As in, sometimes if you know EXACTLY how a tool works, you might still have no idea about the significance of that tool. Even in a universe where no one is lazy, and everyone wants to know “why?”, the answers are NOT forthcoming.

    • stebo@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      2
      arrow-down
      2
      ·
      11 months ago

      Ok but that’s unrelated to putting some numbers and operations in a calculator. No one is going to proofread that. If anything, you simply calculate it again.

    • Ultraviolet@lemmy.world
      link
      fedilink
      English
      arrow-up
      3
      ·
      11 months ago

      I would never write -n². Either ‐(n²) or (-n)². Order of operations shouldn’t be some sort of gotcha to trick people into misinterpreting you, it’s the intuitive reading of a well constructed mathematical expression.

    • ByGourou@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      4
      arrow-down
      1
      ·
      11 months ago

      Isn’t the “-” order of operations the same as a multiply ? I think I learned powers take priority over the “-” so your calculator would be right.
      But either way if it can cause confusion you should use parentheses.

      • TonyTonyChopper@mander.xyz
        link
        fedilink
        English
        arrow-up
        4
        arrow-down
        1
        ·
        11 months ago

        Every calculator I’ve used has separate negative and subtraction keys for this purpose. There is no order of operations to follow, it’s just a squaring a number

        • ByGourou@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          3
          arrow-down
          1
          ·
          edit-2
          11 months ago

          I learned negative as being a separate operation where we need to apply the order of operations. I think it was something like : -2 is a diminutive for -1x2 so it uses the order of operations of a multiplication.
          My calculator is the official one used in schools in France (ti-83 premium ce) and it says -2^2 = -4 with the negative key. I don’t think it would make a mistake in such a simple concept.

          But whatever these concepts can change depending on the field, country, level of education. What I mean is : it’s unclear, so use parentheses. So (-2)^2 or -(2^2) are the correct ways to write it.

  • MotoAsh@lemmy.world
    link
    fedilink
    English
    arrow-up
    7
    arrow-down
    2
    ·
    edit-2
    11 months ago

    The underlying truth of this joke is: Programming syntax is less confusing than mathematical syntax. There are genuinely ambiguous layouts of syntax in math (to a human reader that hasn’t internalized PEMDAS, anyways) whereas you get a compilation error if ANYTHING is ambiguous in programming. (yes, I am WELL aware of the frustrations of runtime errors)

    • dejected_warp_core@lemmy.world
      link
      fedilink
      English
      arrow-up
      1
      ·
      11 months ago

      Also: sometimes, a mathematician just has to invent some concept or syntax to convey something unconventional. The specific use of subscript/superscript, whatever ‘phi’ is being used for, etc. on whatever paper you’re reading doesn’t have to correlate to how other work uses the same concepts. It’s bad form, but sometimes its needed, and if useful enough is added to the general canon of what we call “math”. Meanwhile, you can encapsulate and obfuscate things in software, sure, but you can always get down to the bedrock of what the language supports; there’s no inventing anything new.

      • MotoAsh@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        edit-2
        11 months ago

        Yea, that’s it. Math syntax was created for humans, and programming syntax had to always remain deterministic for computers. It’s not an insult to either, just interesting how ambiguities show up often when humans are involved. I say ‘often’ for the general case: Math should be just as deterministic as programming, but it’s not in some situations.