Naming Text constants, the 2013 R2 way?

Johannes_NielsenJohannes_Nielsen Member Posts: 206
edited 2014-05-22 in NAV Three Tier
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.
Best regards / Venlig hilsen
Johannes Sebastian
MB7-840,MB7-841

Answers

  • Marije_BrummelMarije_Brummel Member, Moderators Design Patterns Posts: 4,262
    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. :mrgreen:
  • tinoruijstinoruijs Member Posts: 1,226
    Good to know. Thanks for sharing. :thumbsup: I did not notice it yet.

    Tino Ruijs
    Microsoft Dynamics NAV specialist
  • Miklos_HollenderMiklos_Hollender Member Posts: 1,598
    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?
  • Johannes_NielsenJohannes_Nielsen Member Posts: 206
    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-841
Sign In or Register to comment.