AutoHotkey Community

It is currently May 26th, 2012, 11:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: #Strict, #Warning
PostPosted: November 2nd, 2009, 1:51 pm 
Offline

Joined: June 20th, 2009, 8:55 pm
Posts: 19
Hello,

I suggest two pragmas which makes it harder to commit frequent errors. Of these two, #Warning is probably more useful, since it's less intrusive, and it's easy to add any amount of warnings without breaking anything. For more background on how this is used in Perl,
http://perldoc.perl.org/strict.html and http://perldoc.perl.org/warnings.html.


Code:
#Strict [On]


This activates errors for the following cases:

* Referencing an non-existing variable (i.e., no local/static/global so far, not existing in the current scope).
* ...

Code:
#Strict Off


...turns the strict mode off.

Code:
#Warnings [On|OutputDebug|Main]


...turns all warnings on. If OutputDebug is used, the warnings go there, if Main is used, they go to the main window instead, if nothing or On is used, they go to both.

Possible warnings:

* Using an undeclared variable generates a warning
* Using = where == would be more probable
* A local variable shadowing a global one
* Somewhere a number is expected but something else was given
* Anything that's regarded as deprecated
* ...

Code:
#Warnings Off


... turns all warnings off.


Later / low priority:

[code]#Warnings [On|Off|OutputDebug|Main], Name

Turns warning "Name" on or off.

[code]#Strict [On|Off|OutputDebug|Main], Name

Turns "strict" feature "Name" on or off.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: #Strict, #Warning
PostPosted: November 2nd, 2009, 2:00 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
Interesting idea. I do know that AHK does a little bit of preprocessing to make sure the script won't crash entirely. It will be up to Chris or other similarly skilled programmers to decide how hard this would be.

AHKIsTheBest wrote:
* Using an undeclared variable generates a warning
* Using = where == would be more probable
* A local variable shadowing a global one
* Somewhere a number is expected but something else was given
* Anything that's regarded as deprecated


Some of these are hard (or impossible) to detect. notes on yours (in order)
- %array9% is 'valid' only when a previous StringSplit (for example) gives 9+ results. AHK may not know ahead of time whether the StringSplit will resolve to that many items (at compile time)
- == is pretty rarely used in AHK.
- this one would be nice.
- Numbers and strings are usually the same thing, so it might be hard to detect.
- Would love this one. You might say we already have it, since nothing is officially deprecated, though I and others have posted about what we would like to see 'officially' deprecated.

Thanks for posting.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2009, 2:43 pm 
Offline

Joined: October 7th, 2006, 4:50 pm
Posts: 3157
Location: MN, USA
This is currently #28 on the "Top 40" list.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2009, 3:23 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
Quote:
* A local variable shadowing a global one

That would definitely help.

Possibly it could be shown in main window "Variables and their contents" under separate section, should not be to hard to implement I think :?:

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun :wink:


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: #Strict, #Warning
PostPosted: November 2nd, 2009, 7:49 pm 
Offline

Joined: June 20th, 2009, 8:55 pm
Posts: 19
engunneer wrote:
Some of these are hard (or impossible) to detect.


Yup, things would need to be prioritized according to effort etc. . The list is just an example of some warnings. I guess almost any experienced AHK user can come up with some personal gripes. :)

Quote:
- %array9% is 'valid' only when a previous StringSplit (for example) gives 9+ results. AHK may not know ahead of time whether the StringSplit will resolve to that many items (at compile time)


The warning does (and should not) be generated at compile time, but at runtime. At runtime, for every variable name, AHK knows whether it encountered it, at the moment when its value is needed.

Quote:
- Numbers and strings are usually the same thing, so it might be hard to detect.


Let me elaborate. Let's say someone mistypes "MouseClick, LEFT, 123, 1oo". Silly, I know, but bear with me. Right now, AHK will happily process this and complain neither at compile- nor at runtime. Also, when executing the line, nothing happens at all (the pointer does not move). But AHK obviously detects that something is wrong (else, SOMETHING would be happening, say, an equivalent of "MouseClick, LEFT, 123, 0"), it may as well output a warning (or, error, in this case), making this almost impossible to find error easily caught.

I am aware that going through every function to check for things like this may be too much effort for the developer(s?), just pointing out possibilities.

Quote:
- Would love this one. You might say we already have it, since nothing is officially deprecated, though I and others have posted about what we would like to see 'officially' deprecated.


It would even be pretty useful if the programmer could tell AHK what he (the programmer) considers deprecated. I.e., I always try to use "a := b" instead of "a = %b%" and would be happy if I could tell AHK to warn me about an accidental "a = b" with something like "#Warning PreferExpressions" or whatever. Or, if I would like it the other way round, a "#Warning AvoidExpressionAssignment" - both warnings would be useful for some people. That does not mean that AHK officially needs to deprecate that feature, i.e, a simple "#Warning" would, per default, not enable this specific Warning.

Quote:
Thanks for posting.


Pure selfishness. :)

jaco0646 wrote:
This is currently #28 on the "Top 40" list.


Thanks for pointing it out (that's forum http://www.autohotkey.com/forum/viewtopic.php?t=37566 ).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: November 2nd, 2009, 11:08 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
Nothing new. I wish this for a long time. An alternative to the way adding a directive to script could be adding new parameter to AutoHotkey.exe itself. So any script could be tested for strictness (debugging phase) without touching the file.


Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: #Strict, #Warning
PostPosted: December 1st, 2009, 3:35 pm 
Offline

Joined: January 2nd, 2008, 4:47 am
Posts: 150
Location: Freenode IRC
engunneer wrote:
- Would love this one. You might say we already have it, since nothing is officially deprecated, though I and others have posted about what we would like to see 'officially' deprecated.


Many things have become officially depreciated in AHK. For homework, I suggest you download every old version of AHK and then several versions of AutoIT prior to AHK's original release. Collect all of the help documentation into one place.

Go through and find all the commands that magically vanish from new versions. :)

Code:
Repeat
EnvAdd, i, 1
ToolTip, %i%
EndRepeat

Code:
Repeat
i++
ToolTip % i
}


Both of these are WORKING examples, though extremely depreciated. You will find Repeat is still indexed in the help file, but no longer documented. It now forwards to Loop.

_________________
Image

Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 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