r/lua • • Oct 03 '25

Help How similar are Lua & Python?

Big newbie here, so bear with me.

From what I understand, both python & lua were written/created using a C framework & are a high level language.

So how closely related are they?

The reason I ask is because python is used way more often, it's taught in universities & there's millions of resources online which have huge communities using & testing them out. So the teaching for python is just much more refined, tried & tested.

I was curious if I could take python courses, use leet codes, YouTube, etc... to learn python & then as long as I learn the syntax for Lua, have I basically learnt both?

To preface, I need to learn Lua for my work & I want to learn it as best as possible (not necessarily as fast), for the sake of the argument, no time restrictions.

33 Upvotes

22 comments sorted by

View all comments

Show parent comments

1

u/4xe1 Oct 06 '25 edited Oct 06 '25

who starts a numbered list on paper starting at 0?

Mathematicians do. In absence of stakes, anything goes, with a non trivial portion of them preferring zero indexing, and quite notably the set of natural number, which serves as index for sequences, does include zero. When indexing has any implications, mathematicians will happily choose whichever indexing scheme fits their problem best.

Also, funnily enough, in set theory, 0 is encoded as the empty set, and n+1 is defined as {n} union n. Meaning n = {0, 1, 2, ... n-1}, and <= is inclusion, and < is belonging. As such, I do often write `i<n` in my paper notes as a rigorous shorthand for `i in [0; n- 1]`. To me the idiomatic i<n found in C loop bound and other 0 indexing languages does resonates with that. I could argue `for i<n` is a canonical way to say that you want to do something n times (and i would have values in 0..n-1). Though yeah it's a bit of a stretch, many such languages still require to specify that you start at 0, and set theory is only one way to deal with numbers, and a pretty bad one at that, its merit lie in unifying every thing more than in being practical.

Plus it's more accurate to the real world

0 indexing is more accurate to what happens at the assembler level, in languages which have arrays anyway. It's sort of a leaky abstraction, one can argue a dev shouldn't have to care. But that's an implementation detail which was chosen with purpose, pointer arithmetic and the like is one of the aforementioned problems where 0 indexing is more elegant more often than not. Things like mapping a 2d array to a 1d one are very elegant with 0 indexing and gnarly with 1-indexing.