Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding binary operator: !== and changing !=. #104

Merged
merged 1 commit into from
Aug 12, 2018

Conversation

HelgeffegleH
Copy link
Contributor

Hello 👋 .

New:
operand1 !== operand2,
x !== y is equivalent to !(x == y) (always case sensitive)
x != y is changed to be equivalent to !(x = y) (never case sensitive)

Example:

msgbox 'a' !== 'A' ; 1
stringcasesense 'on'
msgbox 'a' != 'A' ; 0, previously 1

Reason:
Convenience, readability (subjective), predictability. Probably some performance gain in eg, (x !== y) vs !(x == y)

Cheers.

New:
!==:
operand1 !== operand2
x !== y is equivalent to !(x == y)	(always case sensitive)
x != y is changed to be equivalent to !(x = y) (never case sensitive)

Reason:
Convenience, readability, predictability. Probably some performance gain in eg, (x !== y) vs !(x == y)
@Lexikos
Copy link
Collaborator

Lexikos commented Jun 25, 2018

I like that = and != would be more symmetrical, although <= and >= are similarly combined with = but are still dependent on StringCaseSense.

@HelgeffegleH
Copy link
Contributor Author

Hello.

<= and >= are similarly combined with = but are still dependent on StringCaseSense.

It might seem natural to implement <== and >== to be case sensitive and change <= and >= to never be case sensitive. However, I had something else in mind, I had planned, but not finished planning, to implement a strCompare function to replace <, >, <= and >= for string compairsons, they would then only do numeric compairsons. I do not think <, >, ... are useful for string compairsons in general. Typically, there is a loss of information which require an extra compairsion, eg,

if stra < strb
	; A
else if stra > strb
	; B
else
	; C

vs.

result := strCompare(stra, strb)
if result < 0
	; A
else if result > 0
	; B
else
	; C 

Also, it has already become clear that the ability to have both string and number types on either side of the operator causes confusion. That is, eg, vara > varb may be

  • 1) string comparison if one variable is a pure number but the other is a non-numeric string
  • 2) string comparison if both variables are strings, numeric or not.
  • 3) numeric comparison if one of the variables is a pure number and the other is a numeric string, or both are pure numbers.

strCompare would have option to select case sensitivity or locale, I think it would be nice to be able to choose which locale to use too. Maybe something like StartingPos and/or Length parameters would be useful too, I leave it to the readers imagination to figure what I mean.

<, >, ... would throw for non numeric operands..

In contrast, I think = == != !== are very useful for string compairson. Also, == and !== does memcmp which I guess <== and >== would do too, although I'm not sure that is very useful.

Cheers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants