Ask Reuben

AS (Alias)

How can I avoid typing a long module or package name?

Occasionally in maintenance releases we will add some new syntax rather than waiting for a major release.  If you look in the What is New in 4.01 documentation there is an entry …

Starting at 4.01.02
Module aliases with IMPORT FGL path AS alias-name

The IMPORT FGL syntax has been enhanced  so that you can define an alias for module and package names.

So instead of …

IMPORT FGL a_big_long_name_that_is_a_pain_to_type
DEFINE var a_big_long_name_that_is_a_pain_to_type.my_type
CALL a_big_long_name_that_is_a_pain_to_type.my_function()

… you can code this as …

IMPORT FGL a_big_long_name_that_is_a_pain_to_type AS short_name
DEFINE var short_name.my_type
CALL short_name.my_function()

Particularly with package names that may have a name that represents a deep directory structure, you can create an alias, and avoid repeatedly typing the long package names.

You may also have a coding standard that prefixes filenames, you can use the alias to remove the prefix.

As illustrated by the example entry in the Issue Tracker, the use of alias can also reduce ambiguity

IMPORT FGL Financials.GeneralLedger.Models.Account AS GLAccount
IMPORT FGL Financials.ProjectLedger.Models.Account AS PLAccount
CALL validate -- ambiguous
CALL Account.validate() -- ambiguous
CALL GLAccount.validate() -- preferable
CALL Models.Account.validate() -- ambiguous
CALL Financials.GeneralLedger.Models.Account.validate() -- lengthy and would like to avoid
CALL GeneralLedger.Models.Account.validate() -- is still too lengthy

Within the editor this alias is recognised by code completion, real time syntax checking etc, and so you can these aliases as if they were the actual module or package name.

Hopefully you recognise that this makes the code more readable and can improve your effectiveness when reading and maintaining code.