View Single Post
09-24-16, 04:05 PM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
My current project at work is all in React, and I agree that JSX is great ... for generating JavaScript applications.

I also agree with SDPhantom that that generated Lua code is massively cringe-worthy. It's bloated, convoluted, overly verbose, visually unappealing (those underscores everywhere!) and just generally hard to read and follow.

Compare:

lua Code:
  1. local window = New("WindowWithTitle")
  2. -- ^ Let's pretend here that "New" is your constructor function,
  3. -- and returns a valid frame with all the appropriate parts.
  4. window:SetMovable(true)
  5. window:SetWidth(512)
  6. window:SetHeight(512)
  7. window:SetPoint("CENTER")
  8.  
  9. window.title:SetText("Broxxigar the red")
  10.  
  11. local text = window:CreateFontString()
  12. text:SetPoint("TOPLEFT")
  13. text:SetPoint("BOTTOMRIGHT", window, "RIGHT")
  14. text:SetJustifyH("LEFT")
  15. text:SetJustifyV("TOP")
  16.  
  17. text:SetText("Even for an orc, Broxigar the Red was obsessed with honor ...")
  18. -- ^ Truncated for the sake of brevity in this example.
  19.  
  20. local button1 = New("SmallButton")
  21. button1:SetParent(window)
  22. button1:SetPoint("BOTTOMLEFT")
  23. button1:SetText("OK")
  24. button1:SetScript("OnClick", function(self, mouseButton)
  25.     print("You pressed ok")
  26. end)
  27.  
  28. local button2 = New("SmallButton")
  29. button2:SetParent(window)
  30. button2:SetPoint("BOTTOMRIGHT")
  31. button2:SetText("Cancel")
  32. button2:SetScript("OnClick", function(self, mouseButton)
  33.     print("You pressed cancel")
  34. end)
  35.  
  36. window:RegisterEvent("UNIT_AURA")
  37. window:SetScript("OnEvent", function(self, event, ...)
  38.     if event == "UNIT_AURA" then
  39.         print("Someone gained aura!", ...)
  40.     end
  41. end)

Now there's no mystery variables, you're not creating a billion unnecessary tables and functions, and it's very clear to anyone who looks at it what's going on at any place in the code.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 09-25-16 at 09:51 PM. Reason: Forgot to parent the buttons in my example code.
  Reply With Quote