Functions Syntax - Quick Question

I’m working my way through some sample code and tutorials and I’ve noticed that different developers use different syntax for creating functions:

local function myFunctionName()

OR

local myFunctionName = function()

What’s the difference between the two (if any)? Is one more optimised/efficient than the other?

Thanks
[import]uid: 74503 topic_id: 12656 reply_id: 312656[/import]

I have the same question. [import]uid: 19626 topic_id: 12656 reply_id: 46346[/import]

First syntax creates a named function and second assign an unnamed function to a variable.

The first statement
[lua]local function myFunctionName()[/lua]
translates to
[lua]local myFunctionName; myFunctionName= function ()[/lua]

the second statement is
[lua]local myFunctionName = function ()[/lua]

the first statement just simplifies function definition. I believe both have same impact on performance. This second statement only makes a difference when the body of the function contains references to myFunctionName.

hope this clears the doubt. [import]uid: 71210 topic_id: 12656 reply_id: 46348[/import]

Plus, Corona Project Manager only “recognizes” the first option…

[lua]local function myFunctionName()[/lua]

…for things like autoindent, the function menu, etc. I’m working on making it recognize both ways, but for now if you don’t have a reason to use the second syntax, don’t.

And not just for the sake of using (or not) CPM – the first syntax is very typical of other programming languages and if you ever hire someone to work on your code the fewer “huh?” moments you give them, the better for both of you. :slight_smile:

Jay
[import]uid: 9440 topic_id: 12656 reply_id: 46363[/import]

:slight_smile:
are you the Corona Project Manager guy ?

I have a doubt about project manager. Got some issues when using it. where can I post my queries ? this doesn’t seems to be the right place to do it…

But I want to say it here that it is a nice product and I enjoy using it. :slight_smile: [import]uid: 71210 topic_id: 12656 reply_id: 46368[/import]

Yeah, I’m the CPM guy.

There’s a sub-forum here for asking questions and such:

http://developer.anscamobile.com/forums/corona-project-manager

If you want to say it sucks or something like that then use this instead:

http://coronaprojectmanager.zendesk.com

Or use that to submit an actual bug. :slight_smile: Either place is fine, really.

Jay
[import]uid: 9440 topic_id: 12656 reply_id: 46371[/import]

@Jay,
the CPM guy, I wanted to tell you how much CPM sucked…

It sucked up a lot of takers when it was first released and made development for many a breeze, and with every update, the features added are just amazing. Keep up the good job CPM Guy :wink:
?:slight_smile: [import]uid: 3826 topic_id: 12656 reply_id: 46403[/import]

Great. Thanks for the information guys.

I knew they both intrinsically achieved the same thing, I just wondered whether there were performance benefits to be had with one over the other. As there’s not, I’ll stick with the first option - seems cleaner and more readable.

Cheers [import]uid: 74503 topic_id: 12656 reply_id: 46405[/import]

Jayant, that’s not nice!

I read the first line, thought “Oh great, who is this?”

Glanced over to see your logo.

“What?!?”"

Read the rest, stopped hyperventilating.

Thanks. :slight_smile:

Jay
[import]uid: 9440 topic_id: 12656 reply_id: 46493[/import]

@Jay,
I am sorry for the joke at your expense, but could not resist the chance you left open when you responded with

"Yeah, I’m the CPM guy.

There’s a sub-forum here for asking questions and such:

http://developer.anscamobile.com/forums/corona-project-manager

If you want to say it sucks or something like that then use this instead:
"

It was just too tempting and I took the chance,

I am one of the few that have seen CPM from version 1 and have worked with feedback etc, I cannot explain in words and stress enough what a wonderful application CPM is for any developer that writes code in CoronaSDK. Apart from you being a wonderful guy and all, the CPM guy reference was something that was unexpected :wink:

BTW. Are you also the GameDevNation guy? Wonderful site it is. I hope it did not cause you much grief. Hope all good, you would not cut off my access to CPM and let me out from all the updates for that joke :wink:

cheers,

?:slight_smile:

[import]uid: 3826 topic_id: 12656 reply_id: 46595[/import]

Hey, I’m a big believer in “going for the joke” when you can (much to the chagrin of my wife) so if I open a door, I should expect someone to walk through it. :slight_smile:

And yes, I’m the GameDevNation.com guy, too. Because I just have too much free time not to have my fingers in every pie. :slight_smile:

Jay
[import]uid: 9440 topic_id: 12656 reply_id: 46603[/import]