When you write code, you will spend a lot of time thinking up names for things. Variables and functions, then as you write bigger programs you might also be creating classes and modules.
There are some people who even say that programming is mainly about thinking up names for things! That might be a bit extreme, but it is very important to give items good names, because the names you use can have a huge effect on the readability of your code. And more readable code is more maintainable code.
Simple function or variable names might be just one word, such as "print" or "input", but often you need more than one word. For example if you have a program that calculates a value, then the function that prints the result should be called something like "print result".
Unfortunately, that isn't a valid variable name in most languages, because it includes a space. There are 3 main alternatives:
Java and C# typically use camel case, Python typically uses snake case, some other languages are a bit less clear cut. Whichever you use, it is best to choose one style and stick to it.
When you are writing code, it is worth remembering:
{{% purple-note %}} You write code for humans to understand. {{% /purple-note %}}
Of course, the interpreter or compiler must "understand" your code too, but it doesn't care what you call your variables. Always think of the poor human who might have to read it.
The general rule is to make names descriptive
Some languages have naming conventions that most programmers use. It is a good idea to follow these as it makes you code more readable for other programmers. Here are some common ones of ten used in Python, Java, C and other languages:
Also, variable names are often nouns because they represent things in your program, but function names are often verbs because they represent actions in your program.
{{% blue-note %}} If you program using classes:
{{% /blue-note %}}
Here are a few things you should usually avoid:
Try not to include pointless information in your names:
Sometimes you might see, for example, a list of student called studentList. That isn't too bad, but it might be better to just call it students.
People may tell you that you should never use single letter variable names, but they have their place:
Copyright (c) Axlesoft Ltd 2021