Page 1 of 2
Globalize - EndGlobalize ::: Quickly define a lot of vars
Posted: Sat Sep 08, 2007 10:45 pm
by AND51
Hello!
You all know
Enumeration -
EndEnumeration which allows you to enumerate constants quickly.
What do you think about
Globalize -
EndGlobalize in order to define a lot of variables at once that should be global?
The combination Global-EndGlobal is already in use (as
Global already exists), so 'globalize' should be the keyword.
Example:
Code: Select all
Globalize
mutex_einstellung=CreateMutex()
mutex_cache=CreateMutex()
mutex_logfiles=CreateMutex()
mutex_screenshots=CreateMutex()
mutex_favourites=CreateMutex()
flag_cache
flag_logfiles
OtherGlobalVariables=5
EndGlobalize
Posted: Sun Sep 09, 2007 12:26 am
by nco2k
well, personally i dont need it, because i always use a structure for all my global stuff. having many global variables laying around, is imho not a good way of coding anyway, thats why i prefer the structure way.
Code: Select all
Structure GlobStruct
VarA.l
VarB.l
VarC.l
EndStructure
Global GlobVar.GlobStruct
GlobVar\VarA = 100
Debug GlobVar\VarA
c ya,
nco2k
Posted: Sun Sep 09, 2007 12:41 am
by AND51
It's a good idea you present.
1)
But in your case, you had to write GlobVar\ in front of every "variable". This means that coders have to write more.
2)
Another drawback of your workaround is that you cannot assign values when declaring. You can only save values to your variables when you've finished declaring.
Annoying: When declaring variables of the default-type Long, you have to append .l anyhow.
3)
When declaring variables on "my way", the variables would also appear in the autocomplete-list of the IDE.
> having many global variables laying around, is imho not a good way of coding anyway
Where is the difference between many global variables and one structured global variable?
And it still depends on the coder, if his "way of coding" is good or not, so please do not put a comment on this; this "reason" does not play a role in this discussion.
Posted: Sun Sep 09, 2007 1:22 am
by nco2k
@AND51
> Where is the difference between many global variables and one structured global variable?
look at your 1) thats exactly the difference/feature, that you actually have to write GlobVar\ in front of every variable, so you know at first sight, that the var is global. and by the way, if you want to give your vars a meaningful naming, you will also have to write more.
> Another drawback of your workaround is that you cannot assign values when declaring.
the only plausible reason, but personally i dont have a problem with that.
> Annoying: When declaring variables of the default-type Long, you have to append .l anyhow.
thats a missing feature. i already requested to make declaration in structures optional.
> When declaring variables on "my way", the variables would also appear in the autocomplete-list of the IDE.
thats a missing feature aswell, as far as i can remember jaPBe doesnt have that kind of problems.
> And it still depends on the coder, if his "way of coding" is good or not.
not really, thats what references are made for.
i was just giving my 2 cents, sorry about that. it wont happen again.
c ya,
nco2k
Posted: Sun Sep 09, 2007 2:56 am
by PB
You don't need to have one Global per code line, if that's what you're trying
to avoid? Just put several on one line. You can also assign them values when
declaring too. Look at the following example.
Code: Select all
Global mutex_einstellung=CreateMutex(), mutex_cache=CreateMutex(), mutex_logfiles=CreateMutex()
Global mutex_favourites=CreateMutex(), flag_cache, flag_logfiles, OtherGlobalVariables=5
Procedure Test()
Debug OtherGlobalVariables ; Returns 5
EndProcedure
Test()
Posted: Sun Sep 09, 2007 11:18 am
by AND51
Hello PB!
I already know this feature and I'm using it very often.
But the fact is, that having a Globalize-Section makes your code more clear.
No 'Global' in front of variables and no commas behind variables.
Just like constants within an Enumeration-Area. An Enumeration-Area is also very tidy, so that you have a great overview over all constants.
I don't say that this feature has the highest priority, butI think it would be nice to have this feature implemented, just to give the coder more comfort.
I'm also satisfied if the PB Team says, "OK, we accept this request, but we put it at the bottom of the TODO list."
Perhaps, more PB users can give us their opionion?

Posted: Sun Sep 09, 2007 11:49 am
by freak
I think crowding up the language with such keywords just for the sake of lazyness is not a good idea.
Posted: Sun Sep 09, 2007 11:50 am
by milan1612
I don't use global vars very often, in fact I always try not to use them
where it is not necessary. Therefore I don't need this feature...
Posted: Sun Sep 09, 2007 12:38 pm
by AND51
freak wrote:I think crowding up the language with such keywords just for the sake of lazyness is not a good idea.
I don't consider this as an act of crowding up the language, because there are many things, that haelp you to not lose the overview over all commands, e. g. autocomplete and the statusbar.
Morover, this is not an act of lazyness! I see the advantage in having a tidy area to see at once which vars I've got declared.
Perhaps I and some others, who agree to me, can convince you, freak. So far I would have relized this on my own (with Macros), but I don't know how. And the idea to write a preparser is not good due to compilation-performance. So if you can also show me an alternative method, you're welcome.

Posted: Sun Sep 09, 2007 12:44 pm
by PB
> having a Globalize-Section makes your code more clear
Hmm, I don't really see how. Both code blocks below are just as clear to
me as to what they do. I don't see any advantage of one over the other.
Code: Select all
Globalize
mutex_einstellung=CreateMutex()
mutex_cache=CreateMutex()
mutex_logfiles=CreateMutex()
mutex_screenshots=CreateMutex()
mutex_favourites=CreateMutex()
EndGlobalize
Global mutex_einstellung=CreateMutex()
Global mutex_cache=CreateMutex()
Global mutex_logfiles=CreateMutex()
Global mutex_screenshots=CreateMutex()
Global mutex_favourites=CreateMutex()
Posted: Sun Sep 09, 2007 12:47 pm
by milan1612
AND51 wrote:Morover, this is not an act of lazyness! I see the advantage in having a tidy area to see at once which vars I've got declared.
Maybe you should take a look at Delphi

Posted: Sun Sep 09, 2007 7:42 pm
by AND51
> Both code blocks below ...
Please, consider
ALL facts I've listed:
- less to write
- tidy/clear
- easy to handle
- overview
With your code you just have a look at tidyness.
@ milan:
Bah, hör mir auf damit!

Delphi haben wir in der Schule genug bis zur Vergasung...
Posted: Sun Sep 09, 2007 8:13 pm
by Kaeru Gaman
> With your code you just have a look at tidyness.
it's even easy to handle (I see no advantage in your block)
I don't need additional commands for a good overview.
with both solutions you should add some remark lines.
additional, the way you wrote the example is not very tidy/overview...
at least you should it this way:
Code: Select all
Globalize
mutex_einstellung = CreateMutex()
mutex_cache = CreateMutex()
mutex_logfiles = CreateMutex()
mutex_screenshots = CreateMutex()
mutex_favourites = CreateMutex()
EndGlobalize
so, I see no argument to ask for some new redundant command,
if you are not even setting correct tabulators.
Posted: Sun Sep 09, 2007 8:14 pm
by milan1612
>Delphi haben wir in der Schule genug bis zur Vergasung...
[german]
Ich auch, seitdem hab ichs mir in jeder Sprache angewöhnt
alle Variablen am Anfang einer Procedur zu deklarieren
[/german]
Posted: Sun Sep 09, 2007 9:50 pm
by Bonne_den_kule
The global keyword is good enough imho