 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
AHKIsTheBest
Joined: 20 Jun 2009 Posts: 19
|
Posted: Mon Nov 02, 2009 12:51 pm Post subject: #Strict, #Warning |
|
|
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.
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).
* ...
...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
* ...
... 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 |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Mon Nov 02, 2009 1:00 pm Post subject: Re: #Strict, #Warning |
|
|
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 |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Mon Nov 02, 2009 1:43 pm Post subject: |
|
|
| This is currently #28 on the "Top 40" list. |
|
| Back to top |
|
 |
HotKeyIt
Joined: 18 Jun 2008 Posts: 4652 Location: AHK Forum
|
|
| Back to top |
|
 |
AHKIsTheBest
Joined: 20 Jun 2009 Posts: 19
|
Posted: Mon Nov 02, 2009 6:49 pm Post subject: Re: #Strict, #Warning |
|
|
| 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 ). |
|
| Back to top |
|
 |
Tuncay
Joined: 07 Nov 2006 Posts: 1886 Location: Germany
|
Posted: Mon Nov 02, 2009 10:08 pm Post subject: |
|
|
| 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 |
|
 |
Raccoon
Joined: 02 Jan 2008 Posts: 150 Location: Freenode IRC
|
Posted: Tue Dec 01, 2009 2:35 pm Post subject: Re: #Strict, #Warning |
|
|
| 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. _________________
Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|