News for hackers. Stuff that matters.
Re:What makes Lua tick? by NelsonMinar on Saturday August 10, 2013 @07:34PM (#6193079)
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.
Re:What makes Lua tick? by Kaali on Sunday August 11, 2013 @01:21AM (#6193950)
Lua 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

Lua really is simple, but it not always easy.

Re:What makes Lua tick? by anonymoushn on Sunday August 11, 2013 @03:21AM (#6194191)
It 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.
Re:What makes Lua tick? by eieio on Saturday August 10, 2013 @08:12PM (#6193164)
As 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.
Re:What makes Lua tick? by gebe on Saturday August 10, 2013 @08:14PM (#6193171)
The PIL, http://www.lua.org/pil/, is as canonical as it gets, written by the creator of Lua.
Re:What makes Lua tick? by oblique63 on Saturday August 10, 2013 @08:18PM (#6193187)
Alternatively, there's also http://luatut.com/ for a quick useful intro
Re:What makes Lua tick? by Derbasti on Sunday August 11, 2013 @06:44AM (#6194640)
Really 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.
Re:What makes Lua tick? by mintplant on Saturday August 10, 2013 @08:58PM (#6193292)
This was posted here a while back: http://learnxinyminutes.com/docs/lua/
Re:What makes Lua tick? by Elv13 on Saturday August 10, 2013 @08:22PM (#6193197)
http://tylerneylon.com/a/learn-lua/ as simple as it can get. Lua is a very small (in term a amount of syntax) language.
Re:What makes Lua tick? by phaedryx on Saturday August 10, 2013 @09:22PM (#6193361)
I first started playing around with Lua here: http://repl.it/languages/Lua
Re:What makes Lua tick? by joelg236 on Saturday August 10, 2013 @11:32PM (#6193726)
Re:What makes Lua tick? by speeder on Saturday August 10, 2013 @08:21PM (#6193193)
It 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.

Re:What makes Lua tick? by sheng on Saturday August 10, 2013 @08:55PM (#6193281)
would 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?
Re:What makes Lua tick? by plorkyeran on Saturday August 10, 2013 @11:20PM (#6193698)
Off 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.
Re:What makes Lua tick? by anonymoushn on Sunday August 11, 2013 @03:14AM (#6194182)

  function 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
Re:What makes Lua tick? by oblique63 on Sunday August 11, 2013 @12:02AM (#6193786)
No, 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.

Re:What makes Lua tick? by zeckalpha on Sunday August 11, 2013 @12:41AM (#6193872)
The second would work, if the functions were defined correctly.
Re:What makes Lua tick? by swah on Sunday August 11, 2013 @07:30PM (#6196807)
...and it involves table-based programming.