PolarisProject / salesforceStyleGuide

Code style guide for Salesforce
GNU General Public License v2.0
26 stars 20 forks source link

Missing discussion items, things that could be said? #4

Open brianmfear opened 9 years ago

brianmfear commented 9 years ago

Non-comprehensive list of things you could address.

Some developers omit curly braces around loop and branching blocks if there is only one line-- if(blah) true; else false; versus if(blah) { true; } else { false; }. This should be brought up, and explicitly discouraged.

Usage of the ternary operator ?: -- when (or is it...) is it acceptable to use?

Usage of _ character in names -- when (or is it..) is it acceptable to use?

Usage of System.debug( ... ) statements. They should never be left in production code, as they can cost 45ms each time they're called, and that's assuming they don't do anything complex. They should be discouraged.

When should function variables be declared? Near the top of the function or nearer the use of the function?

Constructor versus inline initialization of member variables. Likewise for static members.

ckoppelman commented 9 years ago

I trust you about System.debug, but it'd be great to cite a source when writing that up. Got one?

brianmfear commented 9 years ago

I'll see if I can find anything recent. The Security Review team used to recommend removing debug statements from code, although I'm not 100% sure if that's in any current documentation. Regardless, I'm putting together an optimization guide that will cover rules like this. I'm not sure it needs to be a style guide thing, though. This falls more in the category of best coding practices and code optimization.

Szandor72 commented 8 years ago

Excellent points.

Ternary operator disrupts reading flow, I avoid it.

Any luck in finding an official resource for the system.debug statement?