Language Modernization ideas for discussion - Idea 5 - Private Globals

Started by Eric B., January 25, 2021, 11:57:47 PM

Previous topic - Next topic

Eric B.

Next idea:  "Private Globals".  This is a ripoff of the concept of static variables in other languages.  Although it doesn't really add new functionality, I think it would considerably improve organization and readability of code.  Basically this implements a private function variable that retains it's value globally/after the function exists.  This could be use for factory functions and similar.  I'd think something like "GLOBAL DEFINE x" to declare it.

For instance, you'd have:
Code (genero) Select
FUNCTION getGlobalCount()
   GLOBAL DEFINE counter

   LET counter = counter + 1
   RETURN counter
END FUNCTION
...

MAIN
   DISPLAY getGlobalCount()   # 1
   DISPLAY getGlobalCount()   # 2
END MAIN


The main benefit here is that the variable and its usage are kept together if it is managed by a single function.  As such it's more of a readability assist; the behavior would be no different from declaring a module-level private variable with the added protection that the compiler would prevent multiple functions in the same module from manipulating the variable.

Sebastien F.

Hello,

The idea is clear, thanks for the suggestions.
I have filed this request as FGL-5524 (not visible in the issue tracker for now)
Will be discussed internally, having a ticket does not mean it will be done.

I would not use the concept "GLOBAL" because this is well know for global variables visible to all functions.

Seb

Rene S.

Hello colleagues:
you're not asking for "private globals", you're asking for (C-speaking) static local variables (or none auto local variables).
I would not name this "language modernization". Modern languages like Java or Google-Go don't know none auto local variables.
I don't see any reason for supporting this request in Genero-4GL. There really no added value.
Rene