lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Luiz Henrique de Figueiredo wrote:
Has it been pointed out, if/why it would be costly to throw an error for #t if a list t ever had holes?

The message by uki before yours says it all: "there is absolutely no way to
check if the table has holes, except by iterating through the whole table."



Things keep repeating here.
As a Lua newbie I was hit more than once by the unusual behaviour of tables, but I kept learning and, keeping it simple, now I can avoid most blunders most of the times.

I'm not saying that a more complex/feature-rich/safe data structure is never needed, but, as I said some time ago in another thread (but I was not the only one), maybe the problem with all this fuss over holes in tables and the like is that most people seem to see Lua tables as an high level data structure (some time ago I thought it too). Indeed they are, if compared with basic data structure of most common languages (C/C++ arrays, Java arrays, for example). But in a Lua perspective, IMHO, tables are best viewed as a low-level facility (even if very powerful), on which to build more complex/safe/user-friendly data structures.

The fact that a newbie can do amazing things with tables doesn't mean that they should be "idiotproof", as some Java data structures are (well at least a more clever idiot enters the game :-) )

Since it is the only data structure of Lua, the balance between ease of use, efficiency and readability attained is a benefit I wouldn't forfait. And as I learned reading this list, Lua authors have spent years to achieve that.

Instead of pushing for changing such a cleverly crafted aspect of the language, I would really spend time in advocating a standard collection of general-purpose library. I think that newbies (if they are the target of this thread) would better be served by an "almost endorsed" library with all the basic tools one usually find in other languages (say pure arrays, maps, sets, string manipulation functions, etc.).

This would smooth considerably their learning curve. I think that for a newbia is more frustrating to have the usual (on this mailing list) reply "but you can do that with these two lines of Lua code..." followed by some idiom that leaves one puzzled for a while (see tricks with 'gsub ' or 'match') (please don't beat me with a stick, I actually got to love some of these tricks _now_ ;-) :-) )


Best Regards

--
Lorenzo