Naming practices for values and objects


#1

Here are a few tips that might make things easier when working on projects :smiley: It's not unusual that people name their values and objects with something like "thingy" or letters typed randomly from the keyboard, but it makes it easier for you and others if you choose a name that describes what the value or object is going to be used for :thumbsup:

Why it's helpful:
So when it's been a while and you look back to the project, you will be able to work out quickly what each value or object does rather than having to go through all the code to understand what each thing is meant to be doing :slight_smile:

Things to consider when naming:
There are things you can think about when naming something too. The more descriptive your name is, the quicker you'll be able to remember what it does with just a glance. For example, you could use a value called 'cost A' to store the amount of money that it takes to buy an apple, but 'price of apple' tells you immediately what that value holds (and helps to avoid confusion if you add another item that has a name starting with A). Even if the name is a little longer, it takes you less time to work out what it does each time you look at it.

It can also be helpful to name the start of objects/values with the type of purpose they were made for. So if you have a lot of values for the costs of certain items (e.g. an apple, a banana, a carrot) and you name the values CostApple, CostBanana, CostCarrot the grouping might make it more convenient when you look for one cost, you see the other costs too. Or depending on your purpose, it might be easier for you if you want all values relating to carrot to be in one place. You could name your values starting with Carrot so you can have them all there when you're looking for anything relating to the carrot.

You can always change it, and this can apply to other things too.
If you don't know what something will be used for at the time you choose its name, that's fine too as you can always change the name of an object or value at any time though you can't change names of values at the moment (it turns out in the new update, you can change names of values now too! Thanks to @CreativeCoder and @CreationsOfaNoob for that!) But any name that you choose to describe what you think the value or object might be used for will be more clear and helpful than "asdf" or "Text4" :stuck_out_tongue:

You can apply this to lots of other things too — naming projects, files on your device (and even titles of forum topics — "game not starting after tapping button" will help others get an idea of the problem more quickly than only "heeelppp" :slight_smile:)


This is just a little something you can keep in mind and I just thought I'd share after reading a sample of App Development With Swift by Apple :) I am sharing too because it had me thinking about how I could improve naming values in my own projects :D

Coding tips for everyone
#2

Very helpful @t1_hopscotch!


#3

Great explanation, t1. In the new update, you actually can rename values just like abilities :D


#4

Good tutorial/help @t1_hopscotch :D
One thing: it is now possible to rename values by pressing them for a couple of seconds :D
Edit: @CreativeCoder you beat me XD


#5

Great topic! Thanks for the tips. Sometimes i name my values and abilities Jenswkndq or thingy or etc.


#6

Wow!! I really did not know that you could rename values now — thank you so much for that @CreativeCoder and @CreationsOfaNoob! That is so helpful!

Thank you @TheRealBlah and @bluedogmc-official I am glad it was helpful :smiley:


#7

Great explanation! Like you said, it's much easier to figure out what an old half-finished project is supposed to be doing if the values are named properly. Otherwise it's a nightmare.


#8

Great topic!

Sadly, I still name my values potato, Jumpyduckz, crouchychakins, thing, etc XD
Hopefully I will start naming my values properly unless that's rally what i need them for lol XD


#9

HAVE YOU BEEN LOOKING THROUGH MY PROJECTS :0

I ALWAYS USE "THINGY!" :sweat_smile:


#10

Awesome tips - and I think naming things might be the hardest part of developing. Especially when I'm doing a big project and just kind of on autopilot, I'll name my variables very weird things without realizing it. I've gotten better over the years, but I do occasionally still slip up - I remember once I coded very long into the night on a physics project, and wanted to keep going on it when I woke up.
So, for one of the formulas I needed the current force of gravity on an object, which I assumed was called "G" or "Gravity" or something like that. But, I kid you not, these were my global variables:

Gravity
G
Gravity?
G!
G2
Gravity2
GGGGGGG
grav

Those were it. I had been using some variation of gravity for every variable in my project without realizing it. The code itself was too messy to look through and identify the right ones in the right variables because I made all sorts of optimization and parallel things. So, I made a set text to see which one matched the value. I knew that the right one would be very small and would go into scientific notation. Well, all of them did. All of them were very close in value, too.

So, I made a graph of their values throughout the project. I knew the right variable would look like a logarithmic plot, and I even could identify a few of the values that the plot would intersect. But, alas, all of them were logarithmic, and all but 1 hit the exact same points on the graph that I predicted, but their plots were slightly different. And can you guess which 1 I had ruled out? Yeah, the one called "Gravity".

At this point I was fed up, so I just deconstructed my code until I could piece together a few formulas I had been using. Turns out, all those other variables were based on the gravity variable, and had been interpolating (mimicking) it because they were canceling eachother out since I hadn't put in formulas for some of them.

So, what was the right gravity variable in the end?
It was a local variable of some random text object, and it was called "Var1".

:confused:


#11

Nice topic! I name only some objects tho


#12

Nice topic @t1_hopscotch :thumbsup:


#13

Great topic!

Soz but I still name mine potato, unicorn, you face, cheezychakinz, ect. XD

It actually helps me remember them!


#14

Don't worry everyone, I still end up with vague names and have to search through the code to see what each thing does :laughing: which is why I thought I'd share this little tip :slight_smile:

@BuildASnowman that's really helpful too — displaying your values using a text object or graphing to see what it is set to :smiley: thank you for sharing that :)


#15

Revive! :D


#16

This is a good topic.