Quantcast WoWInterface - View Single Post - Posting some code for ideas on
View Single Post
01-17-13, 10:01 PM   #5
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,616
For future reference, please do not quote an entire 100-line post, especially when it immediately preceds yours.

Originally Posted by Sieben11 View Post
The button is part of the tooltip. ... So DIALOG keeps the button topmost without stepping over TOOLTIP. Then will allow TOOLTIP to show over it.
Tooltips are the little info boxes that pop up when you move the mouse cursor over something; for example, when you mouse over a player in the game world, a tooltip appears in the bottom right corner of your screen showing that player's name, guild, level, class, and PvP state.

A frame, button, or other object that is always visible on the screen to be collapsed/expanded is not a tooltip.

Use frame levels, not stratas, to control the layering of related frames.

Originally Posted by Sieben11 View Post
My syntax formatting has always been however was easiest for me. ... What does it matter? The code runs the same.
It matters because good formatting makes your code infinitely easier for humans to read.

For example, you indented a few lines apparently at random. However, when the whole file is indented consistently, the structure of functions, blocks, and other scoping levels is immediately obvious even before you read anything.

Similarly, in some places you do:

if X then Y
else Z end
while other places you do:

if X then
Again, it's a consistency issue. If the code is formatted consistently throughout, it's just easier to read quickly and see how the part you are looking at fits into the overall structure.

Spacing just improves readability. Compare "alpha,beta,gamma,delta" vs. "alpha, beta, gamma, delta". There's a reason we use spaces between words and sentences in English (and most other languages). It's easier to read. Your source code is not a SMS message or a macro with a limit on the number of characters it can contain, so there's just no reason to squish everything together and lose readability.

If you're a programmer by trade, or even have previous programming experience, I'd be very surprised if you did not think that consistent variable naming conventions were important. If you write some code, don't look at it for 6 months, and then need to go back and fix something because a bug cropped up, it's just way easier if you have a convention, so you can figure out what you're looking at without having to read the whole file. For example, if you see "foobar" you could know right away that it's a variable, while "Foobar" is a function, and "FOOBAR" is a constant (a variable whose value is static and never changed).

Even if you don't consider bad/inconsistent formatting a problem for your personal workflow (though you really should) if you want other people to be able to read your code and understand it as quickly and easily as possible, you should format it properly. Lack of indentation, lack of consistency, unnecessary "squishing", random naming, and other formatting issues make a huge difference in the readability of your code by people who did not write it.

Your code wasn't that long, but had you posted 1000 lines of code formatted the same way, frankly I would not have bothered to read it or give you any feedback, because I'd have to spend an hour fixing the formatting to make it actually readable first, and that's just way more time and effort than I'm willing to spend providing free advice on a WoW addon forum.

Originally Posted by Sieben11 View Post
State is reflective of frame/button. Setting btn.state to enable self for state. Seems the same as just calling state unless there was a reason for this? State was meant to just control both.
Yes, you should just use self.state (where self is some object) instead of state, always. This makes the state accessible from outside the scope of the "create container" function.

Originally Posted by Sieben11 View Post
Button used clamp for it to always remain on screen with the frame it controlled.
Clamp the frame, attach the button to the frame, and use clamp insets on the frame. If you clamp both, but don't use clamp insets, then you can drag the frame to the edge of the screen and the button will end up overlapping it.

Author/maintainer of Grid, PhanxChat, oUF_Phanx, and many more.
Troubleshoot an addonTurn any code into an addonMore addon resources
Need help with your code? Post all of your actual code! Attach or paste your files.
Please don’t PM me about addon bugs or code questions. Post a comment or forum thread instead!

Last edited by Phanx : 01-17-13 at 10:06 PM.
  Reply With Quote