Understanding boolean values

Miklos_HollenderMiklos_Hollender Member Posts: 1,598
edited 2007-08-24 in NAV Tips & Tricks
I'm posting this because I'm a bit of tiring looking at code written like:
IF Amount>0 THEN BEGIN
   CurrReport.SHOWOUTPUT(TRUE);
END ELSE BEGIN
   CurrReport.SHOWOUTPUT(FALSE);
END;

As any expression that contains comparision operators returns a boolean value and a boolean value is what SHOWOUTPUT wants, it's a lot cleaner, simpler and more readable to write it as:
CurrReport.SHOWOUTPUT(Amount>0);

Similarly, functions that return boolean values can be simply used everywhere a boolean value is needed without assigning them to a variable. (Note: it's a good practice to name boolean functions as one would word the answer to yes/no question: ParentOrderExists, IsNegative, BalanceIsOverCreditLimit, etc.)

So if you have a function called BalanceIsOverCreditLimit then you can just
CurrForm.Name.UPDATEFONTBOLD(BalanceIsOverCreditLimit(Rec));

This improves readibility a lot.

Comments

  • krikikriki Member, Moderator Posts: 9,094
    I definitely agree!

    But it is not so easy to let others use it.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSterDenSter Member Posts: 8,304
    This improves readibility a lot.
    I have to disagree with you, because you're making the wrong assumption. For most people in the NAV world, optimum readability is the first example you gave. You just do not seem to understand that this world is not filled with "real" developers, but mostly with very smart business people that are scripting their way through.
  • SavatageSavatage Member Posts: 7,142
    I am far from being any kind of code master, it would be great to have you or whomever write/cleanup the code so others can see the different ways it can be done.
  • kinekine Member Posts: 12,562
    I agree with Miklos, but I know that it is not so easy for people without programming background to do it in this way. Of course, for me it is incorrectly coded (the first example) because I have long experiences and university for that (where we had negative points for such a code... :D ) but I know that most NAV developers are from other areas and I must to live with it... 8)

    same example is
      If something = true then
    ...
    
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • vytjakvytjak Member Posts: 36
    I'm posting this because I'm a bit of tiring looking at code written like:
    IF Amount>0 THEN BEGIN
       CurrReport.SHOWOUTPUT(TRUE);
    END ELSE BEGIN
       CurrReport.SHOWOUTPUT(FALSE);
    END;
    

    I double that...
    Vytenis Jakas
    B3 Technologies - Making Technology Serve the People
Sign In or Register to comment.