AXForum  
Вернуться   AXForum > Microsoft Dynamics NAV > NAV: Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 09.10.2020, 21:12   #1  
Blog bot is offline
Blog bot
Участник
 
25,459 / 846 (79) +++++++
Регистрация: 28.10.2006
Navigate Into Success: Tip: Text constants in AL
Источник: https://vjeko.com/2020/10/09/tip-text-constants-in-al/
==============

Long time no see, but that’s how it gets every now and then, I guess… Anyway, I am still alive, still kicking, just don’t get to blog as much as I’d hope for, it’s work, and life and universe and everything.

So, I am back with not a typical “Vjeko” post, just a simple AL opinion piece. A tip, without a trick.

One of the problems we’ve all suffered from in the old days of C/AL (who remembers that still, anyway) was inability to define real text constants. One thing we all avoided was using hardcoded Text literals, like this:

It was not only about the sheer scariness of using Text literals in C/AL, stuff that if left unchecked could cause process issues, something nobody in the ERP world (especially those on the business end of it) likes. Arguably, the worst thing about this kind of code was total lack of reusability. If you had to reuse the literal, you would have to write it again:

Yeah, the mismatch (or typo, whatever you prefer) is intentional to prove my point. You could mistype it, or somebody may decide to change it and then forget to change it in all places, or… stuff happens, you know. It was no good.

There were no constants, and it sucked.

Yeah, yeah, there *were* TextConst constants, but that’s not it. The moment you did this:

… somebody could come in and “fix” it like this:

And there was no way for you to prevent them. There goes your discoverable extension, things break up and your users start yelling your way.

Back in those pre-historic days, I’ve seen people work around this problem like this:

The “constant” is coded in one place, other place call the wrapper function, and world goes on. That was the way to do it in C/AL, truly.

Fast forward back to present. I’ve got myself in the middle of refactoring a chunk of code migrated from C/AL to AL a while ago. It’s full of “pluggable” things that identify themselves to various discoverers, and it’s full of “constants” coded with this function-that-returns-a-hardcoded-literal pattern.

While this worked miracles in C/AL, in AL we actually have a far better way to handle this. Labels. Yeah, fells like I am discovering hot water or sliced bread or something, but please, for the record, don’t do this:

Instead, do this:

If you set the Locked property to true, you are making sure nobody inadvertently translates it, and you keep it a bit cleaner. This is especially true if you have multiple constants – listing them in your var block will be much cleaner than creating a function a piece.

Here endeth the lesson. No rocket science, just an easy one to document my train of thoughts for posterity. Everyone is entitled to my opinion, after all

Read this post at its original location at https://vjeko.com/2020/10/09/tip-text-constants-in-al/, or visit the original blog at https://vjeko.com. 5e33c5f6cb90c441bd1f23d5b9eeca34The post Tip: Text constants in AL appeared first on Vjeko.com.




Источник: https://vjeko.com/2020/10/09/tip-text-constants-in-al/
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Navigate Into Success: Codeunit interfaces in AL Blog bot NAV: Blogs 0 03.02.2019 00:14
Navigate Into Success: From C/AL to executable: how NAV runs your C/AL code Blog bot NAV: Blogs 0 06.10.2016 13:11
german_nav_developer: Catch Me If You Can – try-catch für .NET in C/AL Blog bot Dynamics CRM: Blogs 0 22.09.2014 11:00
Platform updates overview - 3.70.B - NAV2009 R2 Blog bot Dynamics CRM: Blogs 0 07.02.2011 22:06
Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 12:01.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.