logoalt Hacker News

widdershinsyesterday at 1:04 PM4 repliesview on HN

I agree on all points, especially the idea of using Lua as a first language. It has so few features that you're really forced to focus on fundamental concepts like functions and (simple) data structures. And its flexibility to be used in an imperative or functional manner is great too. It's almost like a stripped back Javascript, and anyone who learns it will find jumping to JS easy.

I guess one might argue that 1-based indexing could cause beginners to get confused when they move to another language. But maybe it's good for them to get used to the idea that things like this can be different across languages.


Replies

lucasoshiroyesterday at 4:40 PM

> I guess one might argue that 1-based indexing could cause beginners to get confused when they move to another language.

The creator of Lua once visited my university, he told us about the 1-indexing (it looked like this is the thing that everybody asks him). Lua was created in a time that 0-indexed languages wasn't so dominant over the 1-based languages.

Lua is older than Java and JS, and a few years newer than Perl and Python. Before those, as far as I remember about more popular languages: C and C++ are 0-indexed; COBOL, MATLAB and FORTRAN are 1-indexed; Pascal can be 0 or 1 indexed, but its for loop is better suited for 1-indexed.

This way, there wasn't a strong bias to use 0-index in a new language as we have today, they could use what made more sense. Since it was created for engineers used to math notation (sum, products and matrices generally are 1-indexed) and without background in programming, they have chosen to start in 1.

*However*, about using Lua for studying algorithms and data structures, some books use 1-indexed arrays in their pseudocode, notably CLRS' Introduction to Algorithms. When I was studying algorithm analysis using CLRS I used Lua to implement them. I still prefer 0-indexed languages, though.

sitkackyesterday at 2:06 PM

The other great thing about Lua is the utter sparsity of the standard library, it teaches one to think for themselves instead of only taking goods off the shelf.

show 1 reply
vascocostayesterday at 2:12 PM

Your analogy to a stripped back version of JavaScript is really on point. I feel that way about Lua too. Through time Lua kept its simplicity, whereas ECMAScript kept accreting stuff which most of the times makes life easier, but also gives way too many choices for how to do the same thing.

Indeed the 1-based indexing, which often generates heated discussions, could be a source of confusion later on. However, like you mentioned, it can also prompt the beginner to quickly understand the languages are just tools, which have slightly different ways to be used, depending on what they're trying to solve.

In fact, this 1-based indexing is by convention (although everyone uses it), once again showing how flexible and "hackable" Lua is.

show 1 reply
giraffe_ladyyesterday at 3:57 PM

I've taught programming to beginners, both children and adults, and lua is the worst of the languages I've done it with. It's an amazing technical accomplishment, and CS students should study its implementation. But for actual beginners its "focus on fundamental concepts" and flexibility are liabilities.

The main struggle people have learning to code is getting over the initial frustration hurdle where they can't actually accomplish anything yet. What they have to get them through this is excitement about their actual goals. With lua you burn too much goodwill and beginner spark on debugging string manipulation functions that don't seem important to the actual interest or goal that brought them to programming. Or figuring out how to use luarocks so you can make http requests, or regex, or whatever.

> 1-based indexing could cause beginners to get confused when they move to another language.

This is so far from the problems that beginners actually have. You should teach some programming, it's a really fascinating experience that will mess with your intuitions about how people learn this skill, and what's hard about it.

show 3 replies