[POLL] Do you like "then,do,end" or "{ }"?

General discussion about LÖVE, Lua, game development, puns, and unicorns.

Do you like "then,do,end" or "{ }"?

"then,do,end" is just fine
36
82%
"{ }" would be better
8
18%
 
Total votes: 44

User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by Plu » Thu Aug 15, 2013 10:22 am

Even in PHP!

Code: Select all

$obj->doFunction()->doOtherFunction()->doEvenMoreFunctions()->etc()->etc()->andSoOn();

User avatar
Eamonn
Party member
Posts: 550
Joined: Sat May 04, 2013 1:29 pm
Location: Ireland

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by Eamonn » Thu Aug 15, 2013 11:55 am

Plu wrote:Even in PHP!

Code: Select all

$obj->doFunction()->doOtherFunction()->doEvenMoreFunctions()->etc()->etc()->andSoOn();
Awesome! I thought it was just Java! I'd never seen anyone do it in another language! How would you do it in Lua, though. I was trying for about 20 minutes and couldn't figure it out :O
"In those quiet moments, you come into my mind" - Liam Reilly

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by Robin » Thu Aug 15, 2013 12:03 pm

Oh, so they fixed that bug in PHP where a function call wasn't a proper expression?
Eamonn wrote:How would you do it in Lua, though. I was trying for about 20 minutes and couldn't figure it out :O
This is one way:

Code: Select all

local X = {}

function X:foo()
    -- do stuff
    return self
end

function X:bar()
    -- do other stuff
    return self
end

function X:hodor()
    -- hodor
    return self
end

X:foo():bar():hodor()
Help us help you: attach a .love.

User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by Plu » Thu Aug 15, 2013 12:44 pm

Oh, so they fixed that bug in PHP where a function call wasn't a proper expression?
Guess so. It's probably been fixed for a while, I've never seen it not work. But then, I've only really worked with PHP for about 4 years.

They even fixed the one where you can immediately access an array return value without storing it in a variable. AND they included closures.

So now you can do this:

Code: Select all

$this->func()['funcs']['func']()['func']()['func']()['key']['otherkey']()()();
I'm not sure if that would really make anyone happy, but it can technically be done :D

User avatar
DaedalusYoung
Party member
Posts: 402
Joined: Sun Jul 14, 2013 8:04 pm

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by DaedalusYoung » Thu Aug 15, 2013 1:28 pm

That looks awful, tbh. Why would I want to do that? Can't you just do each call separately?

User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by Plu » Thu Aug 15, 2013 1:40 pm

Yeah this example is a huge mess, just for the heck of it :P

Normally you'd more likely do something like this:

Code: Select all

$firstName = $obj->getNames()[0];
Which is kinda neat and cleaner than

Code: Select all

$names = $obj->getNames();
$firstName = $names[0];

User avatar
DaedalusYoung
Party member
Posts: 402
Joined: Sun Jul 14, 2013 8:04 pm

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by DaedalusYoung » Thu Aug 15, 2013 4:48 pm

Well yes, that would make more sense. Although in that example, I would just code the getNames() function to include an argument to get the desired output, so:

Code: Select all

$firstName = getNames('first')

User avatar
Plu
Inner party member
Posts: 722
Joined: Fri Mar 15, 2013 9:36 pm

Re: [POLL] Do you like "then,do,end" or "{ }"?

Post by Plu » Thu Aug 15, 2013 4:53 pm

Yeah, still just an example. In this case it isn't really neccesary, but especially when dealing with PHP internal functions it can be useful to make the direct modification.

Plus, it breaks your concentration when something that seems to make sense doens't work, at least for me.

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests