6 ms·
My favorite thing about Lua is that the language is so simple, once you figure out one way to do something it's probably the only way. Like, say, summing up all
by NelsonMinar 13y ago
My favorite thing about Lua is that the language is so simple, once you figure out one way to do something it's probably the only way. Like, say, summing up all the numbers in a list of strings. In Perl there are many ways, in Python there are many ways but one is right, and in Lua there's probably only one way so once you figure it out, you're done. Simplicity is a nice thing in an embedded tool language.
- eieio 13y agoAs a huge Python fan, comments like this(and many others) have made me want to check out Lua. Is there a canonical Lua introduction out there? I'd love to give it a try.
- mintplant 13y agoThis was posted here a while back: http://learnxinyminutes.com/docs/lua/ http://learnxinyminutes.com/docs/lua/
- gebe 13y agoThe PIL, http://www.lua.org/pil/ http://www.lua.org/pil/, is as canonical as it gets, written by the creator of Lua.
- oblique63 13y agoAlternatively, there's also http://luatut.com/ http://luatut.com/ for a quick useful intro
- Derbasti 13y agoReally an awesome book! It not only teaches you about the programming language itself, but also how to use it well and idiomatically. Also, it is very focused and compact, which is a great thing in a programming book--although it makes for kind of a dry read.
- Elv13 13y agohttp://tylerneylon.com/a/learn-lua/ http://tylerneylon.com/a/learn-lua/ as simple as it can get. Lua is a very small (in term a amount of syntax) language.
- phaedryx 13y agoI first started playing around with Lua here: http://repl.it/languages/Lua http://repl.it/languages/Lua
- joelg236 13y agoTry http://learnxinyminutes.com/docs/lua/ http://learnxinyminutes.com/docs/lua/
- speeder 13y agoIt is not like that... Most things can be done in many ways, some of those in excessively many ways... It just happen that for most projects any of.them are "right" except the most esoteric ones... You can fully pull some crazy "clever" stuff, but requires effort, usually the first idea in your head is already good enough.
- sheng 13y agowould you mind to state some of the so many ways of summing up all the numbers in a list of strings for python? And give a counter example for lua?
- plorkyeran 13y agoOff the top of my head: list = ["1", "2", "3"] sum1 = sum(int(num) for num in list) sum2 = reduce(map(list, int), operator.add) sum3 = 0 for num in list: sum3 += int(num) Lua only has the third of these three options. I don't really consider this a particularly compelling advantage as a user.
- oblique63 13y agoNo, but I think a lot of python users consider this a particularly compelling advantage as readers. At least, I know I sure spend a lot more time reading code than I do writing code; so I appreciate any language that tries to optimize for that use-case and helps me minimize my cognitive overhead.
- zeckalpha 13y agoThe second would work, if the functions were defined correctly.
- anonymoushn 13y agofunction curry(f,x) return function(...) return f(x, ...) end end function reduce(f,t,r) r = r or t[1] for i=2,#t do r = f(r,t[i]) end return r end addf = function(a,b) return a+b end sum = curry(reduce, addf) t = {"1", "2", "12"} print(reduce(addf, t)) -- 15 print(sum(t)) -- 15 res = 0 for i=1,#t do res = res + t[i] end print(res) -- 15 res = 0 for k,v in ipairs(t) do res = res + v end print(res) -- 15
- Kaali 13y agoLua is a really simple language, and is quite malleable to different use cases not included in the language per se. Usually in my book, it is an advantage, for example how many Lisps can implement new features that seem like language features, but aren't. But this simplicity can have a downside, as there might not be canonical ways of doing things that users are accustomed to. For example, object orientation. It could be a hard sell to someone coming from an object-oriented language, when you have to understand, and choose between multiple different styles of object-orientation and implement them consistently in your project, or use one of the many libraries made just for this. For example, see http://lua-users.org/wiki/ObjectOrientedProgramming http://lua-users.org/wiki/ObjectOrientedProgramming Lua really is simple, but it not always easy.
- anonymoushn 13y agoIt is a bit nice to not be limited by any particular OO system. I don't get much use out of this, since my current class.lua is about 14 lines and doesn't do inheritance, but it would be easy to add in the future. It's probably a bit easier for people with js experience to get used to OO in Lua. Coming from js, most of the language just seems like a copy with more expressive power and fewer mistakes.
- swah 13y ago...and it involves table-based programming.