Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Tables -- boy, am I slow

edited February 2012 in General Posts: 1,255

I'm offering this as a cautionary tale. Having never seen Lua before, I looked into Codea examples and immediately siezed on the

t = {}
t[1] = "Hey there"

syntax, treating it like generic arrays available in any language. It wasn't until I came to the problem of creating a doubly-linked list among objects that I started having a few fits, tried something in desperation and found...

Anything can be a key. Sure, use a number. Yes, use a string. Hey, you can use an object. Holy Batman, you can even use the result of a function. The table functionality can WORK like an array, but it can also work like... well, a table, one that can be accessed in many different ways.

Now, if you took ten minutes to read the documentation on Lua, you probably got this at the outset, but trust me, it moves a whole class of problems from the barren lands of Massive Tedium to the happy hills of Trivial Solution. Objects that I was creating to handle intricate nests of pointers and states collapsed back to just their core data. Code that was scrolling off the page disappeared in great ugly gulps.

Let me just say... ahhh, that's better. And if you're not making use of the power of tables, give them a second look.

Tagged:
Sign In or Register to comment.