Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

AutoHotkey_L v1.0.90 and Roadmap


  • Please log in to reply
48 replies to this topic
Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
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.

fragman
  • Members
  • 1591 posts
  • Last active: Nov 12 2012 08:51 PM
  • Joined: 13 Oct 2009

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?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Does positional mean that they are only useable by code below their declaration,

Yes.

guest3456
  • Members
  • 1704 posts
  • Last active: Nov 19 2015 11:58 AM
  • Joined: 10 Mar 2011
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