Damn, your very tallented at writing ugly code.
One of the better examples ive seen posted on a board, tough ive seen worse in production code (dont ask me why). But yeah this appers to happen to 50% of all coders. Im assuming you were thinking of doing the following:
string $ft_ListSel[] = `ls -sl`;
for ($each in $ft_ListSel)
{
addAttr -ln "power" -at "enum" -k 1 -en "on:off:" $each;
setAttr -e -keyable true ($each + ".power");
}
Anyway, just so you know dont comment suff like this (yes im aware you might have commented this for our benefit, but still dont make sense):
int $ft_Laps = 0; //counter that starts at zero
yeah it reads in the code. Its true that your supposed to comment code well. However what people often dont understand is what that means. Theres no point in commenting "counter that starts at zero" allmost ever, but certainly not here. I mean:
int $ft_Laps = 0;
reads quite clearly variable that starts at 0. I mean if your not sure people dont get it then write:
int $counter = 0;
this pretty much reads a counter that starts at 0. In fact its far more precicely saying this than the comment. So the first few rules of commenting code is:
- make your code self evident
- dont comment self eviden stuff
Certainly its hard to know whats self evident and what is not. But to illustrate a point, Ive seen a piece of code that looked more or less as follows:
// make a variable named $a
// variable $a holds the number of iterations
int $a = 1;
// now lets add the pre calculated value in $b to $a
$a = $a + ($c/2 - 1)
...
and so on for about 2000 lines*. This is where I went home for the day. I mean seriously theres 4 times as much comment as code. The comments are obviously fluff i dont really need to tell me that ones making variables with the name of $a. But worse i have no frigging idea wether or not the last line is correct or not.
Which is right the comment or the code?
Point being that comment needs to be maintained and if you comment a lot i will not be, or youll just do the same work many times over. So if you want to increase readability fo code with comment comment something meningful. such as blocks of code:
So taking my correction it could be commented like this:
// add keyable enum attribute power to all objects in selection
string $ft_ListSel[] = `ls -sl`;
for ($each in $ft_ListSel)
{
addAttr -ln "power" -at "enum" -k 1 -en "on:off:" $each;
setAttr -e -keyable true ($each + ".power");
}
if you really need it. Or perhaps comment for loop block only. Tough more prefeerable would be for you to define a procedure named addKeyableEnumAttrPowerToSelection() instead if you must be verbose.
See code IS COMMENT
* said programmer was moved off to management, as he had a second degree in business management. Not sure i ever trusted his competency ever again.