Jump to content




Lua: What would you change?


83 replies to this topic

#1 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 02 December 2013 - 09:30 PM

A discussion just came up with Symmetryc and I thought it'd be interesting to hear other peoples opinions as well.

Topic for discussion:
If you could change anything about Lua, what would you change? and if you wish to elaborate more, why?

I have but one rule.
If you're going to reply to this thread, be respectful, this is me asking peoples opinions, there is no such thing as a stupid or wrong opinion (I hope someone doesn't prove me wrong now :P). Feel free to ask them to elaborate, just don't be mean to them about their decisions, I'm trying to have this as an open discussion.

I guess I should start.
  • proper ternary operators/statements someCondition ? if-true : if-false why: the implementation we have available now just doesn't always cut it, it'd be nice to have a real one;
  • data type checking function foo(string bar) why: mainly 'cause of the next point;
  • function overloading requires above;
  • default parameter values function foo(string bar = "none") why: I hope this is fairly obvious too, its one of the only parts of Python that I like;
  • binary numbers b10011000 why: idk, sometimes I think it could come in handy to help visualise numbers in an environment where you're doing a lot of binary manipulation. Hex is the best we have currently;
  • a few random metamethods, such as __type why: I make my own implementation of this way too much for OO Lua;
  • a better assert function, preferably one like I made all that time ago that has support for the throwback levels! why: same reason as above, I make it way too often;
  • there was another, I've forgotten it, I'll edit this when I remember it;

Finally.
As you can see the things you'd love to be in can be completely bias as to why you want it, for example #5 and #6 for me is just because I always seem to be overriding to be adding functionality

What others have stated that I like the sound of.
  • Declare things by default with a local scope, and specify global with global keyword or global symbol. — Bubba — Yes one million times yes!

Edited by theoriginalbit, 03 December 2013 - 07:13 AM.


#2 Symmetryc

  • Members
  • 434 posts

Posted 02 December 2013 - 09:42 PM

(From the discussion we had)
1. __next, __type, __and, __or, __not, __len, __ne (~=)
2. Being able to set metatables of things that are not tables.
3. Better loadstring (that is not looked down upon :P/>)
4. table.insert returns the table that is being inserted into

Edited by Symmetryc, 02 December 2013 - 10:17 PM.


#3 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 02 December 2013 - 09:56 PM

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

* data type checking function foo(string bar) why: I hope this is fairly obvious

This isn't obvious to me. I can understand the desire for static typing but Lua isn't a static type language. Static typing is only really useful for compiled languages, which Lua isn't.

My main issues with Lua are syntactical. I prefer "if (condition) {...}" over "if condition then ... end". I'm always forgetting the 'then'. Same for for..do and while..do.

When it comes to using higher order functions the syntax really gets worse.

For example, if I want to pass in a predicate function (that is, some function that acts as a filter by returning true or false) in Lua the syntax is much worse than say C# which is what I work in daily.

Lua
doFoo(function(x) return x % 2 == 0 end)

C#
doFoo(x => x % 2 == 0)


#4 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 02 December 2013 - 10:05 PM

 distantcam, on 02 December 2013 - 09:56 PM, said:

-snip-
well for one, having static typing does allow for function overloading, which is one of the major things that I do want in Lua, but can only be achieved through type checking.

i know that it is not possible for Lua to have the functionality because it is not a statically typed language, however that being said this topic doesn't need to make sense in the realm of what it possible, it was more just me seeing what other people thought, even if it were not possible without changing everything about Lua. I find it very interesting to find out peoples ideas, perceptions, and opinions of programming, no matter how feasible it is.

#5 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 02 December 2013 - 10:14 PM

 theoriginalbit, on 02 December 2013 - 10:05 PM, said:

well for one, having static typing does allow for function overloading, which is one of the major things that I do want in Lua, but can only be achieved through type checking.

Ahhhh, ok then. I was only thinking in terms of usefulness with compiling, but function resolution would be another use.

I do like these kinds of thought experiments.

#6 jay5476

  • Members
  • 289 posts

Posted 03 December 2013 - 12:22 AM

i find that the moon is pretty good atm and i would not change it

#7 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 December 2013 - 12:48 AM

 distantcam, on 02 December 2013 - 10:14 PM, said:

Ahhhh, ok then. I was only thinking in terms of usefulness with compiling, but function resolution would be another use.
Yeh there's so many times where I've just wanted functions that are the same name but different args.

 jay5476, on 03 December 2013 - 12:22 AM, said:

i find that the moon is pretty good atm and i would not change it
There's always one :P

#8 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 03 December 2013 - 01:42 AM

 jay5476, on 03 December 2013 - 12:22 AM, said:

i find that the moon is pretty good atm and i would not change it

It should be made out of cheese.

#9 jay5476

  • Members
  • 289 posts

Posted 03 December 2013 - 02:33 AM

I know it should be made out of cheese but I want it to please even the people who are lactouse intolerant

#10 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 03 December 2013 - 03:01 AM

 distantcam, on 02 December 2013 - 09:56 PM, said:

My main issues with Lua are syntactical. I prefer "if (condition) {...}" over "if condition then ... end". I'm always forgetting the 'then'. Same for for..do and while..do.

I couldn't agree more. As I switch between many languages these little things get me off guard. Pretty much every language (that I use at least, Objective-C, JavaScript, PHP etc) use curly brackets. Another thing that gets me some times is using '=' in tables rather than ':' which is used in JavaScript.

Now I think of it, I do miss semicolons. I once wrote half my program with semicolons at the end of each line before having a massive facepalm a few minutes in. Although... it doesn't seem to cause crashes after a quick test. Hmmm

#11 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 03 December 2013 - 03:20 AM

 jay5476, on 03 December 2013 - 02:33 AM, said:

I know it should be made out of cheese but I want it to please even the people who are lactouse intolerant

Soy cheese then?

 oeed, on 03 December 2013 - 03:01 AM, said:

Now I think of it, I do miss semicolons. I once wrote half my program with semicolons at the end of each line before having a massive facepalm a few minutes in. Although... it doesn't seem to cause crashes after a quick test. Hmmm

You can use semicolons in Lua. They're optional. http://www.lua.org/pil/1.1.html

#12 oeed

    Oversimplifier

  • Members
  • 2,095 posts
  • LocationAuckland, New Zealand

Posted 03 December 2013 - 03:49 AM

 distantcam, on 03 December 2013 - 03:20 AM, said:

 oeed, on 03 December 2013 - 03:01 AM, said:

Now I think of it, I do miss semicolons. I once wrote half my program with semicolons at the end of each line before having a massive facepalm a few minutes in. Although... it doesn't seem to cause crashes after a quick test. Hmmm

You can use semicolons in Lua. They're optional. http://www.lua.org/pil/1.1.html

Yea, ok. You never really see anyone use them though.

#13 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 December 2013 - 04:02 AM

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

proper ternary operators/statements someCondition ? if-true : if-false why: the implementation we have available now just doesn't always cut it, it'd be nice to have a real one

The only real case where a ternary condition doesn't work is in this case:
var = condition and false or something_else
Where you wanted to set var to false if the condition was true. However, the easiest way to fix that is to reverse the condition and the "or"
var = not condition and something_else or false
If for some weird reason, the second and third values were false and nil, e.g. "var = condition and false or nil" (this statement would always evaluate to the last value, nil in this case), you're better off using an if statement, which is fine since most people don't really need to do this anyway.

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

data type checking function foo(string bar) why: I hope this is fairly obvious
Personal preference, but I'm fine with checking the type of the value if necessary.

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

default parameter values function foo(string bar = "none") why: I hope this is fairly obvious too, its one of the only parts of Python that I like
I agree on this one; the whole "value = value or default_value" syntax is pretty verbose and doesn't work if you want false as a default.

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

a few random metamethods, such as __type why: I make my own implementation of this way too much for OO Lua.
__type and __len (implemented in 5.2) would be very nice to have, yes.

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

a better assert function, preferably one like I made all that time ago that has support for the throwback levels! why: same reason as above, I make it way too often
I actually looked this up a while ago, and there's a specific reason for the assert that works the way it does. A lot of lua functions usually return a value if successful, or nil and then an error otherwise. It makes a neat syntax in a situation like this:
file = assert(io.open('somefile'))
Where assert would error out with the actual error from io.open. Giving a level to assert would erase every other value given from io.open as function params, e.g. the error message.



As for what I'd personally like, assignment operators (+=, -=, etc.) since I add numbers to themselves quite a bit, especially when working in games. ++ and -- are definitely redundant though, as it's only one less character to type: "var += 1" vs. "var++".

A part of the reason why they don't implement features like ^that is so Lua remains such a small and speedy language.

Edited by Kingdaro, 03 December 2013 - 04:02 AM.


#14 Wobbo

  • Members
  • 24 posts
  • LocationThe Netherlands

Posted 03 December 2013 - 05:09 AM

I would like a switch statement that isn't a function with a lookup table. There are ways around needing one, obviously, but it would be nice to have one if you have a lot of states, for example when checking for command line arguments.

I haven't really had the need to use one yet, but I think it would make checking for keys a lot easier. And if it used a lookup table underneath, also faster.

 theoriginalbit, on 02 December 2013 - 09:30 PM, said:

  • data type checking function foo(string bar) why: I hope this is fairly obvious
  • default parameter values function foo(string bar = "none") why: I hope this is fairly obvious too, its one of the only parts of Python that I like

1. Type checking is possible: http://lua-users.org...LuaTypeChecking
2. I would like to have this as well, and it can be achieved by creating a function that dynamically calls other functions. The wrapper function would have a closure with defaults and the order of the arguments, and it would call the function accordingly. Not really what you are looking for, but it is better than nothing.
Spoiler

Edited by Wobbo, 03 December 2013 - 05:12 AM.


#15 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 December 2013 - 06:07 AM

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

-snip-

 Wobbo, on 03 December 2013 - 05:09 AM, said:

-snip-
I would like to just point out to both of you that I know reasons behind their design choices, and I know that some of it is already implementable but the point of me writing this is to see what people WOULD change given the chance, even if it can already be done now.

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

The only real case where a ternary condition doesn't work is in this case:
var = condition and false or something_else
Where you wanted to set var to false if the condition was true. However, the easiest way to fix that is to reverse the condition and the "or"
var = not condition and something_else or false
If for some weird reason, the second and third values were false and nil, e.g. "var = condition and false or nil" (this statement would always evaluate to the last value, nil in this case), you're better off using an if statement, which is fine since most people don't really need to do this anyway.
in which case a ternary is just cleaner.

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

Personal preference, but I'm fine with checking the type of the value if necessary.
yeh there's just some times where it'd be handy, especially in this case:

 theoriginalbit, on 02 December 2013 - 10:05 PM, said:

well for one, having static typing does allow for function overloading, which is one of the major things that I do want in Lua, but can only be achieved through type checking.

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

I agree on this one; the whole "value = value or default_value" syntax is pretty verbose and doesn't work if you want false as a default.
Indeed, like I stated, one of the only things about Python that I actually like :P

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

__type and __len (implemented in 5.2) would be very nice to have, yes.
Indeed, I actually just discovered the other day that we actually do have __metatable, I didn't think we did, actually would have sworn that we didn't have it!

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

I actually looked this up a while ago, and there's a specific reason for the assert that works the way it does. A lot of lua functions usually return a value if successful, or nil and then an error otherwise. It makes a neat syntax in a situation like this:
file = assert(io.open('somefile'))
Where assert would error out with the actual error from io.open. Giving a level to assert would erase every other value given from io.open as function params, e.g. the error message.
Ahh of course, makes sense.

 Kingdaro, on 03 December 2013 - 04:02 AM, said:

As for what I'd personally like, assignment operators (+=, -=, etc.) since I add numbers to themselves quite a bit, especially when working in games. ++ and -- are definitely redundant though, as it's only one less character to type: "var += 1" vs. "var++".

A part of the reason why they don't implement features like ^that is so Lua remains such a small and speedy language.
Good options to have. implementing those operators wouldn't make the language much larger, and also wouldn't slow it down at all, for example += and -= are functionally no different than expanding, its just less verbose. As for ++ and -- they can definitely help make some statements less verbose.

 Wobbo, on 03 December 2013 - 05:09 AM, said:

1. Type checking is possible: http://lua-users.org...LuaTypeChecking
Of course its possible, I know its possible, but what I mean is this
local function foo(number bar)
  print(bar + 1)
end

foo(1) --#> 2
foo("bar") --#> error: expected number, got string
which obviously is implementable, like so
local function foo(bar)
  if type(bar) ~= "number" then
	error("expected number, got "..type(bar), 2)
  end
end
but the point of the former example is its far less verbose!

 Wobbo, on 03 December 2013 - 05:09 AM, said:

2. I would like to have this as well, and it can be achieved by creating a function that dynamically calls other functions. The wrapper function would have a closure with defaults and the order of the arguments, and it would call the function accordingly. Not really what you are looking for, but it is better than nothing.
-code snip-
yeh I've made a similar script in the past that dealt with type checking and defaults, so the signature was
parseArgs(args, argTypes, argDefaults)
and each table was an indexed table for it to work

Edited by theoriginalbit, 03 December 2013 - 06:07 AM.


#16 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 03 December 2013 - 06:53 AM

A lot of mine have already been mentioned, but I figure that I may as well state them.
  • Indentation requirements. More for my sake when debugging other people's code than anything else. I'm not a fan of the requirement when I'm actually writing a program myself due to the fact that sometimes I just want to test something quickly and not bother with indentation. But when I see some 600 line conglomeration without indentation I quickly exit the tab and return to browsing.
  • += and the like. The reasoning for this should be obvious.
  • Use curly braces for blocks - I'm not a fan of keywords for that purpose
  • Semi-colons to end statements. Simply for clarity's sake.
  • Function overloading. One of the reasons that I'm really liking Java.
  • Comments that begin with // not --. -- Looks ugly to me.
  • Compact the language somewhat: Do away with things such as "and" and replace them with symbols. I've always been a fan of compacting.
  • Declare things by default with a local scope, and specify global with global keyword or global symbol.

Edited by Bubba, 03 December 2013 - 06:55 AM.


#17 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 December 2013 - 07:10 AM

 Bubba, on 03 December 2013 - 06:53 AM, said:

Indentation requirements. More for my sake when debugging other people's code than anything else. I'm not a fan of the requirement when I'm actually writing a program myself due to the fact that sometimes I just want to test something quickly and not bother with indentation. But when I see some 600 line conglomeration without indentation I quickly exit the tab and return to browsing.
Yeh I'm very torn about this one, I like it for the reason that you do, but ti was one of the main reasons that I hate Python the enforced indentation, especially when it changes between IDEs and compilers! for example Uni wanted me to have indentation level of 2 so they could test it, but the IDE I was using had a compiler that was an un-configurable indent of 4.

 Bubba, on 03 December 2013 - 06:53 AM, said:

Function overloading. One of the reasons that I'm really liking Java.
Definitely one of my top ones that I mentioned (kinda, well it was implied), I especially like languages such as C++ which allow operator overloading, which Lua is kinda limited on, like __eq and all that only work when its comparing two of your objects, not your object and another disparate data type.

 Bubba, on 03 December 2013 - 06:53 AM, said:

Compact the language somewhat: Do away with things such as "and" and replace them with symbols. I've always been a fan of compacting.
Thoughts on what it could be? 'cause using something we have in other languages is not much more compact, like for example with Java && is not much more compact than and, also you'd want to avoid using ones like & just so you make sure none of your C and C-like programmers think that you mean bitwise and.

 Bubba, on 03 December 2013 - 06:53 AM, said:

Declare things by default with a local scope, and specify global with global keyword or global symbol.
Yes! One million times yes! Definitely being added to the list! Even if its to make it like Python where you have to declare that the variable is global in the scope.

Edited by theoriginalbit, 03 December 2013 - 07:15 AM.


#18 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 03 December 2013 - 08:54 AM

I'm not familiar enough with the language to really dis it; I'm still in the honeymoon stage, so to speak.

I wouldn't mind having to go without some of the redundant grammar already mentioned ("end"s, "then"s, "x=x+y"s, etc), though on the other hand, I don't mind having to use it (beats the days when I had to type "let"). But to add to the list of that sort of stuff, I suppose I'd like to remove the need to use the bit API to perform basic statements like "var1&var2".

Oh, and concatenation. Lua's the first language I've (knowingly) used which doesn't let me append values using just the "+" symbol. I assume there's a speed concern there (in that with .. it doesn't have to "figure out" whether I'm adding numerals or clumping strings together), but still.

The only other thing that comes to mind is the need to use brackets with print statements. Sure, you don't HAVE to do this as things stand, but... without them you can only print one value at a time. Whah...?!

#19 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 December 2013 - 09:28 AM

 Bomb Bloke, on 03 December 2013 - 08:54 AM, said:

I wouldn't mind having to go without some of the redundant grammar already mentioned ("end"s, "then"s, "x=x+y"s, etc)
At least its not like Pascal where you have to open a block with "begin" and close a block with "end" :P

 Bomb Bloke, on 03 December 2013 - 08:54 AM, said:

The only other thing that comes to mind is the need to use brackets with print statements. Sure, you don't HAVE to do this as things stand, but... without them you can only print one value at a time. Whah...?!
Its actually any function call. the only condition is that it must be only one argument and a string. but yes that is a bit of an odd thing to add to the language.

#20 Kingdaro

    The Doctor

  • Members
  • 1,636 posts
  • Location'MURICA

Posted 03 December 2013 - 09:29 AM

It's actually good for a language to have a separate addition and concatenation operator, so that the difference between 3 + 3 and 3 .. 3 is clear.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users