AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

#Strict, #Warning

 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
AHKIsTheBest



Joined: 20 Jun 2009
Posts: 19

PostPosted: Mon Nov 02, 2009 12:51 pm    Post subject: #Strict, #Warning Reply with quote

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.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Mon Nov 02, 2009 1:00 pm    Post subject: Re: #Strict, #Warning Reply with quote

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.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
jaco0646



Joined: 07 Oct 2006
Posts: 3113
Location: MN, USA

PostPosted: Mon Nov 02, 2009 1:43 pm    Post subject: Reply with quote

This is currently #28 on the "Top 40" list.
Back to top
View user's profile Send private message Visit poster's website
HotKeyIt



Joined: 18 Jun 2008
Posts: 4652
Location: AHK Forum

PostPosted: Mon Nov 02, 2009 2:23 pm    Post subject: Reply with quote

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 Question
_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
AHKIsTheBest



Joined: 20 Jun 2009
Posts: 19

PostPosted: Mon Nov 02, 2009 6:49 pm    Post subject: Re: #Strict, #Warning Reply with quote

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. Smile

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. Smile

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 ).
Back to top
View user's profile Send private message
Tuncay



Joined: 07 Nov 2006
Posts: 1886
Location: Germany

PostPosted: Mon Nov 02, 2009 10:08 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Raccoon



Joined: 02 Jan 2008
Posts: 150
Location: Freenode IRC

PostPosted: Tue Dec 01, 2009 2:35 pm    Post subject: Re: #Strict, #Warning Reply with quote

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. Smile

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.
_________________


Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group