AutoHotkey Community

It is currently May 27th, 2012, 1:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: December 13th, 2011, 4:43 am 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Note: Invalidity follows.

The topic title pretty much sums it up. This doesn't only affect variables explicitly declared global outside any scope, but also affects class declarations.

Reasons include:
  • This is a confusing and obscure source of bugs.
  • Sometimes declaring variables first isn't the best way of ordering code.
  • Consistency: Super-global classes make classes similar to functions in that they are available everywhere, except for the requirement that classes be declared first whereas functions can be declared anywhere.
  • If inter-dependent class declarations (class x extends y) are in separate files, including the files in the wrong order can break the script -- and this should never be the case. (See: Be able to define a base class after the child class)

I realize it may not be simple to implement, but I would certainly be willing to sacrifice a few milliseconds of load-time performance (once, when ahk starts) to do an extra loop through the script to identify variables that need to be treated as super-global. Especially if it means that we gain substantial consistency and remove obscure behavior.

_________________
Scripts - License


Last edited by infogulch on December 14th, 2011, 8:40 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 8:26 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Can you give an example where super-globals are "position-sensitive"?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 13th, 2011, 6:46 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
My argument is invalid. (except for maybe classes)

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 14th, 2011, 8:26 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Ok I'll turn this into a question: If explicitly declared global variables are NOT position sensitive, why are class declarations?

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2011, 8:36 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7503
Location: Australia
Neither explicitly declared super-global variables nor class declarations are position-sensitive with regard to referencing them inside functions. Class declarations are only position-sensitive in that class X extends Y requires that Y contains an object at the time the declaration is processed. This has been discussed elsewhere and may be resolved in a future update.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: December 15th, 2011, 6:02 pm 
Offline

Joined: March 27th, 2008, 2:14 pm
Posts: 700
Aaah I see.

How about this then:

When ahk encounters a class X extends Y and Y is not yet an object:
  • Create an (empty) object for Y and use it as X's base.
  • If the script encounters class Y, populate the (empty) object that already exists.
  • If the script never encounters class Y, exit the script with "unknown class" error

_________________
Scripts - License


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 3 guests


You can 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