var Turtle1 var Turtle2 var Is_Turtle

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

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

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

    An array?

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

    Don’t do this :P

  • 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.)

  • 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.

  • 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:-).

  • Codex@lemmy.world
    link
    fedilink
    arrow-up
    1
    ·
    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!

      • ma1w4re@lemm.ee
        link
        fedilink
        arrow-up
        3
        ·
        edit-2
        7 days ago

        Inheritance established “is a” relationship between classes.

        class Turtle;  
        class TigerTurtle is a Turtle (but better);  
        class BossTurtle is a Turtle (but better);  
        

        Underlying classes hold an inner object to the super class, everything from Turtle will be in TigerTurtle and BossTurtle.

        In some languages that is configurable with public, private, protected keywords.

        Relatedly, there’s also composition, which establishes a “has a” relationship:

        class TurtleTail;
        class Turtle:
          var tail: TurtleTail; (has a tail);
        

        Since Turtle is NOT a tail, but a whole animal, turtle should not inherit TurtleTail. But it HAS a tail, thus we add turtle tail as a property.

      • Dr. Wesker@lemmy.sdf.org
        link
        fedilink
        English
        arrow-up
        6
        ·
        edit-2
        7 days ago

        When you start learning about different paradigms, you’ll likely learn much more about inheritance when learning about the Object Oriented design paradigm.

        To overly simplify, you create objects that inherit attributes from other objects. It’s for instance a way to create reusable patterns, that have stronger and more reliable data structures.

        I made the joke comment, because for instance, you could create a Turtle class, and always know it was a Turtle. Again, an oversimplification.

        EDIT: I should also add that for some reason OOP is an oddly divisive subject. Developers always seem to want to argue about it.

          • arendjr@programming.dev
            link
            fedilink
            arrow-up
            3
            ·
            7 days ago

            Just keep in mind that inheritance is nowadays a very contested feature. Even most people still invested in object oriented programming recognise that in hindsight inheritance was mostly a mistake. The industry as a whole is also making a shift to move more towards functional programming, in which object orientation as a whole is taking more of a backseat and inheritance specifically is not even supported anymore. So yeah, take the chance to learn, but be cautious before going into any one direction too deeply.

          • Dr. Wesker@lemmy.sdf.org
            link
            fedilink
            English
            arrow-up
            1
            ·
            edit-2
            7 days ago

            If I could give a suggestion I wish I had gotten much earlier on in my education and career, it would be to really spend some time learning about the different paradigms, and their best use cases. You will likely ensure yourself a strong foundation in software architecture.

            • OttoVonNoob@lemmy.caOP
              link
              fedilink
              arrow-up
              1
              ·
              7 days ago

              I’ll check it out! I’m very casual and doing thus mostly as a passion/Fun project. But I love any direction thank you:)