View Single Post
09-30-16, 05:31 PM   #1
Sweetsour
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Dec 2014
Posts: 130
Questions about efficient coding

Ever since I've started coding in WoW, and Lua consequently, I've learned a lot of tips on how to use more effective coding practices. Though, I still have a couple curiosities I'm hoping to get cleared up.

1. When I'm sharing variables across files, is it better to put them into global namespace, or within the addon?

Example:
Lua Code:
  1. -- Method #1
  2. local addon, private = ...
  3. private.myVariable = 'contents'
  4.  
  5. -- Method #2
  6. _G["myVariable"] = 'contents'

2. Is it ever ideal to use select()? More specifically, if I need to get a variable that's far down a list of arguments, would I use select(), or the "_,_,_,var" method?

Example:
Lua Code:
  1. local _,_,_,_,_,_,_,_,_,var = MyFunction()
  2.  
  3. -- or --
  4.  
  5. local var = select(10, MyFunction())
  Reply With Quote