Allow "not equal to" operator "~=" in Luau to be written as "!="

Who actually made the decision is irrelevant in this case, my primary point is that Lua/Luau is a programming language that conforms to the rules of its field (computer science) and not the rules of the mathematics field he wants it to so badly conform to.

1 Like

i think you alone on this :broken_heart: not worth fighting fo

many people learning luau are first time game devs (children), also lua is widely used in game dev spaces and i havent seen a game that prominently uses python

Well, it is a minor annoyance and I can guarantee you that it is not a problem worth talking in the DevForum. Sure it is quite an idiotic that the math logic and the Roblox studio logic don’t align, but posting it in the DevForum is a little to far.

So you’re saying not X == Y isn’t confusing to new developers?

I don’t understand how it would break legacy code if you couldn’t use != from the start since Roblox literally yells you to change it to ~=.

I also use Jetbrains Mono that changes >= to ≥. Using ~= doesn’t change it to ≠ and it looks really unappealing.

Sorry for bumping this one month later

This is wrong, you even get a warning for writing this because of it’s ambiguity.

image

Sounds like something that can be fixed from within your IDE, maybe as a setting

2 Likes

I think you didn’t understand me, I said not X == Y is confusing for new developers.
It’s not even correct because not 5 will return false, basically you gonna compare false == 4 which will return false unless the 4 becomes a false boolean.

About the IDE one I’m not so sure, I’m using Roblox Studio so I doubt there’s personalization for it.

It would be nice if we got negation using !. Using if !Player.Character then return end makes it look nicer than typing not.

2 Likes

Yes I just wanted to notify you that the syntax was wrong :upside_down_face:

I thought you said you were using Jetbrains Mono?

Luau would never receive this feature under the current guidelines:

Whenever new syntax is introduced, we need to ask:

  • Is it backwards compatible?
  • Is it easy for machines and humans to parse?
  • Does it create grammar ambiguities for current and future syntax?
  • Is it stylistically coherent with the rest of the language?
  • Does it present challenges with editor integration like autocomplete?

[…]

In addition to these questions, we also need to consider that every addition carries a cost, and too many features will result in a language that is harder to learn, harder to implement and ensure consistent implementation quality throughout, slower, etc. In addition, any language is greater than the sum of its parts and features often have non-intuitive interactions with each other.

From: GitHub - luau-lang/rfcs: RFCs for Luau evolution

The ! is not stylistically consistent with the rest of Luau’s syntax, and serves no functional purpose other than being a synonym.

Languages are different. Over the past few years I have written less and less Luau code compared to code in languages which have similar features like you describe (single-character negation, !=), but I am not angry at Luau for not having these features when I write Luau code every once in a while. You grow use to them, and you understand that it really means nothing in actual programming. It doesn’t matter. The ~ is literally right next to the ! key anyway. Learning multiple languages and becoming use to their differences will simply make you better at programming, which is language-independent, and will make it easier to learn new languages as well.

1 Like

It’s a font

1 Like

This post was solved two years ago, its not being added because it would be inconsistent with vanilla Lua and other dialects of it. (unless you’re glua and that ended well).

God damn it :sob: I’ve been finessed

1 Like

theres no lua ide for jetbrains

I don’t get the point of it being “inconsistent”. You can get the length of a string using the # operator, or using string.len(str) function, which both do the same. I know they are in vanilla Lua, but I have seen no one to cry about inconsistency because of that.

You can also concatenate a string either using the .. operator or string.format().

Now talking about the changes Roblox added to Lua is shortening variable addition, subtraction, etc…

local b = 5
b += 10
print(b) --> 15

This is a feature many languages have, and it doesn’t create any inconsistency either. You can either do it using b += 10 or using b = b + 10.

So why would it be a problem with ~= and !=? It’s not like changing the starting index to 0, which would break lots of code.

Also another thing Roblox added is the Random class.
You can either use that like Random.new():NextInteger(1, 100) or math.random(1, 100) which litreally do the same. Isn’t that inconsistent?

1 Like

Luau will not be adding additional syntax for inequality or negation. We follow a design philosophy similar to C#'s Minus 100 Points meaning that every individual feature we’d want to consider adding to the language is “in the hole” so-to-speak and needs to significantly justify itself in order to warrant being worth the addition. This feature would add no additional capabilities for programmers, add inconsistency between semantically-identical comparisons, would reserve the symbol ! for something that is already expressible in the language, and lacks a motivation beyond “similarity to other languages” (this is a useful component when designing new features, but it is never a reason on its own). As such, it does not hold up to the intentionally very high bar for the language.

I recognize this may nevertheless be disappointing to hear if you’re already convinced of the necessity of this feature, and I’m sorry for that! Designing a coherent product requires us to say no a lot though, even when there is nothing wrong with the idea in a vacuum. Whether or not you agree with the reasons folks do not feel this feature justifies itself, this is one such case where we have to say no. There’s no need to spend energy debating it further.

8 Likes

Random is not a feature of Luau, its a Roblox specific API, both use the same randomisation algorithm.

On the topic of strings, the reason this works is because strings just have a metatable pointing to the string table, so its just syntax sugar, this has legitimate usecases unlike != where it would just be replacing ~ with ! which is pretty redundant.

You could also argue that the : sugar call is inconsistent, because you can implement it with . by defining the first argument as self

local t = {}

function t.foo(self)

end

function t:foo()

end

Are you going to call this inconsistent behaviour?

1 Like

I get that Random is technically part of Roblox API and not Luau itself, but that’s kind of my point, it’s still available to use alongside math.random, and they both serve the same purpose. No one complains that’s inconsistent, even though they’re separate things with the same result.

And saying strings having a metatable makes it “legit” doesn’t change the fact that from a dev’s perspective, you can still do the exact same thing in two different ways: #str vs string.len(str). Whether it’s metatables or not, it’s still functionally redundant, and it exists to make things more flexible.

Same goes for : vs .. You can define methods manually by passing self, but Lua gives you the cleaner way using :. Is that inconsistent? Not really. It’s just more readable and easier to work with.

So why would adding != suddenly be a problem? It’s just another option, like how += was added. Nobody forces you to use it, and it doesn’t break existing code. If anything, it makes the language a bit more welcoming for people coming from other languages. It’s not like it adds confusion, it’s literally doing the same thing with a symbol people are already familiar with.

Rejecting it just because it’s “syntax sugar” ignores how helpful sugar is for writing clean, readable code, especially in a platform like Roblox where devs come from all kinds of backgrounds.


It’s like saying “Well, technically that’s not part of JavaScript, it’s part of the browser API” when we’re clearly talking about using it in the browser. Who cares? You’re still writing JavaScript for the platform.

Your point makes no sense here. You want something implemented in the language and are trying to justify that by using examples of things implemented to interface with the program in some way by said program that is only using the language.

But += serves an obvious purpose, it shortens what would normally be a much longer piece of code into a few characters (path.to.variable = path.to.variable + 6 vs path.to.variable += 6). But what does != serve? It doesn’t shorten any longer pieces of code by existing nor does it make anything more readable than it already is.

1 Like

Did you miss this by chance?

char limit

Yes

I am precisely saying that

It’s equivalent to saying “not true”

yes please lol i dont even know how to type that symbol on my keyboard because it aint available lol.

1 Like