View Single Post
09-08-08, 03:13 PM   #31
Mikord
A Theradrim Guardian
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 61
Originally Posted by kerrang View Post
I've noticed many authors use this approach now - what, exactly is bad about using global functions - or assigning functions into your Frame - or using entirely local functions?
One simple reason is to avoid global namespace pollution and drastically reduce chances of collisions.

You decide to create an event handler called OW_OnEvent. Another mod author comes along and decides to create a mod that has the initials OW and predictably create his event handler to be called....you guessed it, OW_OnEvent. Oops whoever loaded first is now hosed because both XML files try to call OW_OnEvent which just got overwritten.

On the other hand, had they both been namespaced under their mod's name, there would be no problem.

There are also performance reasons too, but that would required an explanation of how lua works internally, and that is better left to a book.
  Reply With Quote