Ask Reuben 13 - No More Globals

Started by Reuben B., April 29, 2020, 05:29:30 AM

Previous topic - Next topic

Reuben B.

Does your code make use of GLOBALS, and do you find maintaining that code can be troublesome?   To increase code re-usability and readability, use modular concepts and define PUBLIC variables in one or more modules that are imported into other modules as required with the IMPORT FGL instruction.  In short ...

Code (genero) Select
GLOBALS "filename.4gl"

... can be replaced with ...

Code (genero) Select
IMPORT FGL fileName


... and in this module, the GLOBALS keyword ...

Code (genero) Select
GLOBALS
DEFINE variableName dataType
END GLOBALS


... can become ...

Code (genero) Select
PUBLIC DEFINE variableName dataType

You can split your monolithic globals file into one or more smaller modules as required, and only reference the appropriate modules.

Read more at https://4js.com/ask-reuben/ig-13/
Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero