Thread Tools Display Modes
05/27/14, 07:52 AM   #1
hulksmash
 
hulksmash's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 30
minified LUA

Is there any issues with only providing the minified version of your LUA source? For example, in my SWAPS addon I am using the minified source. I am interested in knowing if it will conflict with other addons due to variables name changes or if there are any other potential problems.
  Reply With Quote
05/27/14, 08:36 AM   #2
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
Is there any reason you need to use minified code?

Technically, if you avoid using globals, your minified code should be fine. But you're preventing anyone else from learning from what you do, or helping out.
  Reply With Quote
05/27/14, 08:51 AM   #3
gamegenius86
 
gamegenius86's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 27
I would imagine that it could create a bunch of issues. If there is no reason you need to use minified code, then don't. The only pro that i can think of would be a smaller file size which means it might load 1ms faster (if that). However the list of cons (or potential cons) is much larger.

My suggestion: Don't minify.
  Reply With Quote
05/27/14, 08:56 AM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by hulksmash View Post
Is there any issues with only providing the minified version of your LUA source? For example, in my SWAPS addon I am using the minified source. I am interested in knowing if it will conflict with other addons due to variables name changes or if there are any other potential problems.
If you don't use global variables, there shouldn't be any problem.
The only issue I can think of will be with bug reports as it will be very hard to get any useful information from UI error dialog.

A few comments:
It is good practice to unregister events you do not need. As you are trying to make your code very small, you can register for EVENT_ADD_ON_LOADED as follows:
Lua Code:
  1. local ev,a=EVENT_MANAGER,"swaps"
  2. ev:(a,EVENT_ADD_ON_LOADED,function(c,n)if n==a then l()ev:UnregisterForEvent(a,c)end)
("l" is your OnLoad function.)

Also to keep minimal length of code, you do not need to define names for your controls:
Lua Code:
  1. a.renameModal=swaps.Chain(b:CreateTopLevelWindow()):SetDimensions(450,200):SetAnchor(CENTER,GuiRoot,CENTER,0,0):SetHidden(true).__END
  2.  
  3. a.renameModal.bg=swaps.Chain(b:CreateControl(nil,a.renameModal,CT_BACKDROP)):SetEdgeColor(.3,.3,.3,.5):SetCenterColor(.1,.1,.1,.99):SetAnchor(TOPLEFT,a.renameModal,TOPLEFT,0,0):SetDimensions(450,200).__END
Note: If you create control from virtual, it sometimes needs to have defined name because of child controls that use "$(parent)" or "$(grandparent)" in their name.

You are using:
Lua Code:
  1. zo_callLater(function() d("Loaded -- Swap Skills -- AddOn by @HulkSmashWarrior") end, 320)
You can't be sure that this message will by displayed for everyone as loading times are different for each player. It is better to print it from function registered to EVENT_PLAYER_ACTIVATED. Or do not print it at all, as I do not like chat spam .
  Reply With Quote
05/27/14, 09:06 AM   #5
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
But for all of this, why minify anything?

People aren't downloading the lua on the fly, the length of your variable names aren't going to affect load by any significant amount. None of the -benefits- of minification apply here, unless you consider obfuscation a benefit, and coming from a point of addon coding, where everyone should be able to read the code, that's not a benefit.
  Reply With Quote
05/27/14, 09:11 AM   #6
zgrssd
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 280
Originally Posted by gamegenius86 View Post
I would imagine that it could create a bunch of issues. If there is no reason you need to use minified code, then don't. The only pro that i can think of would be a smaller file size which means it might load 1ms faster (if that). However the list of cons (or potential cons) is much larger.

My suggestion: Don't minify.
Agrred. I would avoid it. You are directly transfering the Sourcecode to the other computer, so lua+xml+txt is already a very effective format (compared to .dll or .exe files). Usually .zip compressed too, wich is incredibly effective for anything text based. You will literally not get any measureable benefit regarding Transmission or Loading Times.
My addon Unified Chat Tabs v 1.0 measures 35,4 KiB decompressed (including embedded libraries) and 12 KiB .zip compressed.
Notice that I wrote KiB. Of wich 1024 make just a measily MiB. Of wich 1024 make just a measily GiB. Are there even still HDD below 500 GiB on the market?

In turn:
You will have a hell to debug this.
Since you propably also do not use comments, you will have a hell to udnerstand your own code after 6 months (and those are real life figures I ran into when I forgot to comment).
Nobody can learn from your code
Nobody can help you debug your code if you are stumped.

Good ability to debug and follow your own code is a at least 1,048,576 times more important then sqeezing out the last byte of filesize on something that will propably not even fill a 4 KiB cluster in the first place.
  Reply With Quote
05/27/14, 10:30 AM   #7
hulksmash
 
hulksmash's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 30
Originally Posted by Wobin View Post
Is there any reason you need to use minified code?
Yeah I just wanted to keep my source code to myself really. I dont mind others reading the code and providing tips, helps, hints etc but I dont want people to take the code and bastardize it up making it look like crap and distribute. The only reason I used the minified version was to make it difficult for others to read and yes I have comments everywhere actually. It sounds like without using globals I might be ok. However it might not be worth the trouble.

Im new to LUA and addons so I am sure there is a better way to optimize my code. I didnt minify to optimize space, load, or variable length. Just to protect the source somewhat.
  Reply With Quote
05/27/14, 11:07 AM   #8
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
Originally Posted by hulksmash View Post
Yeah I just wanted to keep my source code to myself really. I dont mind others reading the code and providing tips, helps, hints etc but I dont want people to take the code and bastardize it up making it look like crap and distribute. The only reason I used the minified version was to make it difficult for others to read and yes I have comments everywhere actually. It sounds like without using globals I might be ok. However it might not be worth the trouble.

Im new to LUA and addons so I am sure there is a better way to optimize my code. I didnt minify to optimize space, load, or variable length. Just to protect the source somewhat.
While I dont have anything against you only using minified code -
if you do have even a single randomized global in there I (and probably many others)
am/are going to curse you ... because it 's like playing russian roulette with other addons.
You never know whom or what you hit. till you hit it. So please dont ever do that.

Cheers

Last edited by thelegendaryof : 05/27/14 at 11:14 AM.
  Reply With Quote
05/27/14, 11:28 AM   #9
hulksmash
 
hulksmash's Avatar
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 30
Originally Posted by thelegendaryof View Post
While I dont have anything against you only using minified code -
if you do have even a single randomized global in there I (and probably many others)
am/are going to curse you ... because it 's like playing russian roulette with other addons.
You never know whom or what you hit. till you hit it. So please dont ever do that.

Cheers

Yeah I think I am going to just post the source code and deal with it. I have a lot of really cool ideas and features I want to add to this. I am depending on the forums a lot for support when I am stuck. Its really difficult learning LUA and the ESO api at the same time. Im kind of shocked I made this in a week so far alone. I learn best from examples. The wiki is useful but I have a hard time understanding how to apply a lot of things.

The next version will be w/o minify
  Reply With Quote
05/27/14, 11:45 AM   #10
thelegendaryof
 
thelegendaryof's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 161
Originally Posted by hulksmash View Post
Yeah I think I am going to just post the source code and deal with it. I have a lot of really cool ideas and features I want to add to this. I am depending on the forums a lot for support when I am stuck. Its really difficult learning LUA and the ESO api at the same time. Im kind of shocked I made this in a week so far alone. I learn best from examples. The wiki is useful but I have a hard time understanding how to apply a lot of things.

The next version will be w/o minify
No need to if you dont feel like it! However if you do you're welcome.
Wouldn't refuse to help anyway.

Cheers!
  Reply With Quote
05/27/14, 11:48 AM   #11
ingeniousclown
AddOn Author - Click to view addons
Join Date: Feb 2014
Posts: 122
Originally Posted by hulksmash View Post
Yeah I think I am going to just post the source code and deal with it. I have a lot of really cool ideas and features I want to add to this. I am depending on the forums a lot for support when I am stuck. Its really difficult learning LUA and the ESO api at the same time. Im kind of shocked I made this in a week so far alone. I learn best from examples. The wiki is useful but I have a hard time understanding how to apply a lot of things.

The next version will be w/o minify
Glad we could convince you!

Yeah, it is frustrating when copying happens (there's a thread about it somewhere on these forums), but as long as you spot a copy or someone else shows it to you, this site's wonderful moderators will give you all the assistance you need.
  Reply With Quote
05/27/14, 12:02 PM   #12
lyravega
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 93
At least you can work with UI mate, I am a noob when it comes to UI stuff... if this was Torchlight II however, I'd be able to make UI-origami if the words fit to each other right!

Back to the topic, if you are (were) mainly using minify for performance gains, I don't think this game/API would benefit from it that much. General rules of LUA apply though; like locals being accessed faster than globals (even a simple local next = next improves just a tad), it is best to avoid nested if-checks if possible, etc... general programming stuff if you think about it, not just LUA.

As ingeniousclown said, if anyone tries to copy your stuff over here, moderators seem to be very responsive and helpful. I'm glad that you decided to ignore minify for the future, I'm very curious to see the code as a "whole", like you, I best learn with examples and I think I will learn quite a bit from your work
  Reply With Quote
05/27/14, 02:14 PM   #13
Wobin
 
Wobin's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 78
The top ESO lua coding addon tip I can offer is

Download and learn how to use Zgoo
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » minified LUA


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off