Comment On Now *That* is a Way to do States

It's hard to believe, but a good seven months ago, I honestly thought that using an autonumber as the primary key (instead of OH, NY, etc) was a bad way of implementing a States table in a database. Of course, thanks to everyone who's submitted things over the months (you guys rock, by the way), tblState would simply have been tossed in the "not using best-practices" category. But I think we can all agree that this state-handling routine from Kurt Payne would definitely fit in the Whisky Tango Foxtrot category ... [expand full text]
« PrevPage 1Next »

Re: Now *That* is a Way to do States

2005-01-31 11:59 • by

AHH!  I'm blind!
Oh, sorry, I looked at it directly.


Let me start by asking: why is each of those scalar variables taking an array slice as a value?


Actually, I think I'll end with that too.  I keep scrolling up out of fascination, but I'm afraid if I do it again I'll be scarred for life.

Re: Now *That* is a Way to do States

2005-01-31 12:05 • by
Aagghh! It burns!

Re: Now *That* is a Way to do States

2005-01-31 12:15 • by icelava
Finally, hard evidence that you can be at two different places (states) at one time.

Re: Now *That* is a Way to do States

2005-01-31 12:15 • by
28710 in reply to 28708
I ...............can't...................see.......................why

Re: Now *That* is a Way to do States

2005-01-31 12:28 • by
I don't see any WTF here.



The data from the states array/scalar was probably unreliable, and the
only way to ensure absolutely that the correct states were printed out
was to type them in by hand for each option box.  

Re: Now *That* is a Way to do States

2005-01-31 12:30 • by sas
Shouldn't all the

$statename = @data[n];


be

$statename = $data[n];

 [^o)]

Re: Now *That* is a Way to do States

2005-01-31 12:35 • by KoFFiE
28714 in reply to 28713
sas:
Shouldn't all the

$statename = @data[n];


be

$statename = $data[n];

 [^o)]



I think it's a tcl application, and as far as I remember, arrays are indicated with an @...

Re: Now *That* is a Way to do States

2005-01-31 12:45 • by sas
28716 in reply to 28714
It looks like a lame attempt at Perl to me, but I don't know what tcl
looks like.  In Perl, arrays are referred to with @ prefix, but
only for the entire array.  Element references use the $ (scalar)
prefix.

Re: Now *That* is a Way to do States

2005-01-31 13:13 • by
28719 in reply to 28713

sas:
Shouldn't all the
$statename = @data[n];

be
$statename = $data[n];
 [^o)]


This is perl and the person who wrote it used @data[0] instead of $data[0].  It only throws a warning, but still runs.


And, no, the application did NOT have a database behind it.


--Kurt

Re: Now *That* is a Way to do States

2005-01-31 13:27 • by
28720 in reply to 28713

sas:


Shouldn't all the
$statename = @data[n];

be
$statename = $data[n];


Yes, you're right.  This code happens to work in this situation, but it is wrong.  The former is a an array slice of length 1, the latter is an array element.  Arrays provide a list context, and elements provide a scalar context.  Since Perl is context sensitive, you can get different results depending on which context you provide.  This is explained in the Perl FAQ, part 4, section Arrays.

Re: Now *That* is a Way to do States

2005-01-31 13:35 • by Mike R

How do people get away with writing crap like this?


I'm beginning to believe I've met trained cockroaches that can code better than some of these examples. Of course, I've seen my fair share of "programmers" like this in the real world, somehow they retain their jobs, while the ones that actually wrote decent code get laid off. Maybe it's PHB syndrome... Maybe it's the high corporate execs looking at the staff list going.. "This one is making 54% more than his peers, he needs to go. Send him the axe" ...

Re: Now *That* is a Way to do States

2005-01-31 13:40 • by fluffy
FWIW, this looks very little like Tcl.  You can tell Tcl code because it looks like this:



set var "value"

for { set i 1 } { i < 100 } { incr i } {

    puts "i = $i"

}



Also, Tcl's syntax is extremely basic which makes it so that you can't
format brackets the way you want to; for example, you can't say



for { set i 1 } { i < 100 } { incr i }

{

    puts "i = $i"

}



because that would make the puts block evaluate separately from the for
command.  (And not surrounding it by brackets would be right out!)



Basically, in a for loop, if statement, etc., the subordinate pieces of
code are passed in as parameters to the for/if/etc. functions. 
It's a fascinating language from the design and theory standpoint (it's
basically LISP with variable side-effects and a sequence operator, and
writing a Tcl parser/interpreter is extremely simple),
though not very useful for real-world apps programming. 
Personally, I only use Tcl when I need to write a quick script which
does more numerical processing than is convenient in bash.



But this is all besides the point.  My eyeballs nearly exploded
when I looked at today's WTF.  I seriously hope that whatever
"programmer" wrote that  used copy-paste.

Re: Now *That* is a Way to do States

2005-01-31 13:46 • by

I just love how people try to jump in and justify code, no matter how bad it is.


You can't justify this one folks, the code is just plain stupid.

Re: Now *That* is a Way to do States

2005-01-31 14:08 • by CornedBee
My fingers fall off just from looking at it.



Man, am I glad that Austria only has 9 counties.

Re: Now *That* is a Way to do States

2005-01-31 14:11 • by
Argh!  What about Puerto Rico?  What about Guam or American
Samoa?  What about (horrors) an actual foreign country?

Re: Now *That* is a Way to do States

2005-01-31 14:14 • by
What aggravates me is that I have spent most of my career fixing shtuff like this while the knuckle-head that wrote it is creating new shtuff for me to fix.

Re: Now *That* is a Way to do States

2005-01-31 14:59 • by Scott
So is this code at least used in situations where you don't want all of
the states?  Please say that there is at least some point to this
code.

Re: Now *That* is a Way to do States

2005-01-31 15:02 • by
WTF? Why does a blog software search smileys inside of <PRE>-Tags?



Re: Now *That* is a Way to do States

2005-01-31 15:13 • by
28733 in reply to 28731

Scott:
So is this code at least used in situations where you don't want all of the states?  Please say that there is at least some point to this code.


Yes.  This code was used to generate forms for a website and each form had different states that it applied for.  For example, the website may sell a product, but only to particular states.  For another website, run by the same software, they may sell a product to a different set of states.


Because of the nature of the beast (US laws and regulations pertaining to the product / services these websites offer), these sites would never do business outside of the 50 states or Washington D.C.  So it doesn't have to account for any territories / protectorates / foreign countries / etc.


--Kurt

Re: Now *That* is a Way to do States

2005-01-31 15:39 • by

May I please recommend folks use the FIPS standards?


http://www.census.gov/geo/www/fips/fips.html


 

Re: Now *That* is a Way to do States

2005-01-31 15:42 • by
the redundancy ... hurts me poor brain. Clueless perl, wrong on so many levels that I don't want to even start.



I'm part of the company interview process, and we get perl fragments
every now and then from potential employees. You can guess what sort of
stuff I have to wade. This, is however, even worse than the typical
stuff.[*-)]

Re: Now *That* is a Way to do States

2005-01-31 17:10 • by
28736 in reply to 28731
The true WTF is reading the posts from people saying "This code isn't that bad..."

Re: Now *That* is a Way to do States

2005-01-31 17:44 • by
28744 in reply to 28736

Wow! You have to be a special kind of stupid to write something like that.


Skip.

Re: Now *That* is a Way to do States

2005-01-31 19:52 • by
I don't see any wtf here. It's beautiful clean code, and much similiar to the
code i usually write. Futhermore it's easy to understand and does
excatly what it should.

Re: Now *That* is a Way to do States

2005-01-31 21:42 • by
When you have a loop with a known number of iterations, it's faster to
expand it, since you don't have to do the checking for the loop
condition each time (this is called "loop unrolling"). So this is much
more efficient.

Re: Now *That* is a Way to do States

2005-01-31 22:11 • by
28752 in reply to 28751
So tell me, what is the limit of loop unrolls? When will you stop unrolling loops? At 100? At 1000?

Re: Now *That* is a Way to do States

2005-02-01 01:27 • by Drak
28754 in reply to 28752

I'm getting RSI (or whatever it is called these days) just by looking at this code. My pooooooor hands [:(]


Drak

Re: Now *That* is a Way to do States

2005-02-01 01:36 • by
28755 in reply to 28752

Usually the compiler in use decides when to do loop optimizations. Size vs speed is one factor which needs to be considered...


But there are two special cases:



  1. Developer who have profiled the system and detected that some loop is a bottleneck and manually unrolls the loop.

  2. Some wannabe übersmart developer unrolls the loop for some nogood reason. Usually (s)he also often finds bugs in the compiler when trying to compile his/her code too [;)].

Re: Now *That* is a Way to do States

2005-02-01 02:42 • by
28756 in reply to 28751
:
When you have a loop with a known number of iterations, it's faster to
expand it, since you don't have to do the checking for the loop
condition each time (this is called "loop unrolling"). So this is much
more efficient.





No! No no no no no no no! Now crawl back under the rock before I smack you!



Code like this is simply too horrible to be justified in any way. Leave loop-unrolling to the compiler.

Re: Now *That* is a Way to do States

2005-02-01 03:58 • by
28758 in reply to 28756
yes, in this case loop-unrolling truely is irrelevant.



(but it should not allways be left to the compiler (unless the compiler
has a way to specify which loops should be unrolled) - on critical
algorithms or old computers loop unrolling will roxX0rz.)

Re: Now *That* is a Way to do States

2005-02-01 04:41 • by CannonFodda

Well at least there in alphabetical order, you've got to give the guy credit for that.


I'd love to see the code from this guy when he is capturing someones title though!

Re: Now *That* is a Way to do States

2005-02-01 06:20 • by
28768 in reply to 28723

fluffy:
FWIW, this looks very little like Tcl.  You can tell Tcl code because it looks like this:
[snip]


That was a joke, right?  Please?

Re: Now *That* is a Way to do States

2005-02-01 07:31 • by
28776 in reply to 28749
Are you guys hiring? [:)]

Re: Now *That* is a Way to do States

2005-02-01 14:59 • by


Did the author of this code work for Anderson/Accenture consulting?
I've only seen perl that bad in one place... and it was written by
someone from Accenture.



Ok, so the company that the app is written for can only sell in the 50
states... what if texas is divided into it's 5 proposed states?





Re: Now *That* is a Way to do States

2005-02-01 15:57 • by

Hey everybody! I'm here to justify this code!


Here goes...wait a sec...WHAT WAS I THINKING?!? [:$]

Re: Now *That* is a Way to do States

2005-02-01 16:20 • by

I think we're all missing the point here. The guy who wrote this code is probably making 120K/yr. at some Fortune 500 company. Management probably hangs on his ever word and suggestion.


And he continues writing the same sort of code...


Dude, that hurts.

Re: Now *That* is a Way to do States

2005-02-01 22:13 • by
28843 in reply to 28817
:

I think we're all missing the point here. The guy who wrote this code is probably making 120K/yr. at some Fortune 500 company. Management probably hangs on his ever word and suggestion.


And he continues writing the same sort of code...


Dude, that hurts.



Nah, it was either my boss or another developer who doesn't work here anymore.  It wasn't a highly paid consultant, it was someone who was a great programmer -- of DOS apps -- and who shouldn't be writing perl.


--Kurt

Re: Now *That* is a Way to do States

2005-02-02 10:49 • by
28862 in reply to 28726

:
What about (horrors) an actual foreign country?


No No No, If its all right with you guys Stateside, please keep such programmers, and the systems they spawn to yourself.....

Re: Now *That* is a Way to do States

2005-02-03 17:30 • by Inkieminstrel
I don't know what you guys are talking about.  This is the first time I've ever actually been able to read Perl.

Re: Now *That* is a Way to do States

2005-02-04 21:51 • by
29102 in reply to 28749
I'd hate to see you architect a large building, much less a dynamic Web site.

Re: Now *That* is a Way to do States

2005-02-06 14:01 • by
Yeah, exactly. It's clean and elegant code.



You people are probably just jelus because you cant write so beutiful code.

Re: Now *That* is a Way to do States

2005-02-07 04:20 • by CannonFodda

And you're probably just jelious for your beautiful spelling mistakes. But never mind.[8-|]

Re: Now *That* is a Way to do States

2005-02-09 07:37 • by
29318 in reply to 28726
:
Argh!  What about Puerto Rico?  What about Guam or American
Samoa?  What about (horrors) an actual foreign country?



Brace yourself, Romania actually has 42 (count'em) counties. And I've seen just this kind of crap in a FoxPro application, which, actually and by definition, *was* backed by a database (however primitive). The guy who wrote it seemed overly concerned about fitting the county-related code in a single file. Maybe it's the same thing here.

As for Perl, when I first tried it and decided it was too much for my poor little human brain, I just gave up on in and went for PHP. WTF, is that such a hard thing to do?

Re: Now *That* is a Way to do States

2005-02-09 08:30 • by
29319 in reply to 28749
I do hope whoever wrote that was doing their first day on the job.

Re: Now *That* is a Way to do States

2008-04-09 13:42 • by M4 (unregistered)
188922 in reply to 29319
:
I do hope whoever wrote that was doing their first day on the job.


I do hope whoever wrote that was doing their LAST day on the job.

Re: Now *That* is a Way to do States

2009-09-14 05:20 • by Anthony Gatlin (unregistered)
285088 in reply to 188922
As untalented as this developer is, there are organizations where he could still be their best. Note to developer: The State of Texas is hiring.

Re: Now *That* is a Way to do States

2012-01-26 22:51 • by Hand-E-Food
I'm no native of the USA, but do I count 51 states? (Indices 4 through 54.)

Re: Now *That* is a Way to do States

2012-03-22 16:38 • by tharpa
377522 in reply to 373124
Hand-E-Food:
I'm no native of the USA, but do I count 51 states? (Indices 4 through 54.)

The District of Columbia is not a state, but it is considered as a state for many purposes. (Writing this from DC.)
« PrevPage 1Next »

Add Comment