I'm an idiot!

SkyHog

Touchdown! Greaser!
Joined
Feb 23, 2005
Messages
18,431
Location
Castle Rock, CO
Display Name

Display name:
Everything Offends Me
Hey - fun fact: reinitializing a counter within a loop results in an infinite loop.

Sigh.

That is to say:
Code:
$counter = 0;

for ($x = 0; x < $counter; x++){
  about 200 lines of code

  $counter = 0;
  
  about 200 more lines of code

}

Any idea how long it took me to figure out that I reused a variable?
 
So how long did you sit and wait for it to exit the loop before you stopped the code?
 
If you whippersnappers just used i, j, and k as gawd intended.
 
But did you bring the whole office down when you did it.

Ah, the good old days.

I wrote something equivelant to this little ditty once to be executed when a b-700 powered on during training on the computer.

clear flags
select keyboard
power off

Next morning the note on the system said they were unable to fix the power supply problem, Good Luck.
 
How many of you coders out there use the mtasyntactics past foo and bar???

I have confused folks out there with quux from time to time :D
 
Hey - fun fact: reinitializing a counter within a loop results in an infinite loop.
Don't be so hard on yourself. I'd argue that an infinite loop is a physical impossibility. Your loop isn't still running, is it? Then it can hardly be considered "infinite", though perhaps "of greater duration than anticipated".
Any idea how long it took me to figure out that I reused a variable?
An easy thing to do in a language that doesn't require declarations.
-harry
 
Don't be so hard on yourself. I'd argue that an infinite loop is a physical impossibility. Your loop isn't still running, is it? Then it can hardly be considered "infinite", though perhaps "of greater duration than anticipated".
An easy thing to do in a language that doesn't require declarations.
-harry

Infinite without outside interference. But since you brought it up, prove that one can not make an infinite loop. ;)
 
A few years ago a small firm asked me to do some consulting. I flew up to Cleveland, met the staff, etc, and then sat down to see what to issue was with the code.

"The guy that was working on this left, and we need to get this finished and shipped to the client..."

The variables were declared and consistent: Homer, Marge, Bart, Lisa, Maggie, Homer1, Marge1, Bart1, Lisa1, Maggie1, Homer2, Marge2, Bart2, Lisa2, Maggie2, Homer3, Marge3, Bart3, Lisa3, Maggie3, etc.

Them: "How long will it take to fix it?"
Me; "How much is this client worth?"
Them: "$500k"
Me: "Eat the cost -- you'll sink twice that unravelling that spaghetti code."
Them: (a wave of realization passed across his face) "You think [former programmer] did it on purpose...?"
Me: :sosp:
 
I used to do thsi all the time:

recordSet.Open()
do while not recordSet.EOF

recordSet[firstName] = "something"

loop

And it'd take me hours to realize I forgot: recordSet.MoveNext()
 
I used to do thsi all the time:

recordSet.Open()
do while not recordSet.EOF

recordSet[firstName] = "something"

loop

And it'd take me hours to realize I forgot: recordSet.MoveNext()

:rofl:

Been there!!
 
Yeah. That'll happen. If it's an array just use foreach instead of for. I see a ton of php code where people do for loops with counts when they could have just been using foreach. It seems they don't realize you can foreach yourself through multi-dimensional arrays.

As a general rule -- if you find yourself struggling to think of variable names for a counter you've got a problem and should probably restructure the logic.
 
Last edited:
Yeah. That'll happen. If it's an array just use foreach instead of for. I see a ton of php code where people do for loops with counts when they could have just been using foreach. It seems they don't realize you can foreach yourself through multi-dimensional arrays.

As a general rule -- if you find yourself struggling to think of variable names for a counter you've got a problem and should probably restructure the logic.

Or possibly they are writing code that could be moved between languages and wrote to the lowest common logic. AFAIK, C++ or FORTRAN don't use "foreach"...but these are less likely to be used for web sites or the type of work you seem to do.

As for naming variables, I never had a problem. Homer, Marge, Bart, Lisa, Maggie, Homer1, Marge1, Bart1, Lisa1, Maggie1,... seem to work well:fingerwag:
 
Or possibly they are writing code that could be moved between languages and wrote to the lowest common logic. AFAIK, C++ or FORTRAN don't use "foreach"...but these are less likely to be used for web sites or the type of work you seem to do.

As for naming variables, I never had a problem. Homer, Marge, Bart, Lisa, Maggie, Homer1, Marge1, Bart1, Lisa1, Maggie1,... seem to work well:fingerwag:

In C++ there is a for_each function in the standard library that sort of gets you there. It isn't quite the same thing though. There are other libraries that get you much closer.

I wasn't speaking about every language out there. I can't say I know them all. I can say that the ones I have written in (C, C++, PHP, Perl, a little bit of a few others) if you were getting to the point where counter names were becoming an issue you needed to re-structure.

In a lot of languages you can just better use functions which would contain the counter inside the function.

One really can't try and compare FORTRAN to the PHP advice I was giving Nick since he was writing in PHP. (His example was PHP).
 
Last edited:
Infinite without outside interference. But since you brought it up, prove that one can not make an infinite loop. ;)
Well, maybe not impossible, but certainly highly improbable.

At some point the computer running the program will certainly fail.

If, despite highly improbable odds, it continues to function, you always have the backstop that the Sun will only be able to support life on Earth for a few billion more years.

The probability that humans continue to exist at that time, and that they take your computer, with its still running loop, into space with them to their new planet is, I think, sufficiently improbable that we can dismiss it as a possibility.
-harry
 
A few years ago a small firm asked me to do some consulting. I flew up to Cleveland, met the staff, etc, and then sat down to see what to issue was with the code.

"The guy that was working on this left, and we need to get this finished and shipped to the client..."

The variables were declared and consistent: Homer, Marge, Bart, Lisa, Maggie, Homer1, Marge1, Bart1, Lisa1, Maggie1, Homer2, Marge2, Bart2, Lisa2, Maggie2, Homer3, Marge3, Bart3, Lisa3, Maggie3, etc.

Them: "How long will it take to fix it?"
Me; "How much is this client worth?"
Them: "$500k"
Me: "Eat the cost -- you'll sink twice that unravelling that spaghetti code."
Them: (a wave of realization passed across his face) "You think [former programmer] did it on purpose...?"
Me: :sosp:
He most likely just wrote code to obscure his code intentionally (which does happen).
 
Yeah. That'll happen. If it's an array just use foreach instead of for. I see a ton of php code where people do for loops with counts when they could have just been using foreach. It seems they don't realize you can foreach yourself through multi-dimensional arrays.

As a general rule -- if you find yourself struggling to think of variable names for a counter you've got a problem and should probably restructure the logic.

Some of us have a hard time getting up to speed with these new-fangled statements. I am starting to make much more use of foreach and have even grown to like it.

Understand that when I was first learning, this was the best kind of structure we could use:

if ( a == b ) then do something
if ( a != b ) then do another thing

Hint: No "else" statement.
 
He most likely just wrote code to obscure his code intentionally (which does happen).
Really good obfuscators will choose names like i, ii, iii, l, ll, lll, o, oo, ooo, and variations like il, li, li1, il1, oO, o0, oO0, o0O, etc.
 
Really good obfuscators will choose names like i, ii, iii, l, ll, lll, o, oo, ooo, and variations like il, li, li1, il1, oO, o0, oO0, o0O, etc.
Yeah. I suspect his was just home-grown.
 
Code:
[douche ~ 4]cat foo.c
#include <stdio.h>
main(t,_,a)char *a;{return!0<t?t<3?main(-79,-13,a+main(-87,1-_,
main(-86,0,a+1)+a)):1,t<_?main(t+1,_,a):3,main(-94,-27+t,a)&&t==2?_<13?
main(2,_+1,"%s %d %d\n"):9:16:t<0?t<-72?main(_,t,
"@n'+,#'/*{}w+/w#cdnr/+,{}r/*de}+,/*{*+,/w{%+,/w#q#n+,/#{l,+,/n{n+,/+#n+,/#\
;#q#n+,/+k#;*+,/'r :'d*'3,}{w+K w'K:'+}e#';dq#'l \
q#'+d'K#!/+k#;q#'r}eKK#}w'r}eKK{nl]'/#;#q#n'){)#}w'){){nl]'/+#n';d}rw' i;# \
){nl]!/n{n#'; r{#w'r nc{nl]'/#{l,+'K {rw' iK{;[{nl]'/w#q#n'wk nw' \
iwk{KK{nl]!/w{%'l##w#' i; :{nl]'/*{q#'ld;r'}{nlwb!/*de}'c \
;;{nl'-{}rw]'/+,}##'*}#nc,',#nw]'/+kd'+e}+;#'rdq#w! nr'/ ') }+}{rl#'{n' ')# \
}'+}##(!!/")
:t<-50?_==*a?putchar(31[a]):main(-65,_,a+1):main((*a=='/')+t,_,a+1)
:0<t?main(2,2,"%s"):*a=='/'||main(0,main(-61,*a,
"!ek;dc i@bK'(q)-[w]*%n+r3#l,{}:\nuwloca-O;m .vpbks,fxntdCeghiry"),a+1);}
[douche ~ 5]cc -o foo foo.c
[douche ~ 6]./foo
On the first day of Christmas my true love gave to me
a partridge in a pear tree.

On the second day of Christmas my true love gave to me
...
-harry
 
Well, maybe not impossible, but certainly highly improbable.

At some point the computer running the program will certainly fail.

If, despite highly improbable odds, it continues to function, you always have the backstop that the Sun will only be able to support life on Earth for a few billion more years.

The probability that humans continue to exist at that time, and that they take your computer, with its still running loop, into space with them to their new planet is, I think, sufficiently improbable that we can dismiss it as a possibility.
-harry

That isn't proof. ;)
 
I remember one that burned me for a long time in COBOL class (and I don't remember the fr*in syntax so bear with...):

DO PERFORM ROUTINE

LABEL ROUTINE

stuff...

LABEL SUBROUTINE
stuff......

LABEL END_SUBROUTINE

LABEL END_ROUTINE


....


I thought I was sooooo clever knowing I didn't need to make it

DO PERFORM ROUTINE THROUGH END_ROUTINE

because it always worked that way anyway.
 
Really good obfuscators will choose names like i, ii, iii, l, ll, lll, o, oo, ooo, and variations like il, li, li1, il1, oO, o0, oO0, o0O, etc.

Or better yet, use names that appear to be related to the task at hand, but use those names in a way that makes no sense at all. E.G. in a payroll system use a variable named "employee" as the paycheck date, and FICA as the check number. If you mix this with more rational usage on some of the most obvious stuff it's really hard to decipher.

And the trick for undoing any naming based obscuration is to search/replace each and every name with one that makes sense (and has a "uniquifier" prefix) each time you figure one out.
 
Last edited:

Haven't for a long time until earlier this week when I needed a simple program to simulate the serial output of an altitude encoder with controllable delays between certain characters.
 
Hrm...maybe I should code.

I'm pretty confident in most (all?) all aspects of computer hardware and assembly and everything that goes along with it. I have a small business for computer repair going, but I'm not looking to make a career out of computers. Would it be a good idea for me to get started in code?
 
Hrm...maybe I should code.

I'm pretty confident in most (all?) all aspects of computer hardware and assembly and everything that goes along with it. I have a small business for computer repair going, but I'm not looking to make a career out of computers. Would it be a good idea for me to get started in code?

Only if you enjoy frustration (or overcoming it).
 
Only if you enjoy frustration (or overcoming it).

I actually like(d) it. I like puzzle solving. I knew I'd hate having to do it for a living, though.

It helps when I do bug reports like I did, "Need to use TRIM() on the input field to avoid this error"
 
Hrm...maybe I should code.

I'm pretty confident in most (all?) all aspects of computer hardware and assembly and everything that goes along with it. I have a small business for computer repair going, but I'm not looking to make a career out of computers. Would it be a good idea for me to get started in code?
If you are not looking to make money from computers or technology than only you can answer that question. It can be rewarding - but one must realize it takes many years of coding in the proper enviorment to really get good. There are a lot of folks that write absoulte slop.

It can be a fun hobby--For me, it is a combinatin of hobby and career. My direct area requires very little coding, but since I can, I often do.
 
Hrm...maybe I should code.

I'm pretty confident in most (all?) all aspects of computer hardware and assembly and everything that goes along with it. I have a small business for computer repair going, but I'm not looking to make a career out of computers. Would it be a good idea for me to get started in code?

Look at VBA (Visual Basic for Applications) which you can do on any Micorsoft Office Application like Excel.
http://msdn.microsoft.com/en-us/library/aa140980(office.10).aspx (Urk It doesn't look so simple there but it is.)

You can get all of the documentation at Microsoft.com Start with the sample code they have for each function.

Also try the O'Relliey nutshell books but those are better if you understand the concepts of program flow

Try a course at a community college.
 
Last edited:
Back
Top