News for hackers. Stuff that matters.
Re:Lua and Python (2020) by BugsJustFindMe on Friday January 15, 2021 @03:55PM (#25796310)
> There error messages aren't great

No language has _great_ error messages. But comparing the Lua message for e.g. `print(nil+5)` to the Python message for `print(None+5)`, I somewhat prefer Lua's natural language approach "attempt to perform arithmetic on a nil value" over Python's jargon-heavy "TypeError: unsupported operand type(s) for +: 'NoneType' and 'int'". Of course Lua's message could be better (it could/should tell you which operation and where the nil is in the expression), but "not great" basically describes every language's error messaging, and Lua's messages are not exactly eye-bleeding like C++ STL errors either.

> the 1-indexed arrays

1-based indexing is actually really human friendly, and programmer affinity for 0-based indexing in languages that don't map directly to RAM pointer offsets is largely excess familiarity with C plus cargo-culting and wanting to believe that everything Djikstra ever said is universally true regardless of context. Indexing by 1 gives many nice human-oriented properties, like for instance that indexing the front and back is symmetrical (first is 1 and last is -1), whereas in 0-based languages you have 0 and -1 which makes a lot less sense (people who haven't been bent to the will of the C language gods don't think of the last element as one before the first one, it's all the way at the end) except as a conceit to the fact that there's no -0 available. It's easier to reason about a list of five things where the first element is the first and the fifth element is the fifth, instead of constantly having to do mental -1 arithmetic to satisfy a paradigm that requires visualizing hardware memory layouts.

And if you really really really want to cycle over an array using modulus operations, the classic "0 is better" example that people love to trot out, Lua also lets you start your array at 0 if you want. Lua doesn't care what you use for table keys as long as they're not nil.

> the syntax is super weird

Is it? I teach Lua to people, and most novice programmers I meet find the syntax quite intuitive with its plain english keywords and operators. Do you think "function" is more weird than "def" or "sub", "or" more weird than "||", "not" more weird than "!"?

Re:Lua and Python (2020) by hermanradtke on Friday January 15, 2021 @04:07PM (#25796499)
> No language has _great_ error messages.

Elm and Rust have great error messages.

Re:Lua and Python (2020) by BugsJustFindMe on Friday January 15, 2021 @05:13PM (#25797235)
I was almost going to argue with you, but Rust takes pride in actively developing and improving error messaging and it is strongly to their credit.

So instead of "no languages" let's instead say "very few languages, and none of the top 8 languages according to TIOBE". (Rust is now #9 as of like just now when it was #18 a year ago, so mad props to them for breaking into the top 10!)

Re:Lua and Python (2020) by hisham_hm on Friday January 15, 2021 @08:56PM (#25799164)
And credit where credit's due, Rust got into that inspired by Elm.
Re:Lua and Python (2020) by gugagore on Friday January 15, 2021 @04:29PM (#25796794)
I love that example of the lua error message, but aren't there non-arithmetic functions that also error? What's the message in that case?

What's nice about Python's message is how compositional or "orthogonal" it is, which means that the errors can easily be handled in a program. Does Lua have anything like that? From the manual

> If you need to handle errors in Lua, you should use the pcall function (protected call) to encapsulate your code.

This actually helps me understand a bit the dichotomy between "configuration" and "program", and why Lua is so good for the former. As another comment put it, it's good when you need to "describe stuff". It doesn't make a lot of sense to describe something that handles errors in its own description, which motivates relegating error handling to specific contexts.

Re:Lua and Python (2020) by BugsJustFindMe on Friday January 15, 2021 @05:03PM (#25797134)
> aren't there non-arithmetic functions that also error? What's the message in that case?

Any function can error in any way imaginable, but if we're talking about built-ins...

`print(nil.."a")` -> "attempt to concatenate a nil value"

`print(({}).foo.bar)` -> "attempt to index a nil value (field 'foo')"

`table.insert(a, 1)` -> "bad argument #1 to 'insert' (table expected, got nil)"

On the Python side you get:

`None[1]` -> "TypeError: 'NoneType' object is not subscriptable"

`str.split(None, "d")` -> "TypeError: descriptor 'split' for 'str' objects doesn't apply to a 'NoneType' object"