Learning Lua

Sticking to my plans, I’ve begun teaching myself Lua. Although it’s a bit odd to wrap my head around after just diving head-first into C++, it’s pretty cool!

One lesson I’ve learned (or, rather, had reaffirmed) is how important writing clean code is. Given Lua doesn’t require semicolons to separate statements and doesn’t use braces, you can get away with some really sloppy, hard-to-read stuff. The following are all equivalent:

-- Easy to read factorial function
function fact (n)
   if n == 0 then
      return 1
   else
      return n * fact(n-1)
   end
end
-- Hard to read, but simple enough where you could probably figure it out
function fact (n) if n == 0 then return 1 else return n * fact(n-1) end end
-- Oh boy.
function
fact
(n) if n ==
0 then return
1 else
return n *
fact(n
-1) end

end

Having only really worked with C#, C++, Java, and ActionScript, it’s going to take some effort getting used to the syntax of Lua; however, I’m up for the challenge!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s