3 ms·
Anything that's trivial to write (think "left pad" and 90% of what's in NPM & PIP) shouldn't be used by people who can't conceive of how those things might be w
by enkiv2 10y ago
Anything that's trivial to write (think "left pad" and 90% of what's in NPM & PIP) shouldn't be used by people who can't conceive of how those things might be written, if their goal is to learn to write things. I'm not suggesting that beginners should start with writing bootloaders in machine code or anything; I'm suggesting that beginners should master things like loops and functions and variables before they start plugging together big chunks of other people's code, lest they overestimate their abilities and take a major blow to their self-esteem when they realize that they are completely incapable of doing simple things in another environment because they never really learned how to do things. Some of the biggest and most important hurdles to clear when learning to code are related to learning to master things you've never considered; convenient API calls are convenient to avoid considering. In this way, a tiny standard library is useful: all of the things in Lua's standard library are things that a beginner can afford to put off learning for a little while.
Lua has a handful of strange attributes that distinguish it from most programming languages -- 1-indexing, lack of a distinction between integer and fractional numeric types, lack of a distinction between integer-keyed and non-integer-keyed arrays (and lack of distinction between arrays and objects), and the use of tilde rather than exclamation point in comparison. The number of idiosyncracies is comparable to those in python and javascript. I don't think that distinguishing between arrays and objects is useful for a beginner, nor do I think that the fact that in most languages integer-keyed arrays are special for optimization reasons is terribly important for a beginner. And, metatables are an advanced feature -- they are similar to mechanisms in python and C++ and aren't all that weird, but they won't even come up until long after our hypothetical student is ready for their second and third language.
A first language is for learning. Whether or not it's useful for real work is totally irrelevant; someone who doesn't know ten languages inside-out isn't qualified for real work in any of them. Lua is a good candidate because although it can be used for real work, it's not optimized for that. Instead, it's a simple language that combines ideas that have historically been separated for reasons related to ease-of-implementation and separates ideas that have historically been combined to make ugly hacks possible. In other words, it's a fairly internally coherent and conceptually pure language that is easy to pick up because it lacks "gotchas" (except to people who come from other languages, and are offended by Lua's improvements).
- striking 10y ago90% of what's in npm or pip is not trivial to write. Calling database adapters or HTTP libraries "distractions" is silly. And in the same sense, restricting yourself to a subset of a language that makes it easily ported and contained within any application seems... silly. Furthermore, plugging together pieces of other people's code can very much help in learning how to express concepts in the language. You can look at existing examples of how it's done, and do it yourself. You make small changes, then big changes, then write your own. Easy peasy. Lua is a weird language for many reasons. Not that being weird is a bad thing, but that makes it difficult for people to learn other languages. If you learn a C-style language, you'll be more able to read other C-style languages. And no, metatables are integral to Lua. You can't use prototypical inheritance without them, and they're really difficult to wrap your mind around. Furthermore, prototypical inheritance is very useful. If you've actually learned Lua, you've got to learn about that aspect of metatables. I love Lua for real work. Honestly, actually do. But I don't love Lua for learning.
- enkiv2 10y agoYou need metatables for rolling your own OO system. But, object orientation (particularly when, as in Lua, you need to roll your own) should not be part of a beginner curriculum. Like I said, by the time you need to worry about metatables, you should have already moved on to your second and third languages -- you can learn about OO in the context of Python or JavaScript and then later apply that to Lua.