Coding Style question

genericgeneric Member Posts: 511
Hello I’m wondering why some people write if statement the following way.
IF  Record."Some Boolean field" = TRUE then begin

end;

IF  Record."Some Boolean field" then begin

end;

Which one is easier to read? The second one is probably some millisecond faster or maybe the compiler is smart enough to remove the unnecessary " = TRUE" part.

Thanks.

Comments

  • DenSterDenSter Member Posts: 8,307
    Personal preference, I personally like the first one, and I would even put parentheses around the expression. Neither one is faster than the other, not even a millisecond.
  • ppavukppavuk Member Posts: 334
    I think - second is more standard, I use same. But definitely no difference for compiler :)
  • KYDutchieKYDutchie Member Posts: 345
    I prefer the first one. That clearly indicates to me that the programmer really intended this code.
    And I also like the parentheses especially when there are multiple conditions in the if statement.
    Fostering a homeless, abused child is the hardest yet most rewarding thing I have ever done.
  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    The second one is standard NAV way of coding.

    Using the standard way makes it easier for everyone in the community.

    It is also mandatory to use for the current CfMD certification for NAV2013...
  • DenSterDenSter Member Posts: 8,307
    The second one is standard NAV way of coding.

    Using the standard way makes it easier for everyone in the community.

    It is also mandatory to use for the current CfMD certification for NAV2013...
    I agree that the second is the standard way.

    I do not agree that this is easier for all, because to me, the first way of writing the code is easier to read. Overall I agree that adhering to a standard makes things easier, but to me that applies to naming conventions more than whether you use literal values in expressions, or whether you use BEGIN and END for single line statements.

    It might be mandatory, but I seriously doubt that there is a team of people that actually checks each line of code to make sure you don't evaluate boolean types against literal values.
  • kinekine Member Posts: 12,562
    You do not need people or that, they have automated tools... :-)
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
Sign In or Register to comment.