Page 4 of 4
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 10:22 am
by Plu
Even in PHP!
Code: Select all
$obj->doFunction()->doOtherFunction()->doEvenMoreFunctions()->etc()->etc()->andSoOn();
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 11:55 am
by Eamonn
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
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 12:03 pm
by Robin
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()
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 12:44 pm
by Plu
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
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 1:28 pm
by DaedalusYoung
That looks awful, tbh. Why would I want to do that? Can't you just do each call separately?
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 1:40 pm
by Plu
Yeah this example is a huge mess, just for the heck of it
Normally you'd more likely do something like this:
Which is kinda neat and cleaner than
Code: Select all
$names = $obj->getNames();
$firstName = $names[0];
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 4:48 pm
by DaedalusYoung
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:
Re: [POLL] Do you like "then,do,end" or "{ }"?
Posted: Thu Aug 15, 2013 4:53 pm
by Plu
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.