score_under
|
|
Posted on: February 10, 2009, 01:30:41 pm |
|
|
Joined: Aug 2008
Posts: 308
|
Coollog is a repeat offender of this one. Look at one of his scripts, read the code on each line, then tell me if you are at all enlightened by the comments:
var _d,_i,_j,_c;//Dims the temporary variables for the script.
_d=0;//Sets _d to 0. for(_i=0;_i<=string_length(argument0);_i+=1)//Loops for starting with _i=0, while _i is still smaller than or equal to the length of the first inputed string, add one to _i and execute the bracketed code. _d[_i,0]=_i;//Sets the cell at row _i, column 0 to _i. for(_j=0;_j<=string_length(argument1);_j+=1)//Loops for starting with _j=0, while _j is still smaller than or equal to the length of the second inputed string, add one to _j and execute the bracketed code. _d[0,_j]=_j;//Sets the cell at row 0, column _j to _j.
for(_i=1;_i<=string_length(argument0);_i+=1)//Loops for starting with _i=1, while _i is still smaller than or equal to the length of the first inputed string, add one to _i and execute the bracketed code. for(_j=1;_j<=string_length(argument1);_j+=1)//Loops for starting with _j=1, while _j is still smaller than or equal to the length of the second inputed string, add one to _j and execute the bracketed code. { if string_char_at(argument0,_i) = string_char_at(argument1,_j)//If the character in the first inputed string at position _i is equal to the same position in the second inputed string... _c=0;//Sets _c to 0. else//Otherwise... _c=1;//Sets _c to 1. _d[_i,_j]=min(_d[_i-1,_j]+1,_d[_i,_j-1]+1,_d[_i-1,_j-1]+_c);//Sets the cell at row _i, column _j to the minimum of the above value plus one, the left value plus one, or the top-left value plus _c. }
return _d[string_length(argument0),string_length(argument1)];//Returns the difference between the first inputed string and the second inputed string. The whole point of comments is to help people decipher the code, not to say what each individual command does, but its role in the big picture of the script.
|
|
|
Logged
|
|
|
|
|
|
|
|
notachair
|
|
Reply #5 Posted on: February 12, 2009, 12:51:19 am |
|
|
Definitely not a chair
Joined: Feb 2008
Posts: 299
|
yeesh, those kinds of comments are why people are supposed to use descriptive names. real comments describe blocks of code. they only time you should comment every single line is assembly.
Oh, so that's how you keep your brain from exploding when looking at ASM!
|
|
|
Logged
|
|
|
|
score_under
|
|
Reply #6 Posted on: February 12, 2009, 03:09:25 pm |
|
|
Joined: Aug 2008
Posts: 308
|
yeesh, those kinds of comments are why people are supposed to use descriptive names. real comments describe blocks of code. they only time you should comment every single line is assembly.
No, Assembly has such subtle commands that it's best to comment every tenth line, or less. It can get pretty useless, especially in badly optimized code, for example: xor eax,eax dec eax movzx eax,al xchg al,ah dec eax push ax call SomeFunction ; SomeFunction(-256) A2h, I see you do not share my passion for debugging.
|
|
|
Logged
|
|
|
|
Josh @ Dreamland
|
|
Reply #7 Posted on: February 12, 2009, 06:02:22 pm |
|
|
Prince of all Goldfish
Location: Pittsburgh, PA, USA Joined: Feb 2008
Posts: 2950
|
'Tis a rarity, methinks.
|
|
|
Logged
|
"That is the single most cryptic piece of code I have ever seen." -Master PobbleWobble "I disapprove of what you say, but I will defend to the death your right to say it." -Evelyn Beatrice Hall, Friends of Voltaire
|
|
|
|
Post made February 13, 2009, 03:37:28 am was deleted at the author's request.
|
score_under
|
|
Reply #10 Posted on: February 13, 2009, 01:47:22 pm |
|
|
Joined: Aug 2008
Posts: 308
|
I wouldn't tell someone to comment every line of assembly with something like "move this number into this register" or "call this function," that'd be stupid I agree. It's more to keep a running commentary next to everything you're doing, something like:
; Function to add the first two parameters add: push ebp ; create stack frame mov ebp, esp mov eax, [ebp + 8] ; get the first argument mov ecx, [ebp + 12] ; second argument add eax, ecx ; sum in eax to return pop ebp ; restore stack frame ret Brains are not CPUs. They need help, no matter how good at debugging you think you are.
When I'm reverse-engineering stuff, I usually comment like this: (Using same code) add: push ebp ; add(arg1,arg2) mov ebp, esp ; { mov eax, [ebp + 8] ; mov ecx, [ebp + 12] ; return arg1+arg2; add eax, ecx ; pop ebp ; } ret The comments aren't well placed (the "ret" is on the last line, yet I've put the "return" in the middle of the function, in the middle of the 3 calculation instructions - it'll still execute code similar to that comment). I only try to make sure that the code is readable for me at 04:00 AM. Also, Josh, for support of large numbers in your modulus function, this might work (instead of a-=(int)a;)... double temp; asm("FLD %%st\n\ FISTPQ %2\n\ FILDQ %2\n\ FSUBRP %%st,%%st(1)\n" :"=&t"(x) :"f"(x),"m"(temp)); For the commenting bit: fld st fistp qword [temp] ; temp = (QWORD)floor(x); fild qword [temp] fsubp st, st1 ; x -= temp; If you want to be more standards-compliant, you could always do "x-=(long long signed int)x;", but that will produce around 3x more useless opcodes.
|
|
« Last Edit: February 13, 2009, 03:16:37 pm by score_under »
|
Logged
|
|
|
|
|
Post made February 20, 2009, 09:37:23 am was deleted at the author's request.
|
|
|
|