4 ms·
I love Lua for its architecture and goals, but not for its linguistics... and this is more of the same. The platform is getting even better, but I feel like th
by Pxtl 6y ago
I love Lua for its architecture and goals, but not for its linguistics... and this is more of the same. The platform is getting even better, but I feel like the language is getting worse. <const> and <close> are kinda hideous, aren't they?
- aquova 6y agoI had heard that Lua was adding const support, which I was excited for, but I hadn't seen the syntax until now. I don't care for it. I'm guessing this is due to ambiguity as to whether variables declared as const would be local or global, but I would rather have something like const x = 1 local const y = 2 over what they're adding.
- ufo 6y agoThe problem with putting the "const" first is that it is ambiguous when there is more than one variable. For example, suppose that you want to open a file and test for errors: local f <close>, err = io.open("foo.txt") if not f then error(err) end vs local <close> f, err = io.open("foo.txt") if not f then error(err) end In the first version it is clearer that only the "f" variable is marked as a to-be-closed variable. The second version looks nicer when there is a single variable but is more confusing when there are multiple variables.
- Pxtl 6y agoEither way, why are the <> necessary? local f close = io.open("foo.txt") seems fine.
- ufo 6y agoThat wouldn't work because it is already valid Lua code with a different meaning. Lua parses it as a declaration of a local variable called f followed by an assignment to a variable named close: local f close = io.open("foo.txt") Despite the lack of semicolons, Lua is a free-form language and newlines are treated the same as any other whitespace character.
- pull_my_finger 6y agoI had a knee jerk reaction against it as well. But when you think about it, it kind of makes sense. A) these are properties of the variable, not the value. <close> triggers when the variable goes out of scope, and <const> supposedly was a feature that came out of implementing <close>. Both only work with local variables. B) the angle brackets leave room for extension with more properties in the future without creating an additional new syntax. C) you can multi-declare several variables with different properties i.e.: `local a <const>, b, c <const> = "apple", "banana", "carrot"` with only a and c being const. D) no new keyword(s) added to the language Compared to the simple syntax of the rest of the language it may be a little jarring, but it was well thought out and imo it's still better than weird stuff like "spaceship operators", "hashrockets" or other weird syntax oddities in more popular languages. Would you really prefer chains of keywords? `static const char *strprbrk` We have angle brackets now. If it turns out to be a mistake, I'm sure Roberto and his team will just take it back out of the language.