var Turtle1 var Turtle2 var Is_Turtle

  • henfredemars@infosec.pub
    link
    fedilink
    English
    arrow-up
    47
    ·
    7 days ago

    Try assembly language! You have registers, and they are named for you with highly memorable names like R17.

  • parpol@programming.dev
    link
    fedilink
    arrow-up
    23
    ·
    edit-2
    7 days ago

    Yeah, a name should describe what it is or does, so if you have two turtles, and let’s say turtle1 wants to shit on turtle2’s lawn, you could name them shittingTurtle and victimTurtle. If the name alone tells you what its purpose is, that saves a lot of time for people looking at your code.

    Is_Turtle is not a bad variable name because it tells you it is a Boolean with “is” and that the Boolean tells you whether something is a turtle or not.

    Also, depending on the language, I suggest either camelCase or snake_case naming of variables. PascalCase is usually for defining classes or in case of C#, methods.

    • Repple (she/her)@lemmy.world
      link
      fedilink
      arrow-up
      12
      ·
      7 days ago

      SHOUTING_SNAKE_CASE aka SCREAMING_SNAKE_CASE is the best case for all use cases, because it gives you a chance to use its wonderful names.

    • MajorHavoc@programming.dev
      link
      fedilink
      arrow-up
      3
      ·
      6 days ago

      Thank you for this. This is awesome.

      shittingTurtle and victimTurtle are going into one of my professional slide decks as soon as I think I can get away with it.

    • OttoVonNoob@lemmy.caOP
      link
      fedilink
      arrow-up
      4
      ·
      edit-2
      7 days ago

      I’m gonna be honest I just used Turtle ad an example:X … when it’s actually like a GoldCost, GoldC and GoldH. Where GoldR is a reset var and GoldC is the paid value. GoldCost is self explanatory but I really spagettied it up XD…

  • r00ty@kbin.life
    link
    fedilink
    arrow-up
    10
    ·
    7 days ago

    An array?

    var turtles = new Turtle[] { new Turtle(), new Turtle() };

    Don’t do this :P

  • Kojichan@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    5 days ago

    I remember an old mentor programmer I had who basically described his job as building an addition to an addition to an addition on a tree house built in a twig.

    • Leate_Wonceslace@lemmy.dbzer0.com
      link
      fedilink
      English
      arrow-up
      5
      ·
      7 days ago

      What’s wrong with making a recursive function in a recursive function with variables M, m, N, n? It’s perfectly fine when I’m writing infinite series.

      • CanadaPlus@lemmy.sdf.org
        link
        fedilink
        arrow-up
        1
        ·
        6 days ago

        If we’re talking mathematicians, you just know it’s going to be ω-nested recursive functions any moment now. Just be grateful it’s not all n with polynomial subscripts or something.

  • MajorHavoc@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    6 days ago

    All great code started out as a shitty work-around that happened to work.

    (I say this as someone with one of the more prestigious pedigrees in “not writing shit code”. All the theory I’ve learned helps, but at the end of the day the most important qualities of a line of code are: whether it got the job done, and whether is was obviously correct enough that the next developer left it alone.)

  • some_guy@lemmy.sdf.org
    link
    fedilink
    arrow-up
    3
    ·
    6 days ago

    Because I mostly (almost exclusively) write shell scripts, my vars are often like this: theList, workingDir, etc.

    I’m a monster. But it works for me.

  • umbraroze@lemmy.world
    link
    fedilink
    arrow-up
    3
    ·
    6 days ago

    This is a very cute thread. I love turtles and I like them for their vast computer science skills too.

  • 🇰 🌀 🇱 🇦 🇳 🇦 🇰 ℹ️@yiffit.net
    link
    fedilink
    English
    arrow-up
    4
    ·
    edit-2
    7 days ago

    I always make sure my variables are named in ways I can remember what they’re for. The only time I just use generic var1, var2, etc is if I am experimenting with a function I’ve never used before and wanna play around with it to see how it’s used.

    This should be easily read by others but there could be times where it’s an inside joke.

  • Codex@lemmy.world
    link
    fedilink
    arrow-up
    2
    ·
    6 days ago

    All these jokes about naming variables and yet no serious suggestions that if you have a turtle2, what you really need is a turtle array. I like to block out all the memory I’ll need for the whole program up front, put it all in one big array, and then I can use clean, easy to remember numbers for all my variables!

  • OpenStars@discuss.online
    link
    fedilink
    English
    arrow-up
    2
    ·
    7 days ago

    Yes your variable names should indeed all be different from one another.

    var Turtle1 var Turtle1 var Turtle1

    just doesn’t quite have the same impact:-).

    • WhiskyTangoFoxtrot@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      6 days ago

      The word ‘code’ has many different definitions. The shaolin martial arts tournament is governed by a system of rules of conduct
      …an ethical code.

      The combatants respect each other as warriors, no matter what degree of hatred they have for one another
      …a code of honor.

      Another type of code could be defined as an arbitrary system of symbols or letters for transmitting messages
      …a secret code.

      Mortal Kombat™ adheres to many codes, but does it contain one?