Not too long ago, I followed one of Steve Endow’s amazing livestreams where he was talking about BC Coding Guidelines together with Henrik and Jeremy. And what I noticed was that it appeared to be that “coding guidelines” – whatever they are for you – are hard to find – at least if you’re searching for guidelines in the new AL Language. I was like, wait a minute, I know I have been talking about that for a LOT during sessions and on blogs .. and others must have as well .. but when searching .. it appeared to be not *that* much at all, and usually not in the right context. So, my assumptions were wrong, and the necessity of that session, in my opinion, is high!
Before I continue with the actual topic, there is one thing I need to highlight from that session. Well, in fact, there are more, but just watch the entire session here:
What I wanted to highlight is the site Jeremy created: CAL Rules Review (sparebrained.com). It’s a site that will share C/AL guidelines – of which many are still quite interesting today in AL – and even lets you vote about some guidelines as well. Check it out!
So – there are barely any guidelines online, and the ones there are, are old, or hard to find. Well, recently, I did a session at DynamicsCon about “How do I manage my Dev team” (at the time of this post, it’s not on YouTube just yet), and part of managing the team, IS applying development guidelines.
So why not go deeper into the topic, and share whatever I find important within my company on my blog.
And I thought it was a good idea to kick off with a treasure of information that got buried over time. A community project I’m proud to have been part of. Something I still think is valuable, even in the world of AL. A project that was baptised with the name …
The NAV Design Patterns Wiki
You can find the wiki here: https://community.dynamics.com/nav/w/designpatterns
And you might wonder: why bring that old stuff up? It was a community project that has been abandoned, that isn’t being updated or maintained anymore. And you are right.
It’s still an awesome list of patterns, written by quite some people that put a great deal of time into it. They put time into, first of all, document the patterns of default NAV, and second of all, they came up with a great deal of new patterns that can help in many situations. It’s documented, and I believe that many of them are still very valid even today. Not all – and you’ll need to decide which ones don’t! But I’m telling you: many still are very valid today!
I was actually surprised that it got so little attention during Steve’s talk. Sure, it’s pretty old, but so are the C/AL guidelines from the so called “old guidebook” ;-). May be the only reason why I’m so passionate about this project is because I was part of it, and I loved spending time on it ;-).
Jeremy mentioned the current state of the site was bad. It was very difficult to navigate. And he is totally right. It’s an absolute nightmare to navigate, since on the main pages, there isn’t really good information (only an attempt for a tagged list, basically). The really interesting information you can find in the menu on the right, ONLY when you click the arrows, not the links. You really need to click the tiny triangles to expand the list on the right. And even when you select one item of that list, it would collapse back .. . Again, it’s a nightmare! Let’s just think of it like “internet erosion” over time .. 😉.
To save you the trouble and help you navigate to those pages, I decided to copy/paste the list right here, where every single link will navigate back to the original wiki, including comments, and the original author.
Just have a look at this treasure of information:
.NET Exception Handling in C/AL
– TryFunction – .NET Exception Handling in C/AL
– Data-driven Blocked Entity
Cached Web Service Calls
Conditional Cascading Update
Create Data from Templates
Create URLs to NAV Clients
Creating Custom Charts
Cross Session Events
Currently Active Record
Data Migration Façade
Easy Update of Setup or Supplementary Information
Error Message Processing
Extending the Role Center Headlines
Feature Localization for Data Structures
Implementation of surrogate keys using AutoIncrement pattern
Instructions in the UI
Integration of Addresses
Journal Error Processing
Multilanguage Application Data
– In-context notifications
Posting Routine – Select behavior
– SELECT DISTINCT with Queries
– Use Queries to Detect Duplicate Records
– Use Queries to replace Nested Loops
Read Once Initialization and Validation
1. Sensitive Data Encapsulation
2. Data Encryption
3. Single Point of Access
4. Masked Text
5. SSL in NAV
Setup Specificity Fallback
Silent File Upload and Download
– Singleton Codeunit
– Singleton Table
— Cue Table
— Setup Table
Temporary Dataset Report
Totals and Discounts on Subpages (Sales and Purchases)
Transfer Custom Fields
C/AL Coding Guidelines
- By Reference Parameters
- Class Coupling
- Cyclomatic complexity
- Encapsulate local functionality
- FINDSET, FINDFIRST, FINDLAST
- Initialized variables
- Maintainability index
- Parameter placeholders
- Static object invocation
- Unreachable code
- Unused initialized variables
- Unused variables
- Variable capacity mismatch
- WITH scope name collision
Internally used Dot Net Types
- CaptionML for system tables
- FIELDCAPTION and TABLECAPTION
- Global Text Constants
- Use Text Constants
- Using OptionCaptionML
- BEGIN as an afterword
- Binary operator line start
- Blank lines
- CASE actions
- Colon usage in CASE
- Comments: curly brackets
- Comments: spacing
- END ELSE pair
- Keyword pairs indentation
- Line-start keywords
- Lonely REPEAT
- Named invocations
- Nested WITHs
- One statement per line
- Separate IF and ELSE
- Spacing: binary operators
- Spacing: brackets and ::
- Spacing: unary operators
- Temporary variable naming
- TextConst suffixes
- Unary operator line end
- Unnecessary Compound Parenthesis
- Unnecessary ELSE
- Unnecessary Function Parenthesis
- Unnecessary separators
- Unnecessary TRUE/FALSE
- Variable already scoped
- Variable naming
- Variables declarations order
As I mentioned – it’s not made for AL – it was even created when there wasn’t even any notion of AL. Even the concept of “events” was even VERY new at that time, as far as I remember.
One example is the Hooks pattern, which was one of my personal favourite patterns that got completely useless now that we have events and extension objects..
You will kind of have to decide what will be valid for you and what not.
But in my opinion, it’s a great way to start sharing about AL guidelines. This was just a first post – I’m planning more posts in the near (further 😉) future about guidelines that we apply in our company to keep our software under control. No promise (my wife says I’m bad in keeping promises), but an attempt .. ;-).
I have been on the site (NAV Design patterns) a few times and honestly the info there is invaluable (treasure). I hope you get the chance to do more posts on AL Coding Guidelines because I really enjoy your blog posts.
Thanks so much – really appreciate it!
Still a valuable resource, thanks for bringing it on the front line. Pattern are in the heart of the product since the early beginning : a reliable way to offer consistency in UX and in under the hood of course.
It was a pleasure for me to document… the document pattern 🙂