[Wish] One line while loop (similar to if)
Re: [Wish] One line while loop (similar to if)
Well if you put it that way... It seems to me that neither is unreadable enough
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]
- hoppfrosch
- Posts: 443
- Joined: 07 Oct 2013, 04:05
- Location: Rhine-Maine-Area, Hesse, Germany
- Contact:
Re: [Wish] One line while loop (similar to if)
Code: Select all
while wb.Busy, Sleep 10
Re: [Wish] One line while loop (similar to if)
not sure if this is a joke or notfincs wrote:Claiming thatis less readable thanCode: Select all
while wb.Busy, Sleep 10
is IMO extremely ludicrous.Code: Select all
while wb.Busy Sleep, 10
Re: [Wish] One line while loop (similar to if)
No, it is not a joke.guest3456 wrote:not sure if this is a joke or not
Not sure if this is a joke or not.hoppfrosch wrote:is definitively more unreadable IMHO - I always have to ponder: Is Sleep 10 an argument of wb.Busy? Or is it the body of the while-loop?
---
I assume people posting in this thread are aware that same-line ifs are already supported, e.g.
Code: Select all
if var = "value", MsgBox it happened
Code: Select all
IfEqual, var, value, MsgBox it happened
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 -[My project list]
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 -
Re: [Wish] One line while loop (similar to if)
Yes, I am. But - though not quite sure - I never used this construct, and - quite sure - I never missed it in expressional Ifs.fincs wrote:I assume people posting in this thread are aware that same-line ifs are already supported, e.g. ...
Re: [Wish] One line while loop (similar to if)
For me saving lines means always to see more code at once and understand/remember/connect more code at once.
Also note that here you can group the code by columns, means you can clearly see straight away what happens for which condition.
For example when you need to reassign different variable or do different action.
Is v1 code here more readable? Really?
Also note that here you can group the code by columns, means you can clearly see straight away what happens for which condition.
For example when you need to reassign different variable or do different action.
Is v1 code here more readable? Really?
Code: Select all
; Ahk v2
if (ErrorLevel="Timeout") , b:=var1, TurnOn(a) ,... , ..., ...
else if (ErrorLevel="NewInput") , b:=var2, TurnOff(a) ,... , ..., ...
else if (Errorlevel="Max") , b:=var3, Toggle(a) ,... , ..., ...
else , b:=var4, Switch(a) ,... , ..., ...
; Ahk v1
if (ErrorLevel="Timeout"){
b:=var1
, TurnOn(a)
, ...
, ...
, ...
} else if (ErrorLevel="NewInput"){
b:=var2
, TurnOff(a)
, ...
, ...
, ...
} else if (Errorlevel="Max"){
b:=var3
, Toggle(a)
, ...
, ...
, ...
} else {
b:=var4
, Switch(a)
, ...
, ...
, ...
}
- hoppfrosch
- Posts: 443
- Joined: 07 Oct 2013, 04:05
- Location: Rhine-Maine-Area, Hesse, Germany
- Contact:
Re: [Wish] One line while loop (similar to if)
Same here - I even stricty avoid using them ...just me wrote: Yes, I am. But - though not quite sure - I never used this construct, and - quite sure - I never missed it in expressional Ifs.
I'm not quite sure myself. I hate this "shortened" syntax in general - it makes reading much more difficult IMHO, because the structure of the code layout does give me no additional information about the code itself. Having the body of the while-loop on new lines and indented shows me on one view the body of the while-loop, without haven't read the contents. Unless I'm a perl-man (which has endless possibilities to produce unreadable code), I try to give code a structure to support my reading behaviour (for eexample consequently using { ...} for bodies, even around one liners and so on).fincs wrote:Not sure if this is a joke or not.hoppfrosch wrote:...is definitively more unreadable IMHO - I always have to ponder: Is Sleep 10 an argument of wb.Busy? Or is it the body of the while-loop?
This comparison is not fair. If each coder would layout code like this, this would be an accebtable way to go. But - honestly - have you ever seen anybody using this code layout? Most coders prefer less typing - that's one of the reasons for the existance of this thread. I don't think many users will use additional spaces to support readability...HotKeyIt wrote:Code: Select all
; Ahk v2 if (ErrorLevel="Timeout") , b:=var1, TurnOn(a) ,... , ..., ... else if (ErrorLevel="NewInput") , b:=var2, TurnOff(a) ,... , ..., ... else if (Errorlevel="Max") , b:=var3, Toggle(a) ,... , ..., ... else , b:=var4, Switch(a) ,... , ..., ... }
What I miss most in AHK - based on this disscusion - is a AHKTidy (code formatter - like toralfs famous Auto-Syntax-Tidy). Having this, everybody could transform the code to his own preferred layout before trying to read and understand it ...
Re: [Wish] One line while loop (similar to if)
Why not this way? (with brackets)
Code: Select all
if (ErrorLevel > 9000) { varA := strA, UberFunc() }
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
Re: [Wish] One line while loop (similar to if)
@hoppfrosch: Readability is subjective. I don't think the language should enforce a way of formatting code. IMO one-line While statements are more readable than having to spread them in two lines in many cases. If you don't want to write code like that, then don't. I fail to see why If should get a special treatment, but not While. Either both or none. (And now that we're at it, For too perhaps).
@jNizM: That is way uglier and cannot be cleanly implemented in the current AHK codebase.
@jNizM: That is way uglier and cannot be cleanly implemented in the current AHK codebase.
fincs
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 -[My project list]
Windows 11 Pro (Version 22H2) | AMD Ryzen 7 3700X with 32 GB of RAM | AutoHotkey v2.0.0 + v1.1.36.02
Get SciTE4AutoHotkey v3.1.0 -
Re: [Wish] One line while loop (similar to if)
'If' got special treatment as a substitute for IfEqual etc., which some users still use purely because they allow same-line actions. A lack of this capability, or even the perception that v2 removes some functionality, could be considered a deterrent to switching to v2.I fail to see why If should get a special treatment, but not While.
If it's a matter of consistency or language purity, 'none' is easily the better choice. For instance, Loop couldn't allow it in every case because of ambiguity.Either both or none.
- hoppfrosch
- Posts: 443
- Joined: 07 Oct 2013, 04:05
- Location: Rhine-Maine-Area, Hesse, Germany
- Contact:
Re: [Wish] One line while loop (similar to if)
For sure it's subjective. Asking the question "Either both or none?" I'm rather on the side "None" for the reasons mentioned above.fincs wrote:@hoppfrosch: Readability is subjective. I don't think the language should enforce a way of formatting code. IMO one-line While statements are more readable than having to spread them in two lines in many cases. If you don't want to write code like that, then don't. I fail to see why If should get a special treatment, but not While. Either both or none. (And now that we're at it, For too perhaps).
I probably will not write code like that - the problem for me is, that others might do . As I said, the biggest problem is the lack of code reformatter AHKTidy ... (coming in the situation of having to read and analyze code from someone else).
I'm not passionate on the question, whether this feature will be implemented or not. Having a rather long experience in collaborative software development, I think a common coding style gives several advantages in collaboration. If a language has too many syntactic possibilities to write one expression, each variant will be used - with all it's consequences on decreasing readability and therefore complicating collaboration (it tooks much more time to read and understand the code)
- emmanuel d
- Posts: 90
- Joined: 17 Nov 2013, 04:45
Re: [Wish] One line while loop (similar to if)
That is exactly how i would do it, i love this.hoppfrosch wrote:This comparison is not fair. If each coder would layout code like this, this would be an accebtable way to go. But - honestly - have you ever seen anybody using this code layout? Most coders prefer less typing - that's one of the reasons for the existance of this thread. I don't think many users will use additional spaces to support readability...HotKeyIt wrote:Code: Select all
; Ahk v2 if (ErrorLevel="Timeout") , b:=var1, TurnOn(a) ,... , ..., ... else if (ErrorLevel="NewInput") , b:=var2, TurnOff(a) ,... , ..., ... else if (Errorlevel="Max") , b:=var3, Toggle(a) ,... , ..., ... else , b:=var4, Switch(a) ,... , ..., ...
You dont use spaces but use tabs. saves typing
And easy to copy, just one line
Re: [Wish] One line while loop (similar to if)
In an editor with auto-indent, putting the IF's action on a separate line requires less (or equal) typing:hoppfrosch wrote:Most coders prefer less typing - that's one of the reasons for the existance of this thread.
if condition{enter}action
vs
if condition{comma}{space}action ; (space can be omitted, but I think it usually wouldn't be)
Without auto-indent, I suppose you could compare:
if condition{enter}{tab}action
if condition{comma}{space}action
if condition{enter}action
if condition{comma}action
I really doubt that it's about there being less typing, either way.
Re: [Wish] One line while loop (similar to if)
I agree. I'm gonna go out on a limb & say it's because of the restrictions on how you can write your syntax (not un-similar to complaints against python). I don't want to add another line to my code - I want the simple condition & action on the same line - especially if I'm in a One-Liner type of mood. This becomes extremely important when I'm trying to write beautiful, condensed code - or just trying to impress others with my sophisticated coding skills.lexikos wrote:I really doubt that it's about there being less typing, either way.
... of course I'm being sarcastic, yet truthful ...
Anyways, I'm gonna jump the gun & say why not take the perl approach and allow:
Code: Select all
action if conditon
; or
action while condition
Re: [Wish] One line while loop (similar to if)
How about SleepUntil, (expression), 10?
- emmanuel d
- Posts: 90
- Joined: 17 Nov 2013, 04:45
Re: [Wish] One line while loop (similar to if)
Actualy in V1 i do thisHotKeyIt wrote:Code: Select all
; Ahk v2 if (ErrorLevel="Timeout") , b:=var1, TurnOn(a) ,... , ..., ... else if (ErrorLevel="NewInput") , b:=var2, TurnOff(a) ,... , ..., ... else if (Errorlevel="Max") , b:=var3, Toggle(a) ,... , ..., ... else , b:=var4, Switch(a) ,... , ..., ... ; Ahk v1 if (ErrorLevel="Timeout"){ b:=var1 , TurnOn(a) , ... , ... , ... } else if (ErrorLevel="NewInput"){ b:=var2 , TurnOff(a) , ... , ... , ... } else if (Errorlevel="Max"){ b:=var3 , Toggle(a) , ... , ... , ... } else { b:=var4 , Switch(a) , ... , ... , ... }
Code: Select all
; Ahk v1
ErrorLevel:="tweet"
(ErrorLevel="Timeout") ? ( a:=1, b:="var1")
: (ErrorLevel="NewInput") ? ( a:=2, b:="var2")
: (ErrorLevel="Max") ? ( a:=3, b:="var3")
: (ErrorLevel) ? ( a:=4, b:="????") ; a unknown error was given
: ( a:=5, b:="NoEr") ; no error was givven
Msgbox,%a%----%b%
Re: [Wish] One line while loop (similar to if)
Good idea
But this is not the problem, though, this thread is about one line While statement
While A_Index<5, do something
But this is not the problem, though, this thread is about one line While statement
While A_Index<5, do something
Re: [Wish] One line while loop (similar to if)
One major problem with if expression, action (current) and while expression, action (proposed) is that comma typically separates parameters or sub-expressions -- not statements/commands. I suppose that either multi-statement comma must support commands (only on the right-hand side), as in x := y, MsgBox, or control-flow statements must not use comma in that way. But even if x := y, MsgBox called the command, (x := y, MsgBox) would not; it would purely be an expression.
Other languages which support same-line actions usually either require parentheses around the If/While condition, or a keyword such as then or do. If (condition) { expression } could be an option since concatenation with an {object: literal} is useless (though not invalid), but that could only work with expressions (due to the ending brace), in which case ternary or && is probably better (though with while, one needs at least an empty block on the next line).
Other languages which support same-line actions usually either require parentheses around the If/While condition, or a keyword such as then or do. If (condition) { expression } could be an option since concatenation with an {object: literal} is useless (though not invalid), but that could only work with expressions (due to the ending brace), in which case ternary or && is probably better (though with while, one needs at least an empty block on the next line).
Re: [Wish] One line while loop (similar to if)
I think the only important statements in if and while are break [, Label] + continue [, Label], otherwise only expressions should be supported.
EDIT:
I think (x := y, break) and (x := y, continue) should throw exception.
EDIT:
I think (x := y, break) and (x := y, continue) should throw exception.
Re: [Wish] One line while loop (similar to if)
I have thought about it some more and done some experimentation.
Implementing the following is trivial:It is less trivial to intuitively group the statements, as in if x, y(), return z grouping the last two in a block (or likewise when below an if/loop/etc.).
However, I think this is akin to v1 commands allowing expressions in some args, but instead of an arg being either a string or an expression, it's a string, expression or command. Since the change (requiring % for expressions) basically sacrifices convenience for "purity", it seems difficult to justify the one-liner syntax, which does the opposite.
If x(), break was valid, maybe (x(), break) should also be valid. However, that would require more extensive changes to the way the program works. If that isn't implemented in v2.0, the risk of confusion could be mitigated by prohibiting keywords as variable names (and perhaps this should be done anyway, like HotKeyIt suggested), but reserving all command names might be too restrictive, especially since any user-defined function can be used as a command.
Implementing the following is trivial:
Code: Select all
while condition, statement
for var in expression, statement
for var1, var2 in expression, statement
expression, statement ; as in:
x(), return y
; even:
if x, y(), else, z()
However, I think this is akin to v1 commands allowing expressions in some args, but instead of an arg being either a string or an expression, it's a string, expression or command. Since the change (requiring % for expressions) basically sacrifices convenience for "purity", it seems difficult to justify the one-liner syntax, which does the opposite.
If x(), break was valid, maybe (x(), break) should also be valid. However, that would require more extensive changes to the way the program works. If that isn't implemented in v2.0, the risk of confusion could be mitigated by prohibiting keywords as variable names (and perhaps this should be done anyway, like HotKeyIt suggested), but reserving all command names might be too restrictive, especially since any user-defined function can be used as a command.
Return to “AutoHotkey Development”
Who is online
Users browsing this forum: No registered users and 4 guests