Coding standards

rsaritzky
Member Posts: 469
Hi all,
I'm interested if anyone has either read any coding standard documentation (I've checked the NAV coding guidelines), found any references in any "Clean Code" documents, training, videos or blogs, etc. to state that either one of the following examples is "better". Certainly one is more "compact", but in a more complicated function, my interest is (a) debuggability and (b) readability:
Example 1 (this is in a function that in turn calls a function that returns a result TRUE or FALSE):
vs. writing it this way:
While the second option is more "compact", if I wanted to see the actual return value of the called function, I may not be able to trap for it.
The first option, although a few lines more of code, makes it easier to debug and trap for the value during debugging.
Now, this is a very simple example, but it illustrates what my question is - is there an established development standard one way or the other? Are there any references to that standard that you can point me to?
Thanks
Ron
I'm interested if anyone has either read any coding standard documentation (I've checked the NAV coding guidelines), found any references in any "Clean Code" documents, training, videos or blogs, etc. to state that either one of the following examples is "better". Certainly one is more "compact", but in a more complicated function, my interest is (a) debuggability and (b) readability:
Example 1 (this is in a function that in turn calls a function that returns a result TRUE or FALSE):
IF Item.IsAHomeInstallationKit THEN EXIT(TRUE); EXIT(FALSE);
vs. writing it this way:
EXIT(Item.IsAHomeInstallationKit);
While the second option is more "compact", if I wanted to see the actual return value of the called function, I may not be able to trap for it.
The first option, although a few lines more of code, makes it easier to debug and trap for the value during debugging.
Now, this is a very simple example, but it illustrates what my question is - is there an established development standard one way or the other? Are there any references to that standard that you can point me to?
Thanks
Ron
Ron
0
Answers
-
Ask 5 developers and you get 5 different answers, to a large degree this is totally subjective. For instance, I can't stand the one in your first example, it feels to me that it is missing ELSE. I find myself going the second example more these days. I never used to think about putting logic into reusable bits of code but that's almost at the front of my mind now.0
-
Hi,
There is no real "better" or "worse" in this case. However:
I and many others strongly prefer theEXIT(Item.IsAHomeInstallationKit);
- Shorter Syntax
- Makes it so your function has a single Exit - Statement, which is often desirable for readability and understanding
- The debugger should not be a reason to write your code a certain way (I mean during DEV thats fine, but not in production). Debugging Tools may and will change, your code probably won't.
- It's more expressive: if we want to return whether an Item is something, Exit(Item.IsSomething()) is the most expressive way to do so.
On a sidenote (and I know thats also a matter of personal preference) I would always make sure to actually use Paranthesis for readability. The AL formatter does this, in pretty much every other Language it is mandatory and it just makes sense imo.Exit(Item.IsSomething())
Austrian NAV/BC Dev0 -
Good explanation, but for me, both the ability to debug and "be expressive" (i.e. readable) is important. I also agree that we are somewhat limited by the current debugger - that you can't see the result of a function call. You can verify the value in code, e.g.
IF Item.IsSomething() = <somevalue> THEN...
But unless you store the result or have code to evaluate it, you can't "see" the value.
I'm a bit older than many developers here, so I come from the days of mainframe languages like COBOL and "structured programming" techniques (and the lack of debuggers), so to me, "readable" means something a bit different. But I appreciate the opinions.
RonRon0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K 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
- 320 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