| « Code only what you need right now??? | i++ vs. ++i » |
Variable Usage And Meanings
When you design your program, you need to figure out what sorts of storage you need, temporary or otherwise. For every piece of information you need to track, you will need to allocate a variable to store it.
I see a lot of people doing tricky things. Tricky things are bad because they are hard to understand, and because there is usually a simpler way to handle the situation. In this case, I am talking about assigning more than one meaning to a variable based on what it’s value is (context). For example, having a configuration parameter for some device, and because you know it’s maximum allowable range, adding an offset larger than that range to disable the parameter. It is almost never worth doing this. The programmer could just as easily add a boolean variable to contain the enabled state of the parameter. Adding a column to a database to support this extra variable associated to the parameter is really not that onerous a task, especially when it comes to decoding the variable and the confusion that will inevitably bring.