This thread focuses on naming or defining variables appropriately when you program code. This is commonly viewed as an unimportant aspect that we reluctantly do just to get on with our program. Sometimes we never consider what others might first think upon reading a particular variable. Hopefully, you will attain a different view and practice of naming variables once you read this tutorial.
Why Its Important
Have you ever named a variable something completely irrelevant to its primary function? Perhaps you wanted to light an LED and called the output port TNT or Top_Secret. This might be quite sufficient for your purposes, but if you ever share your code with someone else or ask for help they probably would have no clue as to what it is for. In fact, you might not even recognize it yourself after a couple years. Therefore, you should always attempt to name or define your variables that suggest their obvious function in your code.
Advice On How to Get Started
One of the first pieces of advice has been already mentioned; that is, naming your variables according to their fundamental purpose. A common misconception of categorically naming variables is how long or short you should entitle them. It is recommended that you do not inhibit the length of a variable, otherwise it will result in a misunderstanding of their function. Complex names or numerical signs aren't advised, since it might impede comprehension. Your variables should be simple and straight to the point.
Another important concept to remember is how our brains organize information and what triggers our memories. Now this is where it gets very interesting! As you continue to practice naming variables, your brain commences organizing the names with their significance. What exactly does that mean? Well, let me provide an example.
First lets consider that variable we previously decided to symbolize our I/O port going to an LED. As part of our application, the LED will continuously blink to inadvertently represent a sophisticated security system that will keep predators away by bluffing. After contemplating on the hardware and requirements for our simple application, we come to the conclusion that only one LED is required for an effective solution. Therefore, we could name our variable simply as LED, but only due to the fact that one LED is being used. If this is your first coding project and you need assistance, then whoever is helping you can automatically connect with what you are doing by using that variable name. The name implies that you are controlling an LED as part of your hardware on your I/O pin. To confirm this assumption, anyone who is helping you can quickly glance in your #define section and see whether you set it as your output port (TRIS or GPIO, depends on PIC). If you had used the name TNT, a persons brain wouldnt emphasize remembering that name in association with its function because its completely irrelevant.
Triggers
If you wanted to remember a meeting you have at 12:00 PM, you can think of noon or lunch to prompt a trigger. Whenever you think of those words, it will effectively stimulate a thought that indicates you have a meeting at that time. Therefore, try to organize specific triggers that might stimulate thoughts relevant to your variable name. This is a useful trick when you adjust your code in the future; since you will be more likely remember the variable names and what they do. Likewise, try to think of variable names that might trigger accurate functions in your code so that others may easily understand it.
Now you see how important it is to appropriately and effectively name your variables, for your benefit and for other peoples as well.
Any suggestions, comments, or advice is encouraged!
Why Its Important
Have you ever named a variable something completely irrelevant to its primary function? Perhaps you wanted to light an LED and called the output port TNT or Top_Secret. This might be quite sufficient for your purposes, but if you ever share your code with someone else or ask for help they probably would have no clue as to what it is for. In fact, you might not even recognize it yourself after a couple years. Therefore, you should always attempt to name or define your variables that suggest their obvious function in your code.
Advice On How to Get Started
One of the first pieces of advice has been already mentioned; that is, naming your variables according to their fundamental purpose. A common misconception of categorically naming variables is how long or short you should entitle them. It is recommended that you do not inhibit the length of a variable, otherwise it will result in a misunderstanding of their function. Complex names or numerical signs aren't advised, since it might impede comprehension. Your variables should be simple and straight to the point.
Another important concept to remember is how our brains organize information and what triggers our memories. Now this is where it gets very interesting! As you continue to practice naming variables, your brain commences organizing the names with their significance. What exactly does that mean? Well, let me provide an example.
First lets consider that variable we previously decided to symbolize our I/O port going to an LED. As part of our application, the LED will continuously blink to inadvertently represent a sophisticated security system that will keep predators away by bluffing. After contemplating on the hardware and requirements for our simple application, we come to the conclusion that only one LED is required for an effective solution. Therefore, we could name our variable simply as LED, but only due to the fact that one LED is being used. If this is your first coding project and you need assistance, then whoever is helping you can automatically connect with what you are doing by using that variable name. The name implies that you are controlling an LED as part of your hardware on your I/O pin. To confirm this assumption, anyone who is helping you can quickly glance in your #define section and see whether you set it as your output port (TRIS or GPIO, depends on PIC). If you had used the name TNT, a persons brain wouldnt emphasize remembering that name in association with its function because its completely irrelevant.
Triggers
If you wanted to remember a meeting you have at 12:00 PM, you can think of noon or lunch to prompt a trigger. Whenever you think of those words, it will effectively stimulate a thought that indicates you have a meeting at that time. Therefore, try to organize specific triggers that might stimulate thoughts relevant to your variable name. This is a useful trick when you adjust your code in the future; since you will be more likely remember the variable names and what they do. Likewise, try to think of variable names that might trigger accurate functions in your code so that others may easily understand it.
Now you see how important it is to appropriately and effectively name your variables, for your benefit and for other peoples as well.
Any suggestions, comments, or advice is encouraged!