writing robust programs

Hi all,

Coming from languages like C#, C++, Python this lua+Corona experience feels a bit like handing over sharp loaded guns to 7 year olds and tell them to go out and play in the garden. There’s no way to say what will get shot.

In Python you put try: except: on various levels as you see fit. Even if you don’t bother to carefully check every statement, you can catch an error on a group that belongs together. Basically it turns out nice and robust in an intuitive way.

While it’s nice to only have to write…

testImage = display.newImage(filename,system.DocumentsDirectory,60,50);

…to add an image, I don’t quite see how to deal with errors.

Or a less trivial case

group = display.newGroup() local offs = 0 for row in db:nrows("select filename from images") do group:insert(display.newImage(row.filename,system.DocumentsDirectory,10,50 \* offs)); offs = offs + 1 end

Does any of the files not exist? Is any file corrupt? Memory overflow of the device?

Basically, how do I create a non amateurish application? I’ll make a swift acknowledgment that I’m a lua noob and probably should rtfm more.

Thanks,
Marcus [import]uid: 4441 topic_id: 1127 reply_id: 301127[/import]

I recomment reading up the lua documentation as lua.org and also the tutorials at there wiki. LUA is quite powerfull. [import]uid: 5712 topic_id: 1127 reply_id: 2892[/import]

Seconding Mike here, you should definitely read up some more.

I highly recommend the “blue PiL” (the latest programming in lua book, which is a purchase, but it’s cheap and you can get a PDF of it if you like) for really getting a feel for the power of lua.

It’s not meant to be a full blown 3GL… I’d call it more of a 2.5GL hehe. It’s very small (memory footprint), very fast (execution), and very powerful (almost all of traditional data types can be represented… and anything that isn’t one can write C extensions for (well, ansca could)). To be that way with a scripted language you end up sacrificing some things. And some things are left up to the developer to handle on their own.

Some parts leave a little to be desired and it does put the onus on the developer to write good code, but that is the case with any language. Some languages will force you to be a good developer more than others, but a lot of the time that forces you into a box as well.

At any rate, being a commercial developer in C++, I find Lua a lot of fun to work in due primarily to it’s simplicity. Once you understand how to really work within it, you’ll truly see how powerful it is. Of course, as you say, the gun is loaded and the objects are pointy. :slight_smile:

Scott [import]uid: 5659 topic_id: 1127 reply_id: 2895[/import]

I bought the book and it’s very nice to read. This doesn’t happen very often so I’m very positive surprised.

Thanks for the book suggestion!
Marcus [import]uid: 4441 topic_id: 1127 reply_id: 3121[/import]