Should GLOBAL define variables?

This forum is dedicated to those who wish to suggest new features.
Questo forum è dedicato a chi desidera suggerire nuove feature.
Ce forum est dédié à ceux qui souhaitent suggérer de nouvelles fonctionnalités.
Post Reply
spotlessmind1975
Site Admin
Posts: 127
Joined: Fri Oct 06, 2023 8:25 pm

Should GLOBAL define variables?

Post by spotlessmind1975 »

[italian and french follow]

:arrow: english

Good morning everyone!

I'm not entirely sure it is a bug. The problem involves a form of "relaxation" of the syntax with the GLOBAL command. I'll explain. The GLOBAL command allows you to tell ugBASIC to consider a variable as "global": in other words, its value will be accessible both to the main program and to any (possible) procedure defined within it (take a look here). The syntax is:

Code: Select all

   GLOBAL variable
Now, the term variable indicates not only the name of the variable but also the type. In fact, it can be written

Code: Select all

   GLOBAL variable$
and the compiler will continue without problems. If not that, you can also write

Code: Select all

   GLOBAL variable AS STRING
and, likewise, the compiler will be fine with it. However, this second form seems to almost constitute a "promise" about the type of the variable, which is of no interest to the command because GLOBAL neither initializes the variable nor creates it. At this point the question I ask everyone is the following: is it GLOBAL that must be able to create the variable when it is mentioned? Or, is it the syntax that must change to avoid being able to indicate the type? Or, neither of the two?

:arrow: italian

Buongiorno a tutti!

Non sono del tutto sicuro che sia un bug. Il problema riguarda una forma di "rilassamento" della sintassi con il comando GLOBAL. Mi spiego meglio. Il comando GLOBAL permette di indicare a ugBASIC di considerare una variabile come "globale": in altri termini, il suo valore sarà accessibile tanto al programma principale quando a una qualsiasi (eventuale) procedura definita al suo interno (qui per un approfondimento). La sintassi è:

Code: Select all

   GLOBAL variable
Ora, il temine "variabile" indica appunto non solo il nome della variabile ma anche il tipo. Infatti, si può scrivere

Code: Select all

   GLOBAL variable$
e il compilatore andrà avanti senza problemi. Se non che, si puo scrivere anche

Code: Select all

   GLOBAL variable AS STRING
e, allo stesso modo, al compilatore andrà bene. Tuttavia, questa seconda forma sembra costituire quasi una "promessa" sul tipo della variabile, che invece non è di interesse per il comando perché GLOBAL non inizializza la variabile né la crea. A questo punto la domanda che pongo a tutti è la seguente: è GLOBAL che deve poter creare la variabile quando viene citata, è la sintassi che deve cambiare, per evitare di poter indicare il tipo, oppure nessuna delle due cose?

:arrow: french

Bonjour!

Mais je ne suis pas entièrement sûr que ce soit un « bug ». Le problème implique une forme de « relâchement » de la syntaxe avec la commande GLOBAL. Je vais t'expliquer. La commande GLOBAL permet d'indiquer à ugBASIC de considérer une variable comme "globale" : autrement dit, sa valeur sera accessible à la fois au programme principal et à toute procédure (éventuelle) définie en son sein. La syntaxe est :

Code: Select all

   GLOBAL variable
Désormais, le terme « variable » indique non seulement le nom de la variable mais aussi le type. En fait, on peut écrire

Code: Select all

   GLOBAL variable$
et le compilateur continuera sans problème. Sinon, vous pouvez aussi écrire

Code: Select all

   GLOBAL variable AS STRING
et, de même, le compilateur s’en chargera. Cependant, cette seconde forme semble presque constituer une "promesse" sur le type de la variable, ce qui n'a aucun intérêt pour la commande car GLOBAL n'initialise ni ne crée la variable. A ce stade, la question que je pose à tout le monde est la suivante : est-ce GLOBAL qui doit pouvoir créer la variable lorsqu'elle est mentionnée, est-ce la syntaxe qui doit changer, pour éviter de pouvoir indiquer le type, ou aucun des deux ?
User avatar
wysardry
Posts: 23
Joined: Sun Oct 08, 2023 6:45 pm

Re: Should GLOBAL define variables?

Post by wysardry »

I would prefer a flexible syntax where each parameter is optional. I would also like the option to define the value of a variable when declaring it as global.

Something like:-

Code: Select all

GLOBAL greeting AS STRING = "Hello there."
or

Code: Select all

GLOBAL greeting$ = "Hello there."
See Global in the PureBASIC documentation for an existing example of this. I dislike the dot notation though.
User avatar
wysardry
Posts: 23
Joined: Sun Oct 08, 2023 6:45 pm

Re: Should GLOBAL define variables?

Post by wysardry »

I've thought about this some more and have come up with another option: GLOBAL could be stated as part of the variable type declaration.

Code: Select all

VAR sometext AS GLOBAL STRING
DIM AS GLOBAL INTEGER numberlist(16)
Post Reply