• henfredemars@infosec.pub
    link
    fedilink
    English
    arrow-up
    96
    ·
    2 years ago

    I worked with a developer who insisted on using the shortest names possible. God I hated debugging his code.

    I’m talking variable names like AAxynj. Everything looking like matrix math.

      • nogooduser@lemmy.world
        link
        fedilink
        English
        arrow-up
        7
        ·
        2 years ago

        I don’t understand why people think that it’s acceptable.

        As developers, we’ve had it drummed into us from day one that variable names are important and shouldn’t be one or two letters.

        Yet developers deliberately alias an easy to read table name such as “customer” into “c” because that’s the first letter of the table. I’m sure that it’s more work to do that with auto completion meaning that you don’t even need to type out “customer”.

        • xmunk@sh.itjust.works
          link
          fedilink
          arrow-up
          5
          ·
          2 years ago

          Especially when you also have company and county tables. It forces people to look up what the c is aliased to before beginning to comprehend what you’re doing.

    • ray@sh.itjust.works
      link
      fedilink
      English
      arrow-up
      5
      ·
      2 years ago

      At a previous job I had to work with an old database where all the tables and columns had 6-character names

      • WFH@lemm.ee
        link
        fedilink
        English
        arrow-up
        1
        ·
        2 years ago

        Same. Old DB2 base from the 80’s that was migrated to Oracle in the 90’s then to Postgres in the 2010’s.

        And the people there know all the column names by heart 😅

    • rufus@discuss.tchncs.de
      link
      fedilink
      arrow-up
      10
      ·
      2 years ago

      Make it 63 (31?) to align with what C99 can distinguish.

      Also: I really like unicode in identifiers. So if at all possible don’t just have a random string of letters and numbers, make sure to include greek letters and all the funny emojis. (I just forgot which languages and compilers etc allow that.)

  • steventhedev@lemmy.world
    link
    fedilink
    arrow-up
    30
    ·
    2 years ago

    Older C compilers would truncate a variable name if it was too long, so VeryLongGlobalConstantInsideALibraryInSeconds might accidentally collide with VeryLongGlobalConstantInsideALibraryInMinutes.

    Legend says that they used to do it after a single letter with Dennis declaring “26 variables ought to be enough for anyone”.

    • olutukko@lemmy.world
      link
      fedilink
      arrow-up
      7
      ·
      2 years ago

      I had this problem in my job as a drafter. I was wondering why the hell Tekla would complain about the same object name already being in use despite everything having its own name. took me way too long to realize there wad some stupidly max name length and the program did nothing to alarm the user about trying to put too long name. it just cut the overflow away.

  • ZILtoid1991@lemmy.world
    link
    fedilink
    arrow-up
    26
    arrow-down
    2
    ·
    2 years ago

    Then you realize your code is undebuggable because half the functions and variables have single-letter names or called foo, bar, baz, etc.

    • ObsidianNebula@sh.itjust.works
      link
      fedilink
      arrow-up
      9
      ·
      2 years ago

      I have a somewhat related real world story. I had a client that was convinced that tons of people were going to decompile their application and sell their own version of the program, so they insisted that they needed their code obfuscated to protect company secrets and make it harder to reverse engineer. I tried explaining to them that obfuscation wasn’t that big of a deterrent to someone attempting to steal code through reverse engineering and that it would likely cause some issues with debugging, but they were certain they needed it. Sure enough, they then had a real user run into an issue and were surprised to find that their custom logging system was close to useless because the application was outputting random obfuscated letters instead of function and variable names. We did have mapping files, but it took a lot of time to map each log message to make it readable enough to try to understand the user’s issue.

  • DarkSurferZA@lemmy.world
    link
    fedilink
    arrow-up
    23
    ·
    2 years ago

    Gotten even easier after X became a registered trademark. Now the only choice we have left is i. Or ii if you need more variables

  • FrostyCaveman@lemm.ee
    link
    fedilink
    arrow-up
    20
    ·
    2 years ago

    Single character variable names are my pet peeve. I even name iterator variables a real word instead of “i” now… (although writing the OG low level for loops is kinda rare for me now)

    Naming things “x”… shudder. Well, the entire world is getting to see how that idea transpires hahah

    • Mikelius@lemmy.ml
      link
      fedilink
      arrow-up
      16
      ·
      2 years ago

      I hate short variable names in general too, but am okay with them for iterators where i and j represent only indices, and when x/y/z represent coordinates (like a for loop going over x coordinates). In most cases I actually prefer this since it keeps me from having to think about whether I’m looking at an integer iterator or object/dictionary iterator loop, as long as the loop remains short. When it gets to be ridiculous in size, even i and j are annoying. Any other short names are a no go for me though. And my god, the abbreviations… Those are the worst.

      • FrostyCaveman@lemm.ee
        link
        fedilink
        arrow-up
        5
        ·
        2 years ago

        That’s very reasonable, I can get behind that. (my stance is a partly irrational overreaction and I’m totally aware of it lol)

        Abbreviations are definitely annoying. My least favourite thing to do with them is “Hungarian notation”. It’s like… in a statically typed context it’s useless, and in a dynamically typed context it’s like… kind of a sign you need to refactor

        • Redkey@programming.dev
          link
          fedilink
          arrow-up
          1
          ·
          2 years ago

          Most people use the term “Hungarian Notation” to mean only adding an indicator of type to a variable or function name. While this is one of the ways in which it has been used (and actually made sense in certain old environments, although those days are long, long behind us now), it’s not the only way that it can be used.

          We can use the same concept (prepending or appending an indicator from a standard selection) to denote other, more useful categories that the environment won’t keep straight for us, or won’t warn us about in easy-to-understand ways. In my own projects I usually append a single letter to the ends of my variable names to indicate scope, which helps me stay more modular, and also allows me to choose sensible variable names without fear of clashing with something else I’ve forgotten about.

    • nicky7@lemmy.ml
      link
      fedilink
      arrow-up
      2
      ·
      2 years ago

      Same, except for list comprehension in python, I prefer sinlge character var names there.

  • RandomVideos@programming.dev
    link
    fedilink
    arrow-up
    12
    ·
    2 years ago

    Since a lot of the english words i know i learned from minecraft, in a farming simulator i named tilled soil"hoed"

    I had multiple variables like int isHoed

    • BleatingZombie@lemmy.world
      link
      fedilink
      arrow-up
      20
      ·
      2 years ago

      Variable names should be “self defining” meaning you should be able to understand what its doing from the name. The name also shouldn’t be too long. Combining those together makes it difficult to come up with an “elegant” name

        • Homosexual sapiens@lemmy.blahaj.zone
          link
          fedilink
          arrow-up
          5
          arrow-down
          1
          ·
          2 years ago

          The most atrocious variable names I ever encountered in code were as a research assistant for a math professor doing game theory simulations. Literally unreadable unless you had a copy of his paper on the subject to refer to

    • KillingTimeItself@lemmy.dbzer0.comBanned
      link
      fedilink
      English
      arrow-up
      7
      ·
      2 years ago

      in the linux community it’s really common to have applications like MPD, music player daemon, or MPC, music player client, and ncmpc, ncurses music player client, and ncmpcpp the aforementioned one with ++ tacked onto the end.

      Cmus, which from what i can recall is literally “c music player”

      etc…

    • trolololol@lemmy.world
      link
      fedilink
      arrow-up
      7
      arrow-down
      1
      ·
      2 years ago

      Ha

      You should hear of the method of pretending you’re at breakfast or some other anthropomorphized situation, where you name things as butter and cheese, knife and bread, tea and teapot

      Then there’s Hungarian notation which is actually used seriously. But I can’t give an entertaining example only s boring and probably inaccurate one.

    • mkwt@lemmy.world
      link
      fedilink
      arrow-up
      8
      ·
      2 years ago

      Or Fortran variables that collide with Fortran built-in functions.

      Keep in mind that array subscript and function call are both () in Fortran.