Understanding boolean values
Miklos_Hollender
Member Posts: 1,627
I'm posting this because I'm a bit of tiring looking at code written like:
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:
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
This improves readibility a lot.
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.
0
Comments
-
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!0 -
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.Miklos Hollender wrote:This improves readibility a lot.0 -
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.0
-
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...
) but I know that most NAV developers are from other areas and I must to live with it... 8)
same example isIf something = true then ...
0 -
Miklos Hollender wrote: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 People0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 326 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions


