Decade-old WTF
-
A snippet from some code my predecessor left behind. File is dated 11/18/1994 03:51 PM; language is Clipper Summer '87 but it should be clear anyhow .. very basic-like. (nofc stands for "number of full cartons"; .t. and .f. are "true" and "false" literals)<FONT size=+0><FONT style="BACKGROUND-COLOR: #d3d3d3"> avgwgt = round(pounds / nofc,0)
if pounds % nofc > 0
left = .t.
avgwgt = avgwgt + 1
remain = pounds
for x = 1 to nofc - 1
remain = remain - avgwgt
next
else
left = .f.
endif</FONT>
</FONT>He's bright enough to use mod to test for divisibility, but then uses repeated subtraction ... dios mio.
-
Eww. That "for" loop is sooo unsafe.
-
Hope there's a check that nofc > 0 somewhere before this...
-
If it were zero, though, you'd hit an exception in the first line and bounce out before being stuck in the loop.
If that's any better...
-
You also have to remember that some programming languages don't throw
exceptions when something is wrong. They just silently ignore the
explosion that's happening and go about there business. I've restarted
my fair share of computers because of infinite loops caused by
programming such as this.
-
<FONT size=2>Hope there's a check that nofc > 0 somewhere before this...
</FONT><FONT size=2>As it happens, there was such a check. But Clipper is so verbose and, to my current eye, ugly, that I didn't want to inflict any more on you.</FONT><FONT size=2></FONT><FONT size=2>But, since you asked ... here's the block that enclosed the snippet I started with.</FONT><FONT size=2>[code language="vb"]if nofc > 0
avgwgt = round(pounds / nofc,0)
if pounds % nofc > 0
left = .t.
avgwgt = avgwgt + 1
remain = pounds
for x = 1 to nofc - 1
remain = remain - avgwgt
next
else
left = .f.
endif
select a
for x = 1 to b->nofc
append blank
replace package_id with key
replace serv_type with 4
replace cust_no with substr(b->clubno,1,5)+"-"+substr(b->clubno,6,3)
replace dest_code with d->zip
replace resident with "N"
if b->sendcode = "U"
replace pickup with 1
else
replace pickup with 2
endif
replace reference with h_jobno
replace zone with z
replace weight with avgwgt
replace filler with "000000000"
replace dimwgt with " "
replace oversize with "N"
replace addhandchr with " "
replace value with 0
replace confirmtyp with "0"
replace handling with 0
replace cod_amt with 0
replace cash_only with "N"
replace name with d->name
replace atten with d->address1
replace street with d->address2
replace city with d->city
replace state with d->state
replace phone with transform(d->phone,"(999) 999-9999")
replace zip with d->zip
key = key + 1
next
if left
replace weight with remain
endif
endif[/code]</FONT>
-
I haven't had to look at Clipper code in about 6 years... Now I remember why I don't like it... [:P]
-
Two decade old ?
-
One decade old. Presumably a remnant of the import.