Scroll To Bottom Mystery Master Coding Standards Member

Detective

Coding standards are a set of guidelines, best practices, programming styles and conventions followed by developers. Because I do not strictly enforce coding standards, I will instead say coding preferences. Most of my programming is in the "bracing" languages: JavaScript, PHP, Java, and C#. Some of my preferences may not apply to every language.

General Preferences
  1. I use a tab for indentation, and I keep tabs in my source code. If able to, I set tabs to indent three spaces.
  2. I set a visual limit of 100 characters for lines. I don't always enforce a line limit because I usually turn on word wrap.
  3. I usually have one statement per line.
  4. I terminate a statement with a semicolon even if the semicolon is optional.
  5. I provide scope (private, public) as much as possible.
  6. The scope of a variable does NOT influence its name.
  7. I avoid using this. It's required when a class name has the same name as a private variable or parameter.
  8. The starting brace is NOT on its own line, whereas the ending brace is on its own line.
  9. I define classes, methods and variables as static if it makes sense.
  10. I use get/set in JavaScript and C#. Good stuff.
Naming Preferences
  1. A class name is a singular noun in PascalCase. Examples: Customer, CustomerPurchase.
  2. A file usually contains one class, and has the same name as the class.
  3. A variable name is camelCase. Examples: customer, customerPurchase.
  4. A variable representing an array of class objects is pluralized. Examples: customers, purchases.
  5. A real constant is all uppercase, and may have an underscore. Example: const MAX_LINES = 1000;
  6. I use Hungarian Notation ONLY for visual fields (usually HTML and JavaScript). Examples: txtMessage, btnSubmit.
Brace For Impact

Not everybody will agree with my preferences, especially when it comes to braces. Look at the following two Basic-like examples, and see which one you prefer.

Example 1 Example 2
if triState is 0 then
	doThing0()
else if triState is 1 then
	doThing1()
else
	doThing2()
end if
						
if triState is 0
then
	doThing0()
else
if triState is 1
then
	doThing1()
else
	doThing2()
end if
						
Tools

When I program in JavaScript, I need all the help I can get. The following tools are very helpful.