var Turtle1 var Turtle2 var Is_Turtle

9 points
*

Have you considered using inheritance?

permalink
report
reply
4 points

I’m an amateur I’m not sure what inheritance is:X? Is it like instantiateing?

permalink
report
parent
reply
6 points
*

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.

permalink
report
parent
reply
3 points

Oh yea, class resources. That would work! Thanks.im going to have to into this more, as it’s going to be useful

permalink
report
parent
reply
7 points

At this point I think there is no software dev topic that is somehow not devisive.

permalink
report
parent
reply
3 points
*

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.

permalink
report
parent
reply
3 points
*

I’m only commenting because the actual python is practically pseudo code:


# A turtle class
class Turtle:
    shell=True

# A boss class
class Boss:
    authority=True

#A class that inherits from another
class TigerTurtle(Turtle):
    fuzzy=True

# Multiple inheritance, or "The Devil's Playground"
class TigerBossTurtle(TigerTurtle, Boss):
    #  shell, authority, and fuzzy are all true
    ...
permalink
report
parent
reply
20 points

blew my inheritance on hookers and blow, now what?

permalink
report
parent
reply
12 points
*

Have you considered multiple inheritance. It’s an upgrade. All upside, literally no downside. I’m trustworthy. Trust me.

permalink
report
parent
reply
4 points

You might not like it, but that is what peak shareholders value looks like.

permalink
report
parent
reply
5 points

Idunno, my mom told me not to talk to _stranger_s 🤔

… She said a lot of things that were BS, though, so maybe you’re cool I guess? 🤷

permalink
report
parent
reply
23 points
*

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.

permalink
report
reply
4 points
*

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…

permalink
report
parent
reply
14 points

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.

permalink
report
parent
reply
14 points

I prefer REVERSEcAMEL

permalink
report
parent
reply
9 points
*

Thanks. I hate it.

I consider myself a collector of programming anti-patterns, but I didn’t have this one yet.

permalink
report
parent
reply
3 points

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.

permalink
report
parent
reply
2 points

Yes, its code whether it executes or not.

permalink
report
reply
1 point

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?

permalink
report
parent
reply
1 point

Yes, more code

permalink
report
parent
reply

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.

permalink
report
reply
2 points

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

permalink
report
reply

Programmer Humor

!programmer_humor@programming.dev

Create post

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

  • Keep content in english
  • No advertisements
  • Posts must be related to programming or programmer topics

Community stats

  • 3.4K

    Monthly active users

  • 1K

    Posts

  • 37K

    Comments