Is there a reason to not have OR operator assignment?

Discuss the future of the AutoHotkey language
iseahound
Posts: 571
Joined: 13 Aug 2016, 21:04
GitHub: iseahound

Is there a reason to not have OR operator assignment?

12 May 2020, 21:24

Ternary - If a exists (and is non-zero) do nothing, otherwise assign the value 2.

Code: Select all

a := (a) ? a : 2
MsgBox a
OR - If a does not exist or is zero, assign the value 2

Code: Select all

a := a || 2
MsgBox a
OR Assignment - Assign the value 2 if it has no value.

Code: Select all

a ||= 2
MsgBox a
The symbol ||= reminds me of the turnstile in philosophy where it coincidentally has a similar meaning.

I checked C/C++, C#, Python, and Javascript, and none of them have OR-assignment. Is there a reason why? It's essentially non-overwriting assignment.
lexikos
Posts: 6975
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Is there a reason to not have OR operator assignment?

22 May 2020, 20:54

I think it would mostly be useful for a style of programming where initialization is omitted. So in other words (subjectively), it would be encouraging poor programming.
lexikos
Posts: 6975
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Is there a reason to not have OR operator assignment?

21 Jun 2020, 00:24

I was going through old topics and found that this has already come up: ||= and &&= operators

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 7 guests