Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: Language Modernization ideas for discussion - Idea 5 - Private Globals  (Read 10206 times)
Eric B.
Posts: 10


« on: January 25, 2021, 11:57:47 pm »

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
  1. FUNCTION getGlobalCount()
  2.   GLOBAL DEFINE counter
  3.  
  4.   LET counter = counter + 1
  5.   RETURN counter
  6. END FUNCTION
  7. ...
  8.  
  9. MAIN
  10.   DISPLAY getGlobalCount()   # 1
  11.   DISPLAY getGlobalCount()   # 2
  12. 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.
Four Js
Posts: 545


« Reply #1 on: January 28, 2021, 12:05:35 pm »

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.
Four Js
Posts: 112


« Reply #2 on: January 28, 2021, 02:22:01 pm »

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

Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines