News for hackers. Stuff that matters.
Re:Lua: Good, bad, and ugly parts by shaneeb on Saturday March 09, 2013 @11:35AM (#5348804)
Orthogonal in the sense that the same concept is used if you need maps/arrays or for namespacing functions or metatables(for metaprogramming). Its like a "core" concept that binds seemingly different features in an coherent way. Havent seen a concept used this elegantly in any other language
Re:Lua: Good, bad, and ugly parts by gruseom on Saturday March 09, 2013 @11:42AM (#5348827)
Lists in Lisp, objects in Smalltalk, arrays in APL, stacks in Forth. Lua keeps first-class company.
Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @02:57PM (#5349418)
I find Lua's use of tables as a universal container to be clumsy. For example:

  local array = { one, two, threee, four }
A gap is silently created in the array because Lua returns nil for undefined variables. This causes the (#) operator to an return incorrect result and can lead to subtle, difficult-to-find bugs in the program.

Lua makes no distinction between nil and a non-existent element, so assigning nil to an array element will also create a gap, rather than shifting the keys of the subsequent elements downward:

  local array = { 1, 2, 3, 4 }
  array[2] = nil
  -- array is now { [1] = 1, [3] = 3, [4] = 4 }
Re:Lua: Good, bad, and ugly parts by groovy2shoes on Saturday March 09, 2013 @10:11PM (#5350544)
If you want the array elements to shift into the gap, you want to use table.remove:

    local array = {1, 2, 3, 4}
    table.remove(array, 2)
    -- array is now { [1] = 1, [2] = 3, [3] = 4 }
Re:Lua: Good, bad, and ugly parts by gruseom on Saturday March 09, 2013 @05:18PM (#5349819)
Your second example is not "clumsy", but a consequence of how Lua's tables are simple and cleanly designed. It would be weird magic for the elements to suddenly shift downward. One can do that oneself if need be.

Your first example has a point – perhaps undefined variables should error when accessed – but that's got nothing to do with tables.

Re:Lua: Good, bad, and ugly parts by vor_ on Saturday March 09, 2013 @07:15PM (#5350103)
Array keys shifting downward wouldn't be weird magic; it would be the expected behavior when removing an element from an array. Dismissing it as simply how Lua's tables are designed doesn't make it intuitive or expected.

> Your first example has a point – perhaps undefined variables should error when accessed – but that's got nothing to do with tables.

Well, of course it does. The point is that you can silently end up with array "holes" due to a typo, which you are supposed to avoid in Lua for a number of reasons, such as an the length operator returning an incorrect result. I don't understand why my previous comment is getting voted down for pointing this out.

Re:Lua: Good, bad, and ugly parts by stcredzero on Saturday March 09, 2013 @04:38PM (#5349715)
> Havent seen a concept used this elegantly in any other language

Object in Smaltalk.

Re:Lua: Good, bad, and ugly parts by Shorel on Saturday March 09, 2013 @11:51AM (#5348867)
Go back to Linear Algebra class.
Re:Lua: Good, bad, and ugly parts by ubercow13 on Saturday March 09, 2013 @02:26PM (#5349315)
That was unnecessary. The meaning is the same.