• krey@sh.itjust.works
    link
    fedilink
    arrow-up
    16
    ·
    9 months ago

    The trick is to name everything in a way so you don’t have to remember stuff. Like instead of class “Cronjob” method “process”, name it “ImageCacheEraser” and “purgeByContentID”. Same goes for variables. No need for short names. Nowadays, you can even write with short names at first, so typing is faster, then just use your IDE to rename them to full size afterwards.

      • krey@sh.itjust.works
        link
        fedilink
        arrow-up
        3
        ·
        9 months ago

        Some IDEs (like Netbeans, Intellij, PhpStorm) can rename only in the scope of the selected item. So if you used variable “a” in 2 methods, it would only rename in the selected method and it understands the variable is different from “ab” and won’t replace the “a” part of that.

    • anotherandrew@lemmy.mixdown.ca
      link
      fedilink
      arrow-up
      2
      arrow-down
      1
      ·
      9 months ago

      Agreed except for the variables. You can pry the iterators i, j, k, the pointers p and q, and the temporary buffer buf, from my cold, dead hands.

      Short variable names increase code clarity, particularly when the functions employing them are concise and named appropriately. There’s not much worse than using something like sourcedata[databufferiterator] instead of src[i]. It reminds me of authors who think that big words make them sound more intelligent. Needing or advocating auto complete in IDEs is a symptom of this kind of code smell, IMO.

      Code should be clear and concise; it’s also why I fight for 8 character indentation; if your code is creeping across the screen it’s a damn good indication that the function might be too complex and should be broken up.