AutoHotkey Community

It is currently May 27th, 2012, 12:00 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
 Post subject:
PostPosted: April 20th, 2011, 10:42 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Further to fragman's post, a common source of bugs in scripts is forgetting to declare a variable global in each function. It is also important for class definitions: once a class is defined, it is counter-intuitive to have to declare it in each function before it can be used. Actually, I think that it is generally counter-intuitive for so-called "global" variables to be invisible to functions by default, but given the "no declaration required" nature of AutoHotkey, it might be the lesser evil. Requiring a (single) declaration to make the variable visible in all functions seems like a good compromise between convenience and maintainability.

FYI, super-global declarations are already possible in v2 alpha. The current limitation is that like all variable declarations, they are positional.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2011, 11:50 am 
Offline

Joined: October 13th, 2009, 10:09 pm
Posts: 1389
Lexikos wrote:
Further to fragman's post, a common source of bugs in scripts is forgetting to declare a variable global in each function. It is also important for class definitions: once a class is defined, it is counter-intuitive to have to declare it in each function before it can be used. Actually, I think that it is generally counter-intuitive for so-called "global" variables to be invisible to functions by default, but given the "no declaration required" nature of AutoHotkey, it might be the lesser evil. Requiring a (single) declaration to make the variable visible in all functions seems like a good compromise between convenience and maintainability.

FYI, super-global declarations are already possible in v2 alpha. The current limitation is that like all variable declarations, they are positional.


I fully agree to your argumentation. Does positional mean that they are only useable by code below their declaration, or does the line have to be executed before it can be used?


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2011, 11:52 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
fragman wrote:
Does positional mean that they are only useable by code below their declaration,
Yes.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 20th, 2011, 5:14 pm 
Offline

Joined: March 10th, 2011, 7:17 pm
Posts: 374
i see, yeah i wasn't thinking about classes. i think it would be strange to have to declare a class global inside a function, prior to creating a new instance of it, but i havent thought as much about it as you i'm sure


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 49 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group