Naming Text constants, the 2013 R2 way?

Johannes_Nielsen
Member Posts: 206
Just wanted to share this with anybody who writes C/AL.
I've always deviated from the standard way of naming Text constants (Text001, Text002).
Because it makes the code harder to read, and gives me no real benefits, except really fast naming
This should be the only place where I don't match the base application. I've allowed myself this since the Programming Guide does'nt tell me what to do, when naming Text Constants
http://msdn.microsoft.com/en-us/library/ee414213(v=nav.71).aspx
-
So I've opted for the "tcYouCannotXWhenY" style.
tc = Text constant
"YouCannotXWhenY" = A descriptive text means that I have some idea of the contents of the constant.
"X" and "Y" = I know there are two parameters and I know how they are related (ish)
-
I've discovered that in NAV 2013 R2, MS has ditched the "Text001" style themselves.
So it should be legal for everybody to abandon the old style.
See Codeunit objects 1200..
Abb. like "Err", "Cap" "Qst" and "Txt" has been added to the end for text constant names , somewhat consistently.
To indicate the function of the constant. I might adopt this.
I've always deviated from the standard way of naming Text constants (Text001, Text002).
Because it makes the code harder to read, and gives me no real benefits, except really fast naming

This should be the only place where I don't match the base application. I've allowed myself this since the Programming Guide does'nt tell me what to do, when naming Text Constants
http://msdn.microsoft.com/en-us/library/ee414213(v=nav.71).aspx
-
So I've opted for the "tcYouCannotXWhenY" style.
tc = Text constant
"YouCannotXWhenY" = A descriptive text means that I have some idea of the contents of the constant.
"X" and "Y" = I know there are two parameters and I know how they are related (ish)
-
I've discovered that in NAV 2013 R2, MS has ditched the "Text001" style themselves.
So it should be legal for everybody to abandon the old style.
See Codeunit objects 1200..
Abb. like "Err", "Cap" "Qst" and "Txt" has been added to the end for text constant names , somewhat consistently.
To indicate the function of the constant. I might adopt this.
Best regards / Venlig hilsen
Johannes Sebastian
MB7-840,MB7-841
Johannes Sebastian
MB7-840,MB7-841
0
Answers
-
Yes, this was an internal change in Dynamics NAV. From now on all new messages will have this way of naming.
The reason we had Textxxxx was because of the tool used 1.5 decades ago to move from hardcoded messages to text constants.
Only took 15 years to move to a smarter system.0 -
Good to know. Thanks for sharing. :thumbsup: I did not notice it yet.
Tino Ruijs
Microsoft Dynamics NAV specialist0 -
Johannes Nielsen wrote:This should be the only place where I don't match the base application. I've allowed myself this since the Programming Guide does'nt tell me what to do, when naming Text Constants
I wondered why do you care so much about it... for me anything that makes sense and is generally readable to other programmers is OK. I guess you must be in the add-on business, not customizations and thus have to care about the guide in order to get it certified?0 -
Why I care about best coding practices?
Makes my life easier and less stressful by making code easier to maintain.
Yes, I primarily maintain Add-ons at the moment.
With Add-ons, every sloppy thing you do, generally comes back and bites you. You have to maintain every inch of the product in years to come, so you can save a lot of time in the long run.
The certification requires a code quality check "Impuls Check tool" https://www.impuls-solutions.com/Pages/1048.aspx
which barks about unused variables, not naming Temporary records variables "temp" or "buffer".
For customers, I don't go all the way to make everything polished, but I do keep a level so I have a better chance at doing changes to the same code, later.Best regards / Venlig hilsen
Johannes Sebastian
MB7-840,MB7-8410
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