I believe we’ve covered ++ before - we don’t have plans to add it. There’s many reasons as to why
not:
Pre- and post- forms are usually considered a mistake in language design, because the return value isn’t immediately obvious to readers unfamiliar with the arcane rules
Having an expression that modifies the variable results in complex order dependent evaluation and easy to make mistakes along the lines of process(foo++, foo) – this is also why our compound assignment operators are statements, not expressions
Adding a ++ without -- would leave a glaring symmetry gap in the language, but -- can not be added since it already means a comment
I guess that could make sense and honestly slipped over my head there. I come from a C++ background so it’s easy to get used to a certain way of codebase design. But love the work, the if-then-else is something that I instantly knew I’d start using. I’m a person who likes clean, minimal but effective code.
Now I won’t need to do
local value
if condition then value = value1 else value = value2 end
Makes those circumstances much more cleaner and I’m all for it
Curious as to why it wasn’t implemented exactly like Python. I think local a = b if c else d would make much more sense to read out loud, as well as the expression be shorter since there is no need for a then. But regardless, I’ll be using this.
The order of evaluation is wrong and parsing it is problematic.
local a = print(1) if print(2) or true else print(3)
-- 2 gets printed first!
local b = print(1) if print(2) or true then print(3) end
-- this is actually 2 statements
local b = print(1)
if print(2) or true then print(3) end
-- figuring out if 'if' is an if statement or if expression is complex
-- with this syntax
The formatter within the script editor still thinks it’s an if statement without an escape (end) so it moves the next block of code a tab to the right.
Roblox types are really poor. I’ve had an extremely consistent experience with Roblox LSP, I’ve never had any issues with type definitions. (Only once with :SetCore)
Also shouldn’t Instance be able to be converted to Player? Is that a strict typing thing?
I wonder if they didn’t make Player the type because it wouldn’t be able to accept children properly. Not sure if Instance even does anyway.
The Roblox typechecker doesn’t automatically replace type’s with with types that inherit from the base, if that’s what you mean. To do that you have to do this:
for _,child : Instance in pairs(instance:GetChildren() do -- Child will default to any, even though :GetChildren only returns instance's. So you have to explicitly define it's type as 'Instance'
if child:IsA("BasePart") then
print(child) -- child will now show it's type as 'BasePart' when you hover over it
end
end
In other words, no, you cannot do this:
for _,child : BasePart in pairs(instance:GetChildren()) do
This is for good reason though, because while BasePartdoes inherit from Instance, it is only one of the many classes that inherit from it. Because Instance | Roblox Creator Documentation returns allInstance's under the object, not just those with type BasePart, it isn’t compatible.
That isn’t my point however. My point is that Instance:GetChildren returns type {Instance} while Players | Roblox Creator Documentation also returns the type {Instance} even though it should return {Player} since it already filters through the children so that it only returns the children of the type Player.
It explicitly says on the documentation page for Players:GetPlayers: “It functions the same way Instance:GetChildren would except that it only returns Player objects.”
There’s still end completion and indentation issues when using this new syntax. If there is a function in place of either ‘a’ or ‘b’ in if a then b else c it causes issues. Is there any word on if/when we can expect this to be fixed?
Unfreezing a table will never be allowed as it uses the exact same readonly mechanism that the global environment, Instance metatable, and many, many other objects use to protect themselves from malicious modifications. Providing an unfreeze operation would allow these sacred objects to be unprotected.
Plus, the point of freezing is to prevent modification.