Reformat keyboard.js to use booleans instead of integers#1
Reformat keyboard.js to use booleans instead of integers#1JoshClark431335 wants to merge 1 commit intoHomeMadeGaming:masterfrom
Conversation
Case statements make parsing data like this a lot easier in the long run. Neater to read and understand and not nearly as many if statements. A lot shorter too. You don't have to scroll through a bunch of junk now. You will have to change the main file as well but that's just a simple search and replace.
There was a problem hiding this comment.
Capitalized the boolean names because at least "left" and "right" are keywords when left in lowercase. Javascript is case sensitive so changing capitalization makes it a different word.
There was a problem hiding this comment.
I agree with the boolean type variables. They are much more efficient. However, it is standard javascript that nothing be capitalize, NEVER. This is to avoid the confusion of having to remember "Left" is capital L, not lowercase. And face it, after calling it enough times you're inevitably going to forget to hit the shift key. By leaving everyting lowercase, this is never an issue. The only time I ever capitalize is when a variable is a combination of two words, like in the method "getElementById". If you notice, all javascript methods and properties work this way so by following the same pattern there is no confusion.
This is why I had such a hard time adding audio to your pong file. It is the only time I was required to link to a file with a capitalized name. Notice, all my files are lowercase.
There was a problem hiding this comment.
Leaving variables lowercase or uppercase is personal preference. That's not necessary for it to run, but it is commonly agreed by convention to follow a certain pattern. The reason you like to use all lowercase is because you're used to doing lowercase. If you did it all with the the first letter capitalized you would find that normal. Some variables are in all caps however so that is aside from the point. The reason i wanted the first letter of each word in the variable names capitalized, aside from avoiding keywords, is because it would follow the same rule as variables with multiple words. It doesn't really matter which way we do it because the name of it is not going to make it stop working unless it breaks syntax. We do need to pick a naming convention though and keep it consistent. Capitalizing the first letter of each word in a variable name is quite common actually, although it may depend on the variable type. Sometimes people like to leave booleans in all caps to distinguish them from integers of the same or similar name. We can make it all lowercase if you want, but for the "left" and "right" names at least we can't and it should be consistent across all variables of the same type.
There was a problem hiding this comment.
I recognize there is variety in nomenclature in the programming community, but among the javascript community I've read in multiple articles that the popular nomenclature is all lowercase.
|
All of the forums that i go to when finding out how to do things are all the first capitol rule. As I said, I don't think it matters just as long as we stay consistent. |
Case statements make parsing data like this a lot easier in the long run. Neater to read and understand and not nearly as many if statements. A lot shorter too. You don't have to scroll through a bunch of junk now. Booleans also make more sense in this context because all you need is an on state and an off state, which is exactly what a boolean does. It also uses a lot less memory because all it takes up is one bit instead of several bytes for an integer. You will have to change the main file as well but that's just a simple search and replace.