Coding style: Quotes around numeric values of variables

Get help with using AutoHotkey and its commands and hotkeys
john_c
Posts: 126
Joined: 05 May 2017, 13:19

Coding style: Quotes around numeric values of variables

22 Feb 2018, 07:43

Is it a good practice to use quotes around numeric values of variables?

Both versions do the same, but which one is better from the point of view of logic, consistency, etc? Do you use quotes here?

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

Last edited by john_c on 22 Feb 2018, 07:58, edited 1 time in total.
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Quotes around numeric values of variables

22 Feb 2018, 07:51

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % foo := 1+2
MsgBox % foo := "1+2"
Let's guess there's a difference ;)
john_c
Posts: 126
Joined: 05 May 2017, 13:19

Re: Quotes around numeric values of variables

22 Feb 2018, 07:54

BoBo wrote:...


Yes, I understand, but in original examples there were no math operations :)
BoBo
Posts: 2515
Joined: 13 May 2014, 17:15

Re: Quotes around numeric values of variables

22 Feb 2018, 08:29

john_c wrote:
BoBo wrote:...
Yes, I understand, but in original examples there were no math operations :)

I'd assume that its author assumed doing math operations are the main reason using numbers.

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox % foo := "one plus two"
MsgBox % foo := 1 + 2
john_c
Posts: 126
Joined: 05 May 2017, 13:19

Re: Quotes around numeric values of variables

22 Feb 2018, 08:55

BoBo wrote:I'd assume that its author assumed doing math operations are the main reason using numbers.


So, you will use quotes here? :

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

User avatar
jeeswg
Posts: 4508
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Coding style: Quotes around numeric values of variables

22 Feb 2018, 21:22

- For your example, mm = 1, I wouldn't use quotes. Although mm = "1", would also work in that particular example.

- Here's an example where quotes matter. If at least one item has double quotes, or string content that doesn't look numeric, a string comparison is done.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


- There is a difference in how AHK v1/v2 handle strings/numbers. I believe it works like this: numbers are stored as numbers and strings in AHK v1, however, in AHK v2, it's either/or. E.g. if you define var := 0xF in AHK v2, this is immediately converted to var := 15, there is no trace of the original appearance of the number as 0xF:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus

john_c
Posts: 126
Joined: 05 May 2017, 13:19

Re: Coding style: Quotes around numeric values of variables

23 Feb 2018, 06:35

jeeswg wrote:There is a difference in how AHK v1/v2 handle strings/numbers. I believe it works like this: numbers are stored as numbers and strings in AHK v1, however, in AHK v2, it's either/or. E.g. if you define var := 0xF in AHK v2, this is immediately converted to var := 15, there is no trace of the original appearance of the number as 0xF


I.e. the syntax becomes more strict. I think, it's good.

Return to “Ask For Help”

Who is online

Users browsing this forum: Mingo, MonuKashyap, tyyi and 16 guests