Comment On Now That's A Neat Trick

Brian was excited to join an organization that boasts managing data for "93% of all health care facility inspections." That's important stuff, after all: inspections are essential to maintaining the integrity of facilities and can make the difference between life and death of its patients. But after eight months working there, Brian now looks for facilities in the "other 7%" for his personal health care needs. [expand full text]
« PrevPage 1 | Page 2 | Page 3Next »

Re: Now That's A Neat Trick

2006-09-26 13:37 • by ouch
Maintainable shmaintainable!

Re: Now That's A Neat Trick

2006-09-26 13:44 • by hyness

The horror...he's using + to concat strings in SQL when everyone knows it's ||.  Then he escapes quotes with \' when everyone knows it's ''.

That's the WTF, right?  ;-) 

Re: Now That's A Neat Trick

2006-09-26 13:46 • by ummmWhat?

I would say they should bring that code to the CTO's boss to see if
they can get rid of him, but if the CTO made it that far up the ranks I
can only imagine what the CTO's boss would produce for his "The "Now That's a Neat Trick!" code. 

Re: Now That's A Neat Trick

2006-09-26 13:47 • by neven
Needs more Javascript.

Re: Now That's A Neat Trick

2006-09-26 13:49 • by Scott

You know, The Cleverness Scale isn't a bad way to predict quality...provided you view 1 as the highest score and 4 as the lowest.
 

Re: Now That's A Neat Trick

2006-09-26 13:52 • by mkb
93229 in reply to 93225
Anonymous:

You know, The Cleverness Scale isn't a bad way to predict quality...provided you view 1 as the highest score and 4 as the lowest.
 


It's not that simple. Sometimes you have to do a 2 or a 3 in order to fit 2 values into one register, or one ioctl argument, or use certain Windows SDK functions as designed and documented (ugh). When the choice is between cleverness and brokenness, clever wins every time!

Re: Now That's A Neat Trick

2006-09-26 13:53 • by longtimer
93231 in reply to 93225
I recall a WTF being featured in this space not that long ago where the web page rewrote itself, or something to that effect, and we all mocked it. Apparently, we just don't recognize true cleverness when we see it ;)

Re: Now That's A Neat Trick

2006-09-26 13:54 • by Anon

Multi-Tear architecture.

Re: Now That's A Neat Trick

2006-09-26 13:54 • by Anonymous

Because we all know that code that is impossible to maintain, barely readable, and borderline functional is always better than straight-laced "by the book" code as long as it's clever!

If anybody tried anything rating above a 1 on that scale, they'd be fired at most places, and thankfully so.  How this guy got to be the CTO is a real mystery, or at the very least, how he got the idea that he had enough skills to "show the developers how it's done."  Eeesh.

CAPTCHA: paula; seems oddly appropriate for this one.

Re: Now That's A Neat Trick

2006-09-26 13:54 • by WIldpeaks

That recalls me of something I've read here:

"It could be worse, imagine if this guy knew about XML..." :-)

Re: Now That's A Neat Trick

2006-09-26 13:57 • by sVB_Enterprise_Specialist
I don't ever want to score a 2 or higher...

Re: Now That's A Neat Trick

2006-09-26 14:00 • by longtimer
93236 in reply to 93235

Anonymous:
I don't ever want to score a 2 or higher...

Actually, that's not always the case. Admittedly, most of the time I take the simple-to-understand-and-maintain-so-I-can-hand-it-off-and-move-on approach, but there are those (usually) rare occasions when true cleverness and programming slight-of-hand are required. The trick is to know the difference.

Re: Now That's A Neat Trick

2006-09-26 14:02 • by GoatCheez
Definitely clever to the max... if anyone ever wants to change something in that, the easiest, fastest, most secure way would be to completely rewrite it.... unless you wrote it in the first place..... Brillant....

Re: Now That's A Neat Trick

2006-09-26 14:02 • by AndrewVos

Javascript never really was "pretty" was it. Maybe once, for a day or two.

Do I really need to change my rss settings :(

Re: Now That's A Neat Trick

2006-09-26 14:03 • by TrippyZ
93240 in reply to 93232
Is this a N-Tear architecture?

Re: Now That's A Neat Trick

2006-09-26 14:04 • by ammoQ

The Real WTF(tm) is that the clever query is hardcoded. Should be an http query parameter. Now that would be neat trick.

 

 

;-) 

Re: Now That's A Neat Trick

2006-09-26 14:04 • by dasmb

More mistakes are made through cleverness than have ever been made through stupidity.

dasmb (a dumbass)
 

Re: Now That's A Neat Trick

2006-09-26 14:21 • by Jonathan Grynspan
I've done a 2 once in a while--sometimes, you're constrained to reuse an int32 to store two int16s. But yeesh!

Re: Now That's A Neat Trick

2006-09-26 14:21 • by doodle
93249 in reply to 93240

Anonymous:
Is this a N-Tear architecture?

 Looks like uNi-Tear

Re: Now That's A Neat Trick

2006-09-26 14:27 • by foxyshadis
93253 in reply to 93220
Anonymous:

The horror...he's using + to concat strings in SQL when everyone knows it's ||.  Then he escapes quotes with \' when everyone knows it's ''.

That's the WTF, right?  ;-) 

The quotes are for PHP's benefit, not SQL's. PHP is the outermost layer (someone has to run that SQL after all). SQL isn't going to care about double-quotes when it's opened with single quotes. I've never even heard of || to concatanate anything, short of incredibly painful C++ operator overloads, but then I'm no SQL guru.

I guess technically the HTML's still being done at the PHP layer... even if it has to take a round trip through the database first. o.O

Re: Now That's A Neat Trick

2006-09-26 14:28 • by No
93255 in reply to 93242
Anonymous:

More mistakes are made through cleverness than have ever been made through stupidity.

dasmb (a dumbass)
 

Doubtful.

Re: Now That's A Neat Trick

2006-09-26 14:34 • by dwightschrute
Question. Is the CTO Michael Scott of Dunder-Mifflin (Scranton Region)?

Re: Now That's A Neat Trick

2006-09-26 14:58 • by themagni
93259 in reply to 93248

Anonymous:
I've done a 2 once in a while--sometimes, you're constrained to reuse an int32 to store two int16s. But yeesh!

union address
{
  int32 location;
  int8[4] sub;
}

This way, the 32-bit address could be manipulated using simple mathematics yet be passed to the SPI bus as the 8-bit numbers required by the M25PX0.

For example, after saving a 10-byte value: 

address.location += 10;

And when writing to the SPI:

SPI_WRITE( SPI_WRITE_ENABLE );
SPI_WRITE( address.sub[ 0 ] );
SPI_WRITE( address.sub[ 1 ] );
SPI_WRITE( address.sub[ 2 ] );

Re: Now That's A Neat Trick

2006-09-26 14:59 • by Pedersen
93260 in reply to 93253

I've never even heard of || to concatanate anything,

Allow me to introduce you to PostGreSQL, which uses it for concatenation of strings. 

Re: Now That's A Neat Trick

2006-09-26 15:05 • by [exa]

Holy God..the bad thing is that I have to live with several more people of this species.


and ... Too bad the CTO seems not to know Bash scripting. I guess SQL code generated in bash (with backslashing, yeeeah) would receive level 5 rating..

Re: Now That's A Neat Trick

2006-09-26 15:06 • by Digitalbath
I'm afraid that example only gets a 3 in my book.  The use of INNER JOIN is in no way clever.  Surely, he could have come up with a neater way to waste time.

Re: Now That's A Neat Trick

2006-09-26 15:09 • by dave

"it turns out that there's some sort of relationship between clever code and incredibly painful maintenance"

 

Someone,
and it may have been Dennis Ritchie, but if it wasn't it was another
one of those Unix guys, once observed that debugging is twice as hard
as writing code in the first place, so if you write code that's as
clever as you know how, by definition you're not going to be able to
fix it.

 

 

Re: Now That's A Neat Trick

2006-09-26 15:11 • by savar
93266 in reply to 93220
Anonymous:

The horror...he's using + to concat strings in SQL when everyone knows it's ||.  Then he escapes quotes with \' when everyone knows it's ''.

That's the WTF, right?  ;-) 

 Eh? I don't see any +'s in the SQL code.

 
Where is the PHP, by the way?

I would guess this code was once again anonymized from relative WTFness into SUPER WTFness.
 

Re: Now That's A Neat Trick

2006-09-26 15:13 • by Clever?

How is this "clever"? The main sin I see is mixing more HTML + JavaScript than is needed (could have made more use of JS functions, or styles instead of colors).

What I define as "clever" is the massive barely-documented n-tier superstructures that are employed for the most trivial of apps. Sometimes, the simplest solution works the best, and sometimes that's a plain old SQL query.

Re: Now That's A Neat Trick

2006-09-26 15:15 • by Grimoire
93268 in reply to 93233
Anonymous:

How this guy got to be the CTO is a real mystery

He was probably demoted upwards. 

Re: Now That's A Neat Trick

2006-09-26 15:17 • by No
93270 in reply to 93266
savar:
Anonymous:

The horror...he's using + to concat strings in SQL when everyone knows it's ||.  Then he escapes quotes with \' when everyone knows it's ''.

That's the WTF, right?  ;-) 

 Eh? I don't see any +'s in the SQL code.


Where is the PHP, by the way?

I would guess this code was once again anonymized from relative WTFness into SUPER WTFness.
 

 

$sql = "
  SELECT
    CONCAT(

Re: Now That's A Neat Trick

2006-09-26 15:21 • by Kai MacTane
93271 in reply to 93264
Someone,
and it may have been Dennis Ritchie, but if it wasn't it was another
one of those Unix guys, once observed that debugging is twice as hard
as writing code in the first place, so if you write code that's as
clever as you know how, by definition you're not going to be able to
fix it.


Seems it was Brian Kerhighan. At least according to this page, which may or may not be definitive, but which does score points with me for linking to Kernighan's home page, at least.

Re: Now That's A Neat Trick

2006-09-26 15:25 • by Ghost Ware Wizard

You know I think the terminology for the CTO being where he is is rather incrongruous and at worst shamefully true.  He got to where he is today via a combination of 1) the good 'ol boy network, 2) he *knows* information technology, and 3) just plain shmoozin' with the suits dear wives at a shin-dig on a weekend.  We all know and understand that he's a complete idiot when it comes to 1) actual code writing, 2) implementation of an project (on time and under budget) and 3) testing for completeness in regards to those pesky user requirements.

WTF? he's only doing what he *thinks* is right so why bother pointing out to him he's a blathering idiot with a paycheck 94 times the average programmer with no justifiction for such a high salary and that since he is the CTO trust him.

 

Re: Now That's A Neat Trick

2006-09-26 15:50 • by Freek
What? No XML?

Re: Now That's A Neat Trick

2006-09-26 15:56 • by Jojosh_the_Pi
At least the CTO wasn't hoping to get rid of all that JOIN stuff.

Re: Now That's A Neat Trick

2006-09-26 16:02 • by ParkinT
93278 in reply to 93232
Anonymous:

Multi-Tear architecture.

Now THAT is clever!!

Re: Now That's A Neat Trick

2006-09-26 16:02 • by ang
1 - The Shrug-- Gets the job done, efficient, all that; but just plain boring.
2 - The Nod -- Creative, as in, using a single 32-bit integer variable to store two 16-bit integers.
3 - The Raised Left-Eyebrow -- Very creative, as in, combining all function arguments into a single pipe-delimited string
4 - The "Now That's a Neat Trick!" -- The ultimate in cleverness, as in, code that rewrites itself but maintains the original using generated comments

 

That's much like my scale:

1 - "Good"

2 - "Interesting"

3 - "Clever, but wrong"

4 - "I never would have thought to do it that way"

Re: Now That's A Neat Trick

2006-09-26 16:04 • by ParkinT
93280 in reply to 93233
Anonymous:

  How this guy got to be the CTO is a real mystery, or at the very least, how he got the idea that he had enough skills to "show the developers how it's done." 

If you have never read The Peter Principle you must.  It continues to hold true!! I have seen examples again and again (in my 30+ years working life).

Re: Now That's A Neat Trick

2006-09-26 16:05 • by Jeff

Okay, I get sick of developer egos sometimes, but the hubris of this guy to think that THAT is good code? WTF?

It's easy to program and (generally) solve a problem, but do people just stop learning and thinking when they get just far enough? And of course it's our job to work with or clean up code like that. They should at least be smart enough to take a step back and let the professionals do their job. (I know, I'm asking too much.)

*sigh*

Re: Now That's A Neat Trick

2006-09-26 16:06 • by Maybe
93282 in reply to 93279
Anonymous:
1 - The Shrug-- Gets the job done, efficient, all that; but just plain boring.
2 - The Nod -- Creative, as in, using a single 32-bit integer variable to store two 16-bit integers.
3 - The Raised Left-Eyebrow -- Very creative, as in, combining all function arguments into a single pipe-delimited string
4 - The "Now That's a Neat Trick!" -- The ultimate in cleverness, as in, code that rewrites itself but maintains the original using generated comments

 

That's much like my scale:

1 - "Good"

2 - "Interesting"

3 - "Clever, but wrong"

4 - "I never would have thought to do it that way"

 Haha!

Re: Now That's A Neat Trick

2006-09-26 16:07 • by gutnor
93283 in reply to 93260

I've never even heard of || to concatanate anything,

Allow me to introduce you to PostGreSQL, which uses it for concatenation of strings.

 

Same in Oracle. || is the concat operator.

Re: Now That's A Neat Trick

2006-09-26 16:11 • by ammoQ
 

2 - The Nod -- Creative, as in, using a single 32-bit integer variable to store two 16-bit integers.

3 - The Raised Left-Eyebrow -- Very creative, as in, combining all function arguments into a single pipe-delimited string



IMO 2 is by far more tricky than 3. 3 is almost normal in the age of HTTP and XML.


Re: Now That's A Neat Trick

2006-09-26 16:18 • by Anon
93287 in reply to 93267
Anonymous:

How is this "clever"? The main sin I see is mixing more HTML + JavaScript than is needed (could have made more use of JS functions, or styles instead of colors).

What I define as "clever" is the massive barely-documented n-tier superstructures that are employed for the most trivial of apps. Sometimes, the simplest solution works the best, and sometimes that's a plain old SQL query.

 Mixing HTML and Javascript is fine. Mixing HTML and Javascript inside SQL is the sin.

Seperating your application into data, logic and presentation layers is just good practice. If your application reads, processes and displays data it is probably sufficiently complex to warrant these layers.

You should always be able to alter the apperance of the site without worrying about corrupting your data and logic.

 

Re: Now That's A Neat Trick

2006-09-26 16:28 • by ammoQ
93288 in reply to 93281
Anonymous:

Okay, I get sick of developer egos sometimes, but the hubris of this guy to think that THAT is good code? WTF?

It's easy to program and (generally) solve a problem, but do people just stop learning and thinking when they get just far enough? And of course it's our job to work with or clean up code like that. They should at least be smart enough to take a step back and let the professionals do their job. (I know, I'm asking too much.)

*sigh*

Indeed, "good enough" is a common theme in our business. Unfortunately, because everything seems to change every single day, sooner or later everyone of us has to say "ok, enough learned, now let's try to do something usefull".

Re: Now That's A Neat Trick

2006-09-26 16:40 • by L33+e

Aww, come on! That code isn't so bad. If he had only used styles, it would be possible to alter the presentation somewhat.

So you say it's not maintainable? I don't know about that? You can look at the code pretty briefly and get a good idea of what it does, which is probably more than you could if it were abstracted away in layer upon layer of indirection.

And even if it isn't maintainable, that code is so brief that you can afford to write it once, and if you ever need to alter something, throw it away and write it anew.

Sometimes you can spend weeks and months building up a service-oriented, multi-tiered, abstract, open standards, bells-and-whistles framework, and if all you need to do is produce a simple report then you've grossly over-engineered the solution.

 

Re: Now That's A Neat Trick

2006-09-26 16:45 • by Adam
93294 in reply to 93238

GoatCheez:
Definitely clever to the max... if anyone ever wants to change something in that, the easiest, fastest, most secure way would be to completely rewrite it.... unless you wrote it in the first place..... Brillant....

Nope, even if you were the original author, rewriting it is easier, faster, and more secure. 

Re: Now That's A Neat Trick

2006-09-26 16:46 • by Unklegwar
93295 in reply to 93232
Anonymous:

Multi-Tear architecture.

 

I love it!

Re: Now That's A Neat Trick

2006-09-26 17:02 • by gary
93298 in reply to 93295
this is one of the worst ever.

Re: Now That's A Neat Trick

2006-09-26 17:07 • by Dark
93299 in reply to 93259
themagni:

union address
{
  int32 location;
  int8[4] sub;
}

This way, the 32-bit address could be manipulated using simple mathematics yet be passed to the SPI bus as the 8-bit numbers required by the M25PX0.

For example, after saving a 10-byte value: 

address.location += 10;

And when writing to the SPI:

SPI_WRITE( SPI_WRITE_ENABLE );
SPI_WRITE( address.sub[ 0 ] );
SPI_WRITE( address.sub[ 1 ] );
SPI_WRITE( address.sub[ 2 ] );


 

If you do it that way, endianness will bite you. There's no guarantee that sub[0] is the low byte. This might not matter if you're writing for specific hardware... but even hardware is hardware-independent these days. PCI cards can be plugged into PowerPC machines.

It's best to write some macros that use >> and & to extract specific bytes.

 

Re: Now That's A Neat Trick

2006-09-26 17:08 • by Sean
93300 in reply to 93279
Anonymous:
1 - The Shrug-- Gets the job done, efficient, all that; but just plain boring.
2 - The Nod -- Creative, as in, using a single 32-bit integer variable to store two 16-bit integers.
3 - The Raised Left-Eyebrow -- Very creative, as in, combining all function arguments into a single pipe-delimited string
4 - The "Now That's a Neat Trick!" -- The ultimate in cleverness, as in, code that rewrites itself but maintains the original using generated comments

 

That's much like my scale:

1 - "Good"

2 - "Interesting"

3 - "Clever, but wrong"

4 - "I never would have thought to do it that way, and there's a reason for that"

 

There.  Fixed that for you.
 

« PrevPage 1 | Page 2 | Page 3Next »

Add Comment