• ouch (unregistered)

    Maintainable shmaintainable!

  • hyness (unregistered)

    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?  ;-) 

  • ummmWhat? (unregistered)

    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. 

  • (cs)

    Needs more Javascript.

  • Scott (unregistered)

    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.
     

  • (cs) in reply to Scott
    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!

  • (cs) in reply to Scott

    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 ;)

  • Anon (unregistered)

    Multi-Tear architecture.

  • Anonymous (unregistered)

    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.

  • (cs)

    That recalls me of something I've read here:

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

  • sVB_Enterprise_Specialist (unregistered)

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

  • (cs) in reply to sVB_Enterprise_Specialist

    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.

  • (cs)

    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....

  • AndrewVos (unregistered)

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

    Do I really need to change my rss settings :(

  • TrippyZ (unregistered) in reply to Anon

    Is this a N-Tear architecture?

  • (cs)

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

     

     

    ;-) 

  • dasmb (unregistered)

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

    dasmb (a dumbass)
     

  • Jonathan Grynspan (unregistered)

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

  • doodle (unregistered) in reply to TrippyZ

    Anonymous:
    Is this a N-Tear architecture?

     Looks like uNi-Tear

  • (cs) in reply to hyness
    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

  • No (unregistered) in reply to dasmb
    Anonymous:

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

    dasmb (a dumbass)
     

    Doubtful.

  • dwightschrute (unregistered)

    Question. Is the CTO Michael Scott of Dunder-Mifflin (Scranton Region)?

  • (cs) in reply to Jonathan Grynspan

    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 ] );

  • Pedersen (unregistered) in reply to foxyshadis

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

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

  • [exa] (unregistered)

    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..

  • (cs)

    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.

  • dave (unregistered)

    "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.

     

     

  • (cs) in reply to hyness
    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.
     

  • Clever? (unregistered)

    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.

  • (cs) in reply to Anonymous
    Anonymous:

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

    He was probably demoted upwards. 

  • No (unregistered) in reply to savar
    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(

  • (cs)

    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.

     

  • Freek (unregistered)

    What? No XML?

  • (cs)

    At least the CTO wasn't hoping to get rid of all that JOIN stuff.

  • (cs) in reply to Anon
    Anonymous:

    Multi-Tear architecture.

    Now THAT is clever!!

  • ang (unregistered)
    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"

  • (cs) in reply to Anonymous
    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).

  • Jeff (unregistered)

    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*

  • Maybe (unregistered) in reply to ang
    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!

  • gutnor (unregistered) in reply to Pedersen

    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.

  • (cs)
     

    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.

  • Anon (unregistered) in reply to Clever?
    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.

     

  • (cs) in reply to Jeff
    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".

  • L33+e (unregistered)

    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.

     

  • Adam (unregistered) in reply to GoatCheez

    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. 

  • Unklegwar (unregistered) in reply to Anon
    Anonymous:

    Multi-Tear architecture.

     

    I love it!

  • gary (unregistered) in reply to Unklegwar

    this is one of the worst ever.

  • Dark (unregistered) in reply to themagni
    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.

     

  • (cs) in reply to ang
    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.
     

  • Jay Tee (unregistered)
    Alex Papadimoulis:
    $sql = "
      SELECT 
    CONCAT(
    '<a href=\"javascript:;\" onclick=\"window.open'
    + '(\'site_info.php?siteid='
    ,site_id
    ,'\',\'siteW',\'height=480,width=550,status=no,'
    + 'toolbar=no,menubar=no,location=no,scrollbars=yes,'
    + 'resizable=yes\');\" class=\"siteInfoLink\">'
    ,DATE_FORMAT(insp_date, '%c/%e/%Y')
    ,'</a>'
    ) AS `Inspection Date`
    ,insp_date AS `_realInspectionDate`
    So, I have an Inspection Date and a "real" inspection date.  Good thing there was a CONCAT to clear that up for me. 

Leave a comment on “Now That's A Neat Trick”

Log In or post as a guest

Replying to comment #93281:

« Return to Article