[Beta] if local Statements and Expressions

maybe if you want your code to be slow to the point its unusable. im convinced classes are only being attempted because you guys have too many beginners using metatables everywhere and increasing server costs.

why not just try teach people to use modern paradigms and ecs? the industry is currently moving away from oop which can be verified yourself.

1 Like

It’s not the paradigm’s issue if your code is so un-optimized to the point its unusable.

2 Likes

Can I see that git possibly? Couldent find it on ur profile.

The RFC link was in the post…
https://github.com/luau-lang/rfcs/blob/if_local/docs/syntax-if-local.md

1 Like

You are entirely incorrect, in development of every programming language it always matters what people ask for.
Might be a little different now with some languages focusing on LLMs, but that’s a separate topic.

You also contradict yourself as you propose adding features you care about.

Doesn’t seem that you want to contribute to the discussion in any meaningful way, so do not see a point in continuing along this thread further.

6 Likes

i dont know why all of you roblox staff are so elitist and just making statements without any proof or verifiable claims.

if you add every single thing people ask for you will have a language that has every single feature and every single problem which is simply a bad language.

when did i contradict myself? those arent features i care about but features that have logical benefits rather than just adding a feature for the sake of it.

For stuff like this, I would prefer for the multi-return option (local ok, result = pcall(riskyFunction)) or the one I forgot the name (local x, y = foo(), bar()) to only evaluate the first parameter. And for compound conditions (local x = foo(); local y = bar()) to validate the first return of every one, but being separated by an and or an or instead of ;

Personally, I’m a never nester, so I will probably not use this nice sugar syntax for non-spaghetti code.

I both like and don’t like this. I prefer guard clauses rather than deep nesting, so this syntax, personally, has limited usefulness.

I really like this new feature, but I do have some criticism in regards to it (I don’t know if this is beta behaviour):

  1. if locals only seem to work when the next token is a local identifier which isn’t really ideal for this kind of syntax because I really want it to support and and or chaining. An example of what this means:
if humanoid.Health > 0 and local rootPart = character:FindFirstChild("HumanoidRootPart") then
    -- Do something in this block `'A`
end
  1. This should also be introduced for while loops aswell since it could really be a good feature with purposes similar to the if local. Example:
while local byte = reader:nextByte() do
    -- Do something in block `'B`
end
  1. As mentioned previously, this should be treated as an expression. This will be complicated to implement because you’d have to restrict when this expression can actually be used.

All in all, I think it’s a great concept and a great feature but it’s not at it’s fullest potential.

1 Like

It appears it will eventually be a part of the feature, however I do not believe they have implemented it yet.


From the RFC

1 Like

Thanks for testing it out!

if locals only seem to work when the next token is a local identifier

We’re currently keeping this out of scope because you could define the local rootPart = ... within the initial if block

This should also be introduced for while loops as well

Yep! We’ve gotten good feedback about wanting while local, so support is currently in implementation/testing stages, so it will be a part of the beta when it’s ready!

Stop right there. They aren’t adding literally everything people ask for.

Though they are adding a few highly requested features every now and then, which is exactly how an open-source project should work. You’re making a product for its users, so if most of them collectively agree it would be useful, and you (the developer) consider it reasonable to implement as well, it will be added. I don’t see any issue with that.

Besides, if they should not listen to people, that would mean they shouldn’t listen to you either? I think that’s where the contradiction he was talking about was. I get that you simply want them to add more useful features, but it seems you have very different definitions of “useful”. Almost everyone else, including the developers, genuinely find this feature useful. So telling them that they’re not adding useful features doesn’t get you guys anywhere. Maybe less “do it better” and more “this is why this particular feature does not make sense to add,” if that is your opinion.

I’d also really like to know how exactly updates like these actually ruin your experience with the language? It’s an entirely optional shorthand intended to make code cleaner. If you don’t like it, that’s completely fine, you are not obligated to use it.

6 Likes

I do have a question regarding this new feature:

Will the local binding be introduced as an expression that is only valid in specific contexts, or as hardcoded syntax only usable in if local and while local? I think this could also be implemented neatly in function parameters:

(This should probably be an RFC on GitHub but I’ll just throw it here):

Instead of reassigning the variables and adding lines of code (which can get annoying), a shortform syntax would be introduced that would basically merge this code syntax and the parameter definition. This would not have any side effects because parameters can only be identifier literals, but you could expand the syntax set like this:

local function createPart(name: string = "MyPart", parent: Instance = workspace, attribute = "UnattributedPart")
    local part = Instance.new("Part")

    part.Name = name
    part.Parent = parent
    part:SetAttribute("PartAttribute", attribute)

    return part
end

instead of writing

local function createPart(name: string, parent: Instance, attribute)
    name = name or "MyPart"
    parent = parent or workspace
    attribute = attribute or "UnattributedPart"

    local part = Instance.new("Part")

    part.Name = name
    part.Parent = parent
    part:SetAttribute("PartAttribute", attribute)

    return part
end

The first form would be desugared and collapse into the second form. I bring this up because parameters are locals (as far as I know) and could potentially adopt this new syntax. This would be a great change and I am forward to seeing the new if local feature expanding.

5 Likes

if local is not highly requested because the syntax does not fit luau and you cant claim something is highly requested without any proof. most experienced devs are likely to avoid it due to the fact its inferior to previous guard clauses in all ways. chaining two highly related keywords is also bad practice in language design and is largely proof that the creators dont understand it.

i dont see how you managed to reach the conclusion that im saying they should listen to me? if you tried using common sense you would realise that just because they are staff doesnt mean their additions shouldnt be challenged. i asked them to provide a valid reason for adding it and they refused which clearly shows they dont have a reason.

also i have already stated why it doesnt make sense to add maybe try read my messages first.

these features waste time that could be spent making other parts of the language better and increase complexity of the overall compiler. btw nice job contradicting yourself a total of 10 times in one message whilst saying i am.

This is just a beta, they’re adding support for tuples later.

No, it doesn’t. (according to the RFC)

player gets registered inside the if scope.

This seems pretty cool but would be a separate feature from the conditional bindings we’ve been talking about for if local and while local! This beta/feature just plans on adding support to bind a value in a condition, test/use it, and limit the scope to the block.

More than happy to talk about the default parameters feature you might be mentioning via an RFC or in the luau-lang discord we use to more casually discuss things!

I’ll get to working on an RFC for this feature, as to the Discord server, I’ve been banned for “being too immature” although other people have faced stupid bans aswell so I have to just create the RFC and wait.

1 Like