Jump to content




Lua: What would you change?


  • You cannot reply to this topic
83 replies to this topic

#21 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 03 December 2013 - 10:49 AM

False as a default works just fine. Imagine _var is nil:

var = _var or false

Just nitpicking. Lua is fine, and it seems like a lot of these suggestions just want to make it more like Java. The two serve totally different roles. I agree that some of the syntactic sugar would be nice (+=, I'm looking at you!), but overall, it's pretty good. I'd like to see more ideas that actually fit the rest of the language instead of stuff that just fanboys about turning it into java. :P

Also, symmetryc's suggestion about metatables on things that aren't tables is possible with __type, since you'd just claim the type to be something else.

#22 M4sh3dP0t4t03

  • Members
  • 255 posts
  • LocationGermany

Posted 03 December 2013 - 11:01 AM

Most of the stuff I would changed has already been said, but I would also like 0-indexed tables.

Edited by M4sh3dP0t4t03, 03 December 2013 - 11:01 AM.


#23 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 03 December 2013 - 11:45 AM

View PostLyqyd, on 03 December 2013 - 10:49 AM, said:

...instead of stuff that just fanboys about turning it into java. :P

Java sux. I want to turn it into C#.

*runs for cover*

#24 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 03 December 2013 - 12:25 PM

View Posttheoriginalbit, on 03 December 2013 - 07:10 AM, said:

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.

I have no more love for Python than you do, and yeah I doubt I would like enforced indentation if I had it. However, it would be nice if people would indent their code...

and use code tags!

Quote

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.
I guess I don't really mean compact it. I actually would just like Lua to follow some of the more typical standards such as using '&&' rather than 'and'. I get used to doing it one way and the switch is annoying.

View PostLyqyd, on 03 December 2013 - 10:49 AM, said:

Just nitpicking. Lua is fine, and it seems like a lot of these suggestions just want to make it more like Java. The two serve totally different roles. I agree that some of the syntactic sugar would be nice (+=, I'm looking at you!), but overall, it's pretty good. I'd like to see more ideas that actually fit the rest of the language instead of stuff that just fanboys about turning it into java. :P

Java is a nice language so meh :P

But suggesting ideas that "fit the language" would mean little or no changes at all. Sometimes you have to break away from the "it doesn't fit" mentality :)

#25 Symmetryc

  • Members
  • 434 posts

Posted 03 December 2013 - 02:38 PM

Um, how will number-- work if -- is for comments?

View Posttheoriginalbit, on 03 December 2013 - 09:28 AM, said:

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.
It actually also works with tables.

Edited by Symmetryc, 03 December 2013 - 02:38 PM.


#26 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 03 December 2013 - 02:47 PM

View PostSymmetryc, on 03 December 2013 - 02:38 PM, said:

Um, how will number-- work if -- is for comments?
Really, nobody spoke about that syntactical sugar :P
They have talked about +=, -=, /= etc.

How awesome Java is, keep it on its own language. I see the problem where we cant progrram with Java in CC, but thats for obvious reasons.
Since we are just talking about programming languages:
Keep Lua Lua, and Java Java.

Really, its like comparing a brick with a banana. Pointless :P

#27 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 03 December 2013 - 03:12 PM

Maybe a goto function to jump to declared position like in Batch.

Batch example:
firstplace:
echo first
goto secondplace

secondplace:
echo second

goto firstplace


#28 Engineer

  • Members
  • 1,378 posts
  • LocationThe Netherlands

Posted 03 December 2013 - 03:20 PM

View PostFreack100, on 03 December 2013 - 03:12 PM, said:

Maybe a goto function to jump to declared position like in Batch.

Batch example:
firstplace:
echo first
goto secondplace

secondplace:
echo second

goto firstplace
You can achieve that using functions, though you have a stack overflow then

#29 Symmetryc

  • Members
  • 434 posts

Posted 03 December 2013 - 04:06 PM

View PostEngineer, on 03 December 2013 - 02:47 PM, said:

View PostSymmetryc, on 03 December 2013 - 02:38 PM, said:

Um, how will number-- work if -- is for comments?
Really, nobody spoke about that syntactical sugar :P
Well yeah, but BIT and Bubba did, so I just thought I'd mention it.

#30 Bomb Bloke

    Hobbyist Coder

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

Posted 03 December 2013 - 04:38 PM

View PostFreack100, on 03 December 2013 - 03:12 PM, said:

Maybe a goto function to jump to declared position like in Batch.
I gather it's in, as of 5.2.

#31 Bubba

    Use Code Tags!

  • Moderators
  • 1,142 posts
  • LocationRHIT

Posted 03 December 2013 - 04:59 PM

View PostFreack100, on 03 December 2013 - 03:12 PM, said:

Maybe a goto function to jump to declared position like in Batch.

Batch example:
firstplace:
echo first
goto secondplace

secondplace:
echo second

goto firstplace

I refer you to this thread. Goto is a valid tool in some situations - however, I don't believe that it would be helpful to new programmers, which seems to be what Lua caters to (or at least what ComputerCraft caters to). In many cases it would be hurtful - goto leaves a lot of uncertainty in some situations and complicates things more than necessary.

I disagree with the decision to add goto, but then again I am not on the PUC-Rio team so my opinion has little weight.

View PostSymmetryc, on 03 December 2013 - 02:38 PM, said:

Um, how will number-- work if -- is for comments?


As I suggested in my earlier post, comments in Lua should be changed to the form of // rather than --. // Looks far better in my opinion and would allow for syntactic sugar such as n--.

Edited by Bubba, 03 December 2013 - 05:30 PM.


#32 PixelToast

  • Signature Abuser
  • 2,265 posts
  • Location3232235883

Posted 03 December 2013 - 05:13 PM

it seems many of this is in a language ive been making that compiles into lua

here is a breif explanation of it
everything global is localized at the top of the program unless marked as global
parentheses are optional and are only required if you want to call multiple functions in one line
function statements can support arg types including a special one for "..."

-- function argstest args:tArgs {
--  walrus
-- }
-- function test number:num {
--  for a 1 num {
--  print "Potato $a$!"
--  }
-- }
-- test 10

local argtest,test
function argstest(...)
  local tArgs={...}
  walrus()
end
function test(num)
  assert(type(num)=="number","bad argument number:num expected, got "..type(num))
  for a=1,num do
	print("Potato "..a.."!")
  end
end
test(10)

it is intended to be a language easier to code in and eliminate common mistakes new people do

#33 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 03 December 2013 - 06:55 PM

I don't think anyone is proposing we swap Lua for Java in ComputerCraft. But Java has some nice features that are missing from Lua and since most people here would be familiar with Java it's being used as the example.

#34 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 03 December 2013 - 07:08 PM

View PostSymmetryc, on 03 December 2013 - 02:38 PM, said:

View Posttheoriginalbit, on 03 December 2013 - 09:28 AM, said:

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.
It actually also works with tables.
only table constructors, you can't do this
local t = {}
print t
it has to be
print {}
which is kinda pointless

View PostLyqyd, on 03 December 2013 - 10:49 AM, said:

Just nitpicking. Lua is fine, and it seems like a lot of these suggestions just want to make it more like Java.
I wouldn't exactly say they are. Pretty much all the suggestions are generic to most high level programming language, except for the one that distantcam stated that was C#

Edited by theoriginalbit, 03 December 2013 - 07:10 PM.


#35 oeed

    Oversimplifier

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

Posted 03 December 2013 - 07:40 PM

View Postdistantcam, on 03 December 2013 - 06:55 PM, said:

I don't think anyone is proposing we swap Lua for Java in ComputerCraft. But Java has some nice features that are missing from Lua and since most people here would be familiar with Java it's being used as the example.

I find Java such a pain to work with, especially Java tables/arrays/dictionaries/what-ever-you-want-to-call-them. I started making an Inception inspired mod but the arrays were just such a pain to work with.

#36 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 03 December 2013 - 07:47 PM

View Posttheoriginalbit, on 03 December 2013 - 07:08 PM, said:

I wouldn't exactly say they are. Pretty much all the suggestions are generic to most high level programming language, except for the one that distantcam stated that was C#

Lambdas are coming in Java 8. http://docs.oracle.c...xpressions.html

View Postoeed, on 03 December 2013 - 07:40 PM, said:

I find Java such a pain to work with, especially Java tables/arrays/dictionaries/what-ever-you-want-to-call-them. I started making an Inception inspired mod but the arrays were just such a pain to work with.

I do like the way tables work in Lua.

#37 Symmetryc

  • Members
  • 434 posts

Posted 03 December 2013 - 08:21 PM

View Posttheoriginalbit, on 03 December 2013 - 07:08 PM, said:

View PostSymmetryc, on 03 December 2013 - 02:38 PM, said:

View Posttheoriginalbit, on 03 December 2013 - 09:28 AM, said:

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.
It actually also works with tables.
only table constructors, you can't do this
local t = {}
print t
it has to be
print {}
which is kinda pointless
Same with strings though:
local s = "567"
print s
Wouldn't work

Edited by Symmetryc, 03 December 2013 - 08:21 PM.


#38 GravityScore

  • Members
  • 796 posts
  • LocationLand of Meh

Posted 04 December 2013 - 03:10 AM

Default arguments for functions. This is one of the few things I like about Python, and hate about Javascript.

I sort of like the if ... then and for/while ... do, so I wouldn't personally swap them for curly braces, although I still love curly braces.

I dislike having two different operators for concatenation and addition - it'd be better if it was just +.

I really hate the -- for commenting. // or even # is better (// is superior IMO).

+= and -= are something I can't stand Lua not having. I use them in code and then get an error, and it just annoys me.

I dislike how some languages like to be different (from C/Java) with their for loops. I like the 3 separate statements in a for loop. It allows the conditional of a for loop to be completely unrelated to the initialisation and the increment, which is so useful when reading from a file, etc. This is something I dislike about python, although it's worse in Lua as Lua's for loop syntax is more confusing than Python's.

I dislike how when you try to print out something in Lua, it just shows the type and memory address. How I wish the tostring function for tables actually returned some useful data.

I loooovvveeee how tables work in Lua. I wish every higher level language would follow Lua's implementation of tables.

I hate enforced indenting. It is such a damned pain in Python, especially if I open the file with a different IDE/editor, and it starts using spaces for tabs instead of actual tabs. Python just complains to me and it takes me a while to figure out why it's complaining because visually they look the same.

#39 distantcam

  • Members
  • 139 posts
  • LocationChunk 0

Posted 04 December 2013 - 03:19 AM

To be clear, my complaint about if...then was the then part. I'd be happy with "if (condition) ... end" where the brackets denote the end of the condition instead of the then.

#40 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 04 December 2013 - 03:35 AM

View Postdistantcam, on 04 December 2013 - 03:19 AM, said:

To be clear, my complaint about if...then was the then part. I'd be happy with "if (condition) ... end" where the brackets denote the end of the condition instead of the then.
Again, try Pascal :P
if condition then
begin
  statements;
end;

Although the above example could be
if condition then
  statements;

Its just if your block will be more than 1 statement you need to add the begin...end

Edited by theoriginalbit, 04 December 2013 - 03:36 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users