Coding style

Thomas Templemann wrote a nice blog post about his preferred coding style guidelines.

And most I absolutely agree with.

Except one.

His suggested style is to test booleans simply for the value they hold and not to test for TRUE or FALSE explicitly. He considers testing for TRUE or FALSE bad style. Examples of bad style are :

if hidden = true then ... // bad style
end if
if hidden = false then ... // bad style
end if

Instead he suggests using good names and the following style

if isHidden then ... // good style
end if
if not isHidden then ... // good style
end if

Personally I find that sometimes picking a “good name” so things read like an English sentence can be challenging and that any code you get from someone else may not adhere to the “good name” principle.

As of late I’ve been working in a lot of code written in German. All the variable names, controls, etc are German. And so nothing reads well to me since I don’t read German.

So I prefer a style like

if einigeWirklichSchrecklicheVariablennamen = true then ... 
end if
if a这儿没有发布参数和返回值 = false then ... 
end if

All this said whatever style you use stick to it and use it consistently throughout your code. Use Thomas’s if you like them and they work for use. Or those from BKeeney. Or write your own set, try them out and work with them and tweak them until they make code easier to write AND easier to read and comprehend when you’ve been away from it for months at a time.