AutoHotkey Community

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

All times are UTC [ DST ]




Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3

Should "While(...)" be a loop or a function?
A function: Preserves backward compatibility & avoids having a "forbidden" function name.
A loop, for consistency with the existing "if(...)" & for convenience of those in the habit of writing "while(...)"
You may select 1 option

View results
Author Message
 Post subject:
PostPosted: September 27th, 2009, 12:46 pm 
HEY, another solution is to let while loop take the form of

While, expression
{
msgbox, "testing"
}

without any bracket


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 12:48 pm 
Offline

Joined: August 2nd, 2009, 6:40 am
Posts: 215
Anonymous wrote:
I don't really care about this change, it don't affect me (mostly), I write functions without a space...function()...(even if they would work with a space {which should NOT happen, plz don't support that}) & I write if's & while's with a space, since they are NOT functions & always with parens (even when not "needed")...so this change is unnecessary for me...if I would ever write...while()...I would mean a function, if I write...while ()...then I'm making a loop...so this change is unnecessary & breaks back-compat...I'm not against breaking back-compat, for good changes, but this change only loosens the language & allows sloppy use of the while loop, making it look like a function call...

Let me fix that for you, the change prevents sloppy use of the while statement. Whether you use:
Quote:
while()
while () or
while,
It will do the expected while-loop, and at a glance you can discern exactly what it is supposed to be.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 1:02 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Laszlo wrote:
- My main complaint was that old scripts break with the new AHK interpreter (may get to infinite loops), without any warning or error message. It is a lot of work to go back to debug all of our older scripts at a minor AHK update, which does not introduce new features.
Understandable. If I'd known it would affect you and the guest who posted above, I probably wouldn't have changed it.

Now that it is changed, it's harder to go back.

I've created a poll in this topic; though it might only prove useful if the majority votes to undo the change. If the majority votes to keep the change, that would be less useful because popularity might not be enough justification to break backward compatibility -- especially since the change benefits only a minority of users with a more convenient syntax.

Another issue is the fact that the poll's participants might biased because those in favor of the change tend to be the ones who would read this topic, while others might not even look at it (not realizing that backward compatibility is at stake). So if there is demand, I can create a new topic and poll with a more relevant title.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 1:19 pm 
Anonymous wrote:
...let while loop take the form of...without any bracket

..."bracket" should be "paren" or "parentheses" but, that IS the current form...parens are allowed but not required (as least based on the help file)...I actually would like parens to be required & require the space between while & the open paren...

Crash&Burn wrote:
Whether you use...

...as stated in this post, I do not like the other forms of while...by sloppy I mean you can write anything, in any way & it still works...instead of having one right way to write a while loop...as I said above, while should be written this way & this way only...

Code:
while (expression) {
   ;//loop contents
}

...required parens, space before open paren, space after close paren, open brace on same line, close brace on line after all contents...

Crash&Burn wrote:
It will do the expected while-loop...

...I do agree that while should only be used for a while loop (not a function that does something else), but I also think that 1 form should be put in the help file/required, so everyone does it the same way...the help file current only says..."While Expression"...that tells me nothing about using parens around the expression or using braces/blocks...

Chris wrote:
I've created a poll in this topic

...(guests can't vote, so perhaps a new topic with a poll AND mention guests should vote by posting)...since while as a function has no point other than creating the fake while loop when it didn't exist, the poll should probably be "should if & while be changed to require spaces before the open paren"...I'm sure most would vote No, but I would vote Yes...even if...if()...works, I will never write it that way, since if is not a function...& neither is while...as already stated 2 or 3 times in this post...if & while should both be changed to require the same syntax, as my while example above...it makes everything look much nicer & more structured...& even if you will never make that syntax required...I would suggest you a least use that syntax in the help file, so that new people will learn it right & have a good example to learn from...


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 2:15 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Anonymous wrote:
...(guests can't vote, so perhaps a new topic with a poll AND mention guests should vote by posting)
It seems too unreliable to count votes from guests; so they should probably create a username if they want to vote.

Anonymous wrote:
...since while as a function has no point other than creating the fake while loop when it didn't exist, the poll should probably be "should if & while be changed to require spaces before the open paren"...I'm sure most would vote No, but I would vote Yes...even if...if()...works, I will never write it that way, since if is not a function...& neither is while...as already stated 2 or 3 times in this post...if & while should both be changed to require the same syntax, as my while example above...it makes everything look much nicer & more structured...& even if you will never make that syntax required...I would suggest you a least use that syntax in the help file, so that new people will learn it right & have a good example to learn from...
The above doesn't seem that relevant to the original suggestion made by the topic starter. It seems best for this poll to stick to the original issue.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 3:44 pm 
Offline

Joined: November 7th, 2006, 9:47 pm
Posts: 1934
Location: Germany
I voted for traditional style only for constistency. It does not make sense to me to allow function style. It is not a function call and it dont act like one. Its not too late to change this back.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 27th, 2009, 4:28 pm 
Offline

Joined: February 14th, 2005, 4:05 pm
Posts: 4710
Location: Boulder, CO
Anonymous wrote:
just do a replace of "while(" with "old_lol_while(" in your script
Of course, it does not help with dynamic function calls, and in many more cases. Furthermore, as Chris and others noted, scripts given away cannot be always edited by their authors.

We had this nightmare already with if() functions, posted earlier to this Forum. They implemented the ternary operator before they got introduced to AHK, and simulated switches. Exceptions to rules are generally not nice.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 28th, 2009, 1:29 pm 
Laszlo wrote:
Furthermore, as Chris and others noted, scripts given away cannot be always edited by their authors.


i think the least that could be done is to introduce an error msg popup right?

Anonymous wrote:
HEY, another solution is to let while loop take the form of

While, expression
{
msgbox, "testing"
}

without any bracket


i think this could do as well.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 2:01 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
The poll is currently 9 to 3 in favor of not changing it back. The poll data indicates that there were no suspicious votes from similar IP addresses or newly-created usernames.

Since there is some concern about bias due to the topic title and the fact that the topic didn't start out with a poll, if anyone wants to have another poll, feel free to start a new topic in Wish List (or let me know if you want me to start it).


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 6:02 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
I think since While is a command and not a function, it does not return anything and this is not an AutoHotkey syntax for commands but for functions, same syntax as for other commands should be used.

Otherwise it brings in another alternative syntax, which does not work for other commands and this is really confusing :?
I think programmers and advanced users will find out very quick how to use while command while a starter and possibly most of AutoHotkey users may never discover that it is possible to use While()-loop.

I think, either all commands should support this syntax or no command ( :arrow: dynamic commands. )

I also wonder about this:
Code:
;Why does this work
While (A_Index<3)
;But this does not
Loop (3) ; you must use Loop % () as for all other commands


Would it be possible to support "(" additionally to "%" to identify an expression for all commands (at least where possible) :?:
As far as I understand this would not break any existing script since "(" is not a valid variable character.
Code:
;But like 
WinWait (...

( could be valid for some commands so this commands would still not support that.

What do you think?

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 6:18 pm 
Offline

Joined: July 9th, 2009, 9:25 pm
Posts: 120
HotKeyIt wrote:
I also wonder about this:
Code:
;Why does this work
While (A_Index<3)
;But this does not
Loop (3) ; you must use Loop % () as for all other commands

Due to the need to support file-pattern loops, Count cannot be an expression.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 7:11 pm 
Offline

Joined: June 18th, 2008, 8:36 am
Posts: 4923
Location: AHK Forum
temp01 wrote:
Due to the need to support file-pattern loops, Count cannot be an expression.


I see, a file could be called ().txt or similar, I missed that :(

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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 29th, 2009, 11:03 pm 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
HotKeyIt wrote:
I think since While is a command and not a function, it does not return anything and this is not an AutoHotkey syntax for commands but for functions, same syntax as for other commands should be used.
The whole purpose for supporting "while()" as a loop is because many programmers have a deeply-ingrained habit of writing it that way (this is because it's a common style among programmers of C-like languages). This is also why the program was changed a long while ago to recognize "if()" as an if-statement rather than a function.

HotKeyIt wrote:
Would it be possible to support "(" additionally to "%" to identify an expression for all commands (at least where possible) :?:
As far as I understand this would not break any existing script since "(" is not a valid variable character.

Code:
;But like 
WinWait (...

( could be valid for some commands so this commands would still not support that.
It would probably add a lot of code size and complexity due to all the exceptions that would have to be allowed, like the ones mentioned by you and others. There doesn't seem to be enough benefit to justify it.

Thanks.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 4 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