return ErrorLevel from functions

Discuss the future of the AutoHotkey language
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

return ErrorLevel from functions

18 Feb 2014, 06:32

EDIT: The friendly splitting mod/admin did not even marked this topic as being a topic split. And as coincidence(?) the subject (-header) turns out to be related to a topic I've recommended to neglect at least two times. Lol, obedience over capacity?
  • BIVs, Subcommands, StdLib, Settings:
    Imho,
    AHK. > A_ !
    But, even more
    win.move > winmove
    and finally,
    win.titlematchmode > AHK.titlematchmode
    so, in effect, AHK would be truncated to some directives (in this form not so interesting).
    What? I'd prefer namespaces (or objects) win, math, gui, str, ... whenever they arise naturally. Then, one could use different settings side by side:

    Code: Select all

    win2 := win.clone()
    win2.titlematchmode := "regex"
    win2.detecthiddenwindows := "off"
    win2.close("title1|title2")
    
  • Variables:
    Imho it is good that an "undefined" var bahaves like an "empty" var, that is a var that is freed according to the rules of the language.
    Now, ahk is like arithmetic before the invention of the 0, and, uses the empty string for this purpose (maybe not ahk-internally, but in the script it looks like that). Hence, it'd be consistent that an "undefined or free" var behaves exactly like an empty string (which is a string imho).
    On the other hand, after the invention of a reserved "undefined or free" type one should cast it for (almost) all operators or for none, everything in between only fills the support forum. Imho one should cast, as it would reduce the abuse of the ternary operator to circumvent a simple var "start-assignment".
  • Misc:
    I've no doubt that it will work, but it is imho very quirky:
    (1) Comma operator and command syntax (to be found in v1 and v2)
    (2) Built-in functions, some returning !ErrorLevel and others not.
    If the comma operator returns the right-most operand (which was at least discussed), then this mechanism

    Code: Select all

    actually_I_am_interested_in_the_ErrorLevel := (function(args), ErrorLevel)
    
    is much clearer than (2).
Last edited by strobo on 11 Mar 2014, 07:21, edited 3 times in total.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2-thoughts Discussion

19 Feb 2014, 02:07

strobo wrote:But, even more
win.move > winmove
I disagree.
Then, one could use different settings side by side:
I think that's an interesting idea, but not suitable for AutoHotkey. If you think the idea has merit, you could implement it as a script library.

Variables: I understood little of what you tried to say in this part of your post. "Undefined or free" variables contain an empty string. This will not be changed. However, use of uninitialized variables can be detected using the #Warn directive.

(1) What about it? Quirky how?

(2) This is not quirky. All built-in functions which set ErrorLevel to a boolean value will return !ErrorLevel. It would not be useful for all functions to return !ErrorLevel. It is not logical to imply that all functions in a library should return the same value - different functions have different purposes.
actually_I_am_interested_in_the_ErrorLevel := (function(args), ErrorLevel) is much clearer than (2).
I disagree. How do you know what ErrorLevel means? Either you read the documentation (which would also say what the return value is), or you assumed (maybe incorrectly) that the function follows the common pattern of ErrorLevel=0 for success and ErrorLevel!=0 for failure. Another common pattern is for a function to return true on success, false on failure. Now functions which followed the former pattern also follow the latter pattern. IMHO,

Code: Select all

if WinSetTransparent(N, Title)
    MsgBox success
is clearer and less verbose than

Code: Select all

if (WinSetTransparent(N, Title), ErrorLevel)
    MsgBox failure
Before, they returned ErrorLevel as-is, so they returned true on failure. To me, this seemed counter-intuitive. RunWait and SendMessage didn't set ErrorLevel to a boolean "error" value, so they are unaffected by the change.
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: v2-thoughts Discussion

19 Feb 2014, 09:59

@Variables
IIRC (sorry if not),
fincs: non-numerics --> 0
just me: empty var contains empty string --> throw exception (math operator context)
strobo: all the same to me, but keep it consistent.
I mention it because last time I checked,

Code: Select all

msgbox,% ++p ; blank
++p
msgbox,% ++p ; 2
a := {}
msgbox,% ++a[1] ; blank
++a[1]
msgbox,% ++a[1] ; blank
@(1)
IIRC v2 has even more corner cases than v1, when it comes to interpreting a whole code-line as expression (due to command-syntax). My reference to the comma-operator was misleading because other operators are affected as well.
@(2)
I am not assuming anything about ErrorLevel. I am not suggesting that functions should not return meaningfull values. Maybe I should just extend the example

Code: Select all

actually_I_am_interested_in_the_ErrorLevel := (function(args), ErrorLevel)
I_dont_care_ErrorLevel_I_dont_read_the_docs := function(args)
The user should be able to guess the meaning of the return value from the function name and not from knowing whether ErrorLevel is boolean. Frankly, the difference is maybe to subtle to have many real world consequences.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2-thoughts Discussion

19 Feb 2014, 19:47

strobo wrote:@(1)
IIRC v2 has even more corner cases than v1, when it comes to interpreting a whole code-line as expression (due to command-syntax).
Such as? I think you're mistaken. Also, your example produces all blank results on v2.
@(2)
I am not assuming anything about ErrorLevel.
So then you don't know what ErrorLevel means? How then is it clearer to use ErrorLevel via the comma operator? Why are you interested in the ErrorLevel and not the return value?
The user should be able to guess the meaning of the return value from the function name and not from knowing whether ErrorLevel is boolean.
They can...
joedf wrote:I don't want to sound like a pessimist. There is great ambition here.
How could your post be interpreted as pessimistic? The whole point of v2 is that it breaks compatibility.
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: v2-thoughts Discussion

20 Feb 2014, 02:25

Such as? I think you're mistaken

Code: Select all

p ++
Also, your example produces all blank results on v2
Great news.
So then you don't know what ErrorLevel means? How then is it clearer to use ErrorLevel via the comma operator? Why are you interested in the ErrorLevel and not the return value?
The guy who don't know ErrorLevel writes

Code: Select all

I_dont_care_ErrorLevel_I_dont_read_the_docs := function(args)
he is interested in the return value and doesn't use ErrorLevel via comma operator.
The other guy uses comma.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

return ErrorLevel from functions

20 Feb 2014, 04:07

strobo wrote:p ++
Now I'm not sure what you mean by corner case, or why it's a bad thing. v2 is more consistent - for instance, compare MsgBox ++ and MsBox ++ on v1.
The guy who don't know ErrorLevel [...] is interested in the return value and doesn't use ErrorLevel via comma operator.
The other guy uses comma.
I think that just reinforces my point. It isn't inherently clearer at all; you are just more familiar with ErrorLevel. It has no benefit to a new user. I think someone that doesn't know how the comma operator works (or is familiar with its behaviour in v1, which is different) would find your code more confusing.

By the way, I think this thread has defeated the purpose of adding the v2 forum (to avoid putting various unrelated discussions into one big thread). Would a moderator care to split the posts up?
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: v2-thoughts Discussion

20 Feb 2014, 05:28

Afaik

Code: Select all

q := 1
is expression

Code: Select all

q ++
is not (IIRC). Then, what about

Code: Select all

q += 1
I guess it is expression;)
It isn't inherently clearer at all;
The user could use the function letter-by-letter as in your example, if the function returns a meaningfull value. So, no difference there. And, if the user uses some fancy option to alter the semantics of the ErrorLevel (e.g. breaking some accepted rule like "return true on succes"), he doesn't necessarily need to alter the semantics of the return value. As said, it is subtle and maybe to academic to be of relevance here, but iirc the topic name was "v2-thoughts..."
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: v2-thoughts Discussion

20 Feb 2014, 07:16

They do not need to guess. They simply need to read the documentation. If they are unwilling to do that why should we assume they will pay any attention to how the function signature is defined. Error levels are enigmatic in other environments as well. Any that employ them from other languages is familiar with having to pay special attention to them. In this, AutoHotkey is especially standardized. Some commands and functionalities may be used rather carelessly. Some require more detailed attention to the documentation and an understanding that is not often found in novice of how these functionalities operate. still others function in ways that have little or nothing to do with the way AutoHotkey is implemented (COM). Like it or not Errorlevel is going to require some extra attention to detail wherever it is used. It is not intuitive and I don't think it can be. What I actually think you might be looking for is what the name errorlevel implies. a success/failure indicator for commands and or functions ( I am not sure how this would work with functions). unfortunately Errorlevels have a very long history of being used for and by programmers to indicate numerous things. in some environs they even accept input.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: v2-thoughts Discussion

20 Feb 2014, 07:56

They do not need to guess.
let me quote Lexikos
They can...
I prefer a guessable, easy to remember API, but it's only me.
If they are unwilling to do that why should we assume they will pay any attention to how the function signature is defined...
Like it or not Errorlevel is going to require some extra attention
Then, why not unlink return value and ErrorLevel, sth one could easily extract from this quote
And, if the user uses some fancy option to alter the semantics of the ErrorLevel (e.g. breaking some accepted rule like "return true on succes"), he doesn't necessarily need to alter the semantics of the return value.
I haven't proposed that all functions should return (!)ErrorLevel. I have stated that the binding of the return values to ErrorLevel or !ErrorLevel seems not to be consistent. This does not imply that I propose to bind all to, say, ErrorLevel. Just use the quoted "accepted rule" as counter example (in the sense of a rule, not in the sense of actual return values).
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2-thoughts Discussion

20 Feb 2014, 17:22

N += 1 is an expression in both versions, even if N is a command name. The same goes for any binary assignment operator. Postfix operators like ++ were inconsistent in v1.
So, no difference there. And, if the user uses some fancy option to alter the semantics of the ErrorLevel
That's a hypothetical that has no relevance to the discussion. When I referred to returning !ErrorLevel, that was to avoid having to list all of the commands. I wasn't saying these functions will always return !ErrorLevel even if ErrorLevel is changed (which it won't be).
iirc the topic name was "v2-thoughts..."
Don't take it out of context. Read the topic before posting. The thread is about the document linked in the first post, named v2-thoughts.
let me quote Lexikos
I said they can, not that they need to. tank said they don't need to.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2-thoughts Discussion

20 Feb 2014, 19:14

strobo wrote:I have stated that the binding of the return values to ErrorLevel or !ErrorLevel seems not to be consistent.
It is consistent... Functions which just indicate success or failure (as opposed to returning some other value, like text, a process exit code, message return value, etc.) have a uniform behaviour.
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: v2-thoughts Discussion

21 Feb 2014, 01:15

That's a hypothetical that has no relevance to the discussion.
I agree, although I warned two times that it might not be relevant (for this audience at least), so, I haven't keep it alive.
Don't take it out of context. Read the topic before posting.
I haven't. I have.
I said they can, not that they need to. tank said they don't need to.
My position was not that they need to guess, but that they _should be able to_ guess. And You wrote in this context, "They can..." Maybe my poor english let me interpret it falsely as confirmation that they (actually) are able to guess. But tank also wrote
They do not need to guess. They simply need to read the documentation.
which is in fact (in cases) opposite to "be able to guess", as, if one is able to guess, one does not need (in this cases) to read the documentation.
And, to be ABSOLUTELY CLEAR, my position is NOT that they _should not_ read the documentation. And, my position is not that tea is superior to coffee. Nvm, I won't disturb your topic hygiene anymore.
lexikos
Posts: 9553
Joined: 30 Sep 2013, 04:07
Contact:

Re: v2-thoughts Discussion

21 Feb 2014, 02:44

To be clear, you're saying that "They need to read the documentation" means that they can't guess? I don't think tank meant it that strictly. Originally (and again) you quoted "They do not need to guess", which in no way means that they can't guess.

However, they do need to read the documentation if they want to use each function correctly. If they don't, they will run into trouble eventually. You can guess, but that doesn't mean the result will always be good...
User avatar
joedf
Posts: 8940
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: v2-thoughts Discussion

21 Feb 2014, 03:04

I agree. It's like trying to speak a language you've never learned.
You know what happens : it comes all crooked and full of errors.
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
strobo
Posts: 125
Joined: 30 Sep 2013, 15:24

Re: v2-thoughts Discussion

21 Feb 2014, 03:39

"They need to read the documentation" means that they can't guess? I don't think tank meant it that strictly.
How to earn here such indulgence?
"They do not need to guess", which in no way means that they can't guess.
edited:
I agree, and, I have never written it (the implication: need not guess ==> can't guess) down.
This part of the discussion is not constructive, it is imho better to move on.
User avatar
tank
Posts: 3122
Joined: 28 Sep 2013, 22:15
Location: CarrolltonTX
Contact:

Re: v2-thoughts Discussion

21 Feb 2014, 10:06

strobo wrote:How to earn here such indulgence?
Because, for all of my poorly worded statements. Lexikos has come to quite well understand what I do and don't mean over the course of years and thousands of posts.
strobo wrote:[..]discussion is not constructive, it is imho better to move on.
agree
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me
https://t.me/ttnnkkrr
If you have forum suggestions please submit a
Check Out WebWriter

Return to “AutoHotkey Development”

Who is online

Users browsing this forum: No registered users and 41 guests