This last item in my
NAV2013 Beta to RTM - Some Striking Code Changes series is addressing code changes NAV core team made to get IF-THEN-ELSE statements coding standards compliant.
If you read the
Microsoft Dynamics NAV 2009 Developer and IT Pro Documentation on
IF-THEN-ELSE, and also on the
use of parentheses, you'll notice that there are quite some conventions to take into account. Quite some to violate, isn't it?
Let's take some exemplar code changes that underline these conventions. It think it's a good way to refresh your coding standards knowledge, like most of the previous posts in this series could have done that somehow.
1. EXIT or ERROR as last statement in the THEN part of an IF-THEN-ELSE?
Do not continue with an ELSE statement
Correct
IF <Condition> THEN
<Statement Block ending with ERROR or EXIT>
<Statement>
Incorrect
IF <Condition> THEN
<Statement Block ending with ERROR or EXIT>
ELSE
<Statement>
Click on the image to get a full view that's readable.
2. Compound or long expressions after IF?
THEN should be on a new line and aligned with IF
Correct
IF <Condition1> AND
<Condition2>
THEN
<Statement>
...
Incorrect
IF <Condition1> AND
<Condition2> THEN
<Statement>
...
Click on the images to get a full view that's readable.
Note
This also applies to the DO part of a WHILE-DO statement
3. Use parentheses only to enclose compound expressions inside compound expressions
I.e. do not use redundant parentheses.
Correct
IF Boolean1 AND Boolean2 AND (x = y) THEN
<Statement>
...
Incorrect
IF ((Boolean1) AND Boolean2 AND (x = y)) THEN
<Statement>
...
Click on the images to get a full view that's readable.
Note
This also applies to WHILE-DO and CASE statements
Читать дальше