I’ve been making some changes in one of my projects that have multiple timers, I use timer1.mode = 0 for off, timer1.mode = 1 to simgle and timer1.mode = 2 for multiple, when I look in the examples did not see the use of 0, 1 and 2 being used but modeoff or modesingle, I ask, do the numbers not being used?
I can tell you from my own projects of 15 years, and dealing with Other Peoples Code that both styles are ‘correct’, but using the wordy constant is more readable at a glance. Remember, you’re writing your code not only for now and six weeks from now but six years from now.
If you have to go look up what a number means in the documentation you’ve already lost. Timers are easy, since we use them all the time and there are only 3 choices, but there are other parts of the framework that are used less often that have more choices. Go for the readability.
As a side point, I despise the default control names. In your example, the timer1 name tells me nothing about its function. tmrOpenDelay, or tmrOneShot tells me something. I strongly suggest getting into the habit of naming your controls and making the names consistent. Again, the school of hard knocks tells me that this is a better approach than using the default control names. I’ve had to work on Other Peoples Code projects with a window full to TextFields with names from TextField1 up to TextField50 and literally had to go in and look at the code to figure out their function. Name them something meaningful and give your future self a break.
@Bob Keeney Excellent post! May I add just to include always a comment at the very first line of the method/event/computed property to explain what this method/etc… actually does and what do you expect. With these in mind, beautiful code and takes less than 21days ( habit time ) to follow Yoda.
I would change this to say make method names meaningful and use comments to make things explicitly clear. We usually have Load, Save, Validate methods. No need to put a comment telling someone what they do because the method name is abundantly clear. If I happen to have more than one load-type method I’ll usually break it down into something like Load_ListBox, Load_PopupMenu to make it more obvious. Same thing with Save and Validate.
Comments for the sake of comments irritate me. I fired a developer, once, that put a comment on every simple line of code but then failed to add any comments on a piece of complex code. Comments should be timely and useful - not there for the sake of looking pretty.
BTW, search my blog at http://www.bkeeneybriefs.com. I’ve talked about this topic, and many others, over the last 8 years.
Bob, I understand your point of view but I did not say that my timer is called timer1, timer2, etc … I just made a placement of calls from 0, 1 and 2, because I do not think this to be a problem because like you even spoke are only three numbers, regarding timer, listbox, buttons agree that the names have to make sense but this was not my question.
[quote=215719:@Paulo Vargas]Bob, I understand your point of view but I did not say that my timer is called timer1, timer2, etc … I just made a placement of calls from 0, 1 and 2, because I do not think this to be a problem because like you even spoke are only three numbers, regarding timer, listbox, buttons agree that the names have to make sense but this was not my question.
I thank for your attention ![/quote]
While 0 1 and 2 will work I would, as part of regular updating of code, use the named constants