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 

Should true and false become built-in variables?

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  

Should the words true and false become built-in constants?
I strongly agree.
63%
 63%  [ 7 ]
I moderately agree.
18%
 18%  [ 2 ]
I don't have a preference.
9%
 9%  [ 1 ]
I moderately disagree.
0%
 0%  [ 0 ]
I strongly disagree.
9%
 9%  [ 1 ]
I prefer something different.
0%
 0%  [ 0 ]
Total Votes : 11

Author Message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Jan 16, 2005 6:29 pm    Post subject: Should true and false become built-in variables? Reply with quote

Although AutoHotkey does not have a boolean data type (since all variables are stored as strings), having the words true and false as built-in constants might improve the readability of scripts. For example:

UseStandardMenu = Y
CaseSensitive =

Could be written instead as:
UseStandardMenu := true
CaseSensitive := false
(Note that the above must use the colon-equals operator to avoid percent signs around true/false)

Internally, true and false would be stored as 1 and 0, so it wouldn't be too much of a help when using the View menu's "List Variables". But it might be worth something.

The only drawback I see to adding them is the breaking of a few existing scripts that already use them as variable names. However, that is mitigated by the fact that the syntax checker would display an error when such scripts are loaded, making it easy to revise them.

Comments are welcome. Thanks for voting.
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1718

PostPosted: Sun Jan 16, 2005 6:54 pm    Post subject: Reply with quote

though i didn't very much like the language of 'I strongly disagree' Smile but that's what i voted... well i think its not too much benefit compared to the points against it.
_________________
Back to top
View user's profile Send private message
Nemroth



Joined: 07 Sep 2004
Posts: 262
Location: France

PostPosted: Sun Jan 16, 2005 7:19 pm    Post subject: Reply with quote

I think it can be a good thing, but not a necessity. For me it can be implemented but with a low priority.
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sun Jan 16, 2005 8:59 pm    Post subject: Reply with quote

I think this is just short of necessary, since the most common use of variables is a simple on/off indicator. I think it's really cool to finally have a standard proposed for this, as boolean values should be separated from string values for both readability and practicality.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Jan 17, 2005 1:52 am    Post subject: Reply with quote

Great comments so far. More are welcome and appreciated.
Back to top
View user's profile Send private message Send e-mail
corrupt



Joined: 29 Dec 2004
Posts: 2402

PostPosted: Wed Jan 19, 2005 10:05 am    Post subject: Reply with quote

I think it may make code a bit easier to read.

True = 1 or -1
False = 0

?
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Jan 20, 2005 12:22 am    Post subject: Reply with quote

Currently, false is any variable that is empty or that contains 0 or 0.0. True is everything else, including 1, -1, or any other string.

However, when you assign true to a variable, or when an expression evaluates to true such as (1 > 0), the result will always be 1. This is done for consistency and also because it's traditional.
Back to top
View user's profile Send private message Send e-mail
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Jan 23, 2005 4:14 pm    Post subject: Reply with quote

Well, it's currently 4 to 1 in favor of the idea. Note that I do not vote in these polls, but if I were to vote in this one I would probably prefer it too.

If anyone has any more comments, feel free to post them. Also, I'll wait a few more days for more votes to come in.

Thanks.
Back to top
View user's profile Send private message Send e-mail
Rajat



Joined: 28 Mar 2004
Posts: 1718

PostPosted: Sun Jan 23, 2005 4:46 pm    Post subject: Reply with quote

though i don't plan to change my scripting ways due to this change, it seems fine if it doesn't break my existing scripts. Confused
_________________
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Sun Jan 23, 2005 4:58 pm    Post subject: Reply with quote

I think the only ones that would be broken are those that use the words true and false as variable names. Even those will not be broken in a bad way because the syntax checker will alert you the moment you launch such a script.

Still, breaking scripts is never a good thing. I feel it is only warranted when there is a significant benefit, which is what this poll is trying to find out.
Back to top
View user's profile Send private message Send e-mail
JSLover



Joined: 20 Dec 2004
Posts: 542
Location: LooseChange911.com... the WTC attacks were done by the US Gov't... the official story is a lie...

PostPosted: Sun Jan 23, 2005 5:19 pm    Post subject: Reply with quote

Chris wrote:
Could be written instead as:

I don't care if they become aliases for true & false, but I don't want them to be the only way to determine true & false...so in your example, I'd still wanna be able to do the before...if you follow C & JavaScript's idea of true & false, I'll be at home...you CAN use true & false to check, but you can check other ways too.
_________________

Home • Click image! • Blog
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Mon Jan 24, 2005 12:20 am    Post subject: Reply with quote

Yes, the shorthand method such as "if Done" will still correctly check whether Done is true or false. You would also be able to write "if (Done = true)" if you prefer the long method.
Back to top
View user's profile Send private message Send e-mail
deguix



Joined: 26 Aug 2004
Posts: 72
Location: Everett - MA, USA

PostPosted: Mon Jan 24, 2005 1:51 am    Post subject: Reply with quote

(Hmmm... ignore this post because I forgot that you wanted to do like: var1 := true so I agree)
_________________
Working now on:
NSIS Wiki (NSIS)
Back to top
View user's profile Send private message
hh



Joined: 05 Dec 2004
Posts: 13

PostPosted: Mon Jan 24, 2005 6:25 pm    Post subject: Reply with quote

it clearly improves code readability.
i can't really see any disadvantages - not any that matter to me anyways.

so, my vote was a clear yes.
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Tue Jan 25, 2005 1:55 am    Post subject: Reply with quote

True and False exist as built-in variables in the latest version. Thanks for all the votes and comments.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   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