• Jakob H. Poulsen (unregistered)

    Holy hell, this really did make me go "WTF?!"

  • Procedural (unregistered) in reply to Mike
    Mike:
    I stopped reading halfway down. If I had a job that involved this code, my next words would be "I quit".

    Ah, the generic throwaway comment; how appreciated.

    Two things:

    1. Hmmm, no you wouldn't; I'm sure it sounds great to say it at the brewery with the boys (or muttering on the sofa at night in front of the telly), but in reality, no you wouldn't.

    2. If you did you wouldn't be worth employing anyway; this code needs refactoring. Do you not consider refactoring part of your job ? Do you only take jobs to fix and improve code that is already good ? Perhaps you can't reengineer your way out of a few lines of code ? What good are you to a project then ?

    I propose that we relabel all the "I'd quit" posters that pollute every single darn story as incompetent and lazy prima donnas. Take up gardening or something.

  • rwb (unregistered)

    for anyone wondering wtf all that binary shite is, my guess is someone in management wanted a html grid of check boxes to click turning products on and off (as well as some product features?). A the db architecture was probably never designed properly so they had to shoehorn some kludge into hold lots of meta data into it.

  • (cs) in reply to Aaron
    Aaron:
    May have been? How about a fixed-point decimal column? Or even two integer columns (one 64-bit and one 32-bit)?

    Also, there's no such product as "MSSQL". Or "Orace" for that matter.

    Splitting data into multiple columns can be a more egregious mistake than packing it into a single column using a horrible format.

    If you type MSSQL into google, the top of the list is a Microsoft SQL Server home page. And if you can't spot the Oracle typo for what it is then there is not help for you.

  • procedural (unregistered) in reply to Procedural
    Procedural:
    Mike:
    I stopped reading halfway down. If I had a job that involved this code, my next words would be "I quit".

    Ah, the generic throwaway comment; how appreciated.

    Two things:

    1. Hmmm, no you wouldn't; I'm sure it sounds great to say it at the brewery with the boys (or muttering on the sofa at night in front of the telly), but in reality, no you wouldn't.

    2. If you did you wouldn't be worth employing anyway; this code needs refactoring. Do you not consider refactoring part of your job ? Do you only take jobs to fix and improve code that is already good ? Perhaps you can't reengineer your way out of a few lines of code ? What good are you to a project then ?

    I propose that we relabel all the "I'd quit" posters that pollute every single darn story as incompetent and lazy prima donnas. Take up gardening or something.

    Nah, they'd stop at the first bit of weed, take out their lace umbrellas, and declare in operatic tones: "Blasphemy ! This garden has weeds ! I quit !". So, no go for gardening. You need something that doesn't require any effort.

  • greg (unregistered)

    And yes. Everything is better when its a string

    $isnul=='T'
    ...
    $isnul=='F'
    ...
    if($isnul=='T') {}
    ...
    
  • Spuds (unregistered) in reply to Dilbert

    Maybe not limited. It's certainly still widely in use for a reason other than people just don't know how to get out of using it (which happens a lot, as we all know COUGHCOBOL**COUGH) but you can't say it's not perverted.

  • David Hamilton (unregistered) in reply to David Hamilton
    David Hamilton:
    Just because you can do it that way doesn't mean that you should.
    Actually, a quick glance at the code shows the data is clearly structured into a number of groups of pairs of data:
    77-81 and 01-14
    15-20 and 21-24
    43-45 and 46
    47-49 and 50-51
    52-53 and 54-55
    56-57 and 58-59
    plus 25-41 used in the query
    In other words: That data could (and should) have been broken up into several data columns to make it supportable.
  • Craig (unregistered)

    What's a "redcated" table name?

  • BSDPwns (unregistered)

    This code is OVER 9000!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    Captcha: facilisi, Facist Pasta

  • NoAstronomer (unregistered)

    Oh come on! This isn't a WTF. It's definitely an OMFG.

  • (cs)

    It's obvious that the original code used "." and "*", replaced by "0" and "1" during the entry anonymization process.

    At least I assume that's why several of the former maintainers were found missing with only one quote left behind: “oh my God—it's full of stars!”.

  • (cs) in reply to @Deprecated
    @Deprecated:
    - DON'T LOOK AT THE CODE, MARION! - It's beeeyooootiful!
    ¡Supercow al rescate!
  • NOrgTheFat (unregistered)

    DAAAH!!! It burns! My eyes! Wow, and I thought VisualFoxPro was bad.

  • (cs)
    My Little Pony:
    what's binary?
    unary++
  • (cs) in reply to rwb
    rwb:
    [...] wanted a html grid of check boxes to click turning products on and off [...]
    Yes sir! A form with 96 checkbox fields! Add XML and you have another WTF!
  • (A different) Mike (unregistered) in reply to Procedural
    Procedural:
    Mike:
    I stopped reading halfway down. If I had a job that involved this code, my next words would be "I quit".

    Ah, the generic throwaway comment; how appreciated.

    Two things:

    1. Hmmm, no you wouldn't; I'm sure it sounds great to say it at the brewery with the boys (or muttering on the sofa at night in front of the telly), but in reality, no you wouldn't.

    2. If you did you wouldn't be worth employing anyway; this code needs refactoring. Do you not consider refactoring part of your job ? Do you only take jobs to fix and improve code that is already good ? Perhaps you can't reengineer your way out of a few lines of code ? What good are you to a project then ?

    I propose that we relabel all the "I'd quit" posters that pollute every single darn story as incompetent and lazy prima donnas. Take up gardening or something.

    At least the original poster only wasted 2 seconds of our lives with his comment. That's a lot less time than I wasted reading your overwrought and totally unnecessary over-analysis of it. Just something for you to consider next time you're thinking of rebutting a useless comment with a considerably longer useless comment.

  • Thick as Pig Sh*t (unregistered)

    Apparently back in the distant past they used 0 and 1's to represent data. These days of course we use bytes as they are much more understandable.

  • Nick (unregistered)

    Oh it's PHP... what a surprise. Years ago every newbie was producing similar "gems" in VB... now it's PHP

  • DeepThought (unregistered)

    Wow, this is truly a WTF!

    Jani and Alex, thanks for sharing this marvelously grotesque masterpiece.

  • (cs)

    I would so love to hear this post done by Hear a blog. That would be some awesome listening!

  • (cs) in reply to student
    student:
    The only thing I could think of while reading this was that I had already solved this problem. Store the damn value as an integer and just do a quick conversion. (I use it to determine admin privileges).
    Doesn't that make it difficult to run queries against? If the business really has that many flags on an object, then it is only sensible to slap them all in the database in seperate bit columns. I would only convert to an int for sanity in the code.
  • procedural (unregistered) in reply to (A different) Mike
    (A different) Mike:
    Procedural:
    Mike:
    I stopped reading halfway down. If I had a job that involved this code, my next words would be "I quit".

    Ah, the generic throwaway comment; how appreciated.

    Two things:

    1. Hmmm, no you wouldn't; I'm sure it sounds great to say it at the brewery with the boys (or muttering on the sofa at night in front of the telly), but in reality, no you wouldn't.

    2. If you did you wouldn't be worth employing anyway; this code needs refactoring. Do you not consider refactoring part of your job ? Do you only take jobs to fix and improve code that is already good ? Perhaps you can't reengineer your way out of a few lines of code ? What good are you to a project then ?

    I propose that we relabel all the "I'd quit" posters that pollute every single darn story as incompetent and lazy prima donnas. Take up gardening or something.

    At least the original poster only wasted 2 seconds of our lives with his comment. That's a lot less time than I wasted reading your overwrought and totally unnecessary over-analysis of it. Just something for you to consider next time you're thinking of rebutting a useless comment with a considerably longer useless comment.

    Nah, definitely the same Mike. Go back to work.

  • (cs) in reply to Nick
    Nick:
    Oh it's PHP... what a surprise. Years ago every newbie was producing similar "gems" in VB... now it's PHP

    You can write good code in a shitty language and shitty code in a great language. I've seen my share of WTF in my beloved Python. Don't blame the tools.

  • Chris Lightfoot (unregistered)
              if($i!=21 and $i!=22 and $i!=23 and $i!=24 and 
    	     $i!=46 and $i!=50 and $i!=51 and $i!=54 and 
    	     $i!=55 and $i!=58 and $i!=59 && 
    	     !in_array($i, array(1,2,3,4,5,6,7,8,9,10,11,12,13,14)))
    

    TRWTF is all those $i != conditions and then a further check against the array!

    It also looks like there's a huge if/else with similar code in both conditions; maybe they're the same... There's too much code bother comparing ;-D

  • anon (unregistered) in reply to Aaron
    Aaron:

    Also, there's no such product as "MSSQL". Or "Orace" for that matter.

    Oh yes there is - 'Orace at least: http://myspeccy.com/en/games/horace-goes-skiing

  • (cs) in reply to OzPeter
    OzPeter:
    The sample strings are 82 bits long. I did a cursory search on google and I can't see any popular DB (MSSQL, MySQL or Orace) that supports 96 bit integers. So storing the result in a varchar column isn't totally in the realms of stupidity. The alternatives would have been to split the value up into multiple columns, which then creates the issue of trying to ensure that the columns are assembled in the correct order when you are doing a query.

    Of course I bet that there may have been another way to encode the information so you didn't have to jump through all of these hoops.

    Well, one should at least put hex code on that varchar, to simplify reading, and reduce storage space. But that wouldn't simplify the code... For that, one'd need to use a big integer class/type/whatever, instead of the regex nonsense. Or better yet, why the hell does it need that amount of booleans? (Those are booleans, aren't they?)

    highphilosopher:
    You can write some pretty elegant code in PHP. The real problem is that it has such a low learning curve that almost any idiot with a keyboard can write code in PHP.

    Well, if you are talking about PHP5, you have a point. Earlier versions were so bad, that I doubt they could be put to good use. Bad languages atract bad coders, and those don't simply go away when you improve it, but keep compatibility.

  • anon (unregistered) in reply to Craig
    Craig:
    What's a "redcated" table name?

    ZZzzzz...

  • Some Wonk (unregistered) in reply to KittyKat
    KittyKat:
    It was horrible ones and zeros everywhere and I think I saw a two
    That's OK, Bender. There's no such thing as 2.
  • Peter (unregistered) in reply to Patryk Zawadzki
    Patryk Zawadzki:
    You can write good code in a shitty language and shitty code in a great language. I've seen my share of WTF in my beloved Python. Don't blame the tools.
    ...unless you're referring to the tools who wrote the code.
  • decoder (unregistered)

    if code works... that guy is a genius ;-)

  • NetTears (unregistered)

    TRWTF is that this code is covered by an NDA. You will be hearing from our lawyers.

  • Anonymous (unregistered) in reply to Aaron
    Or "Orace" for that matter.

    Me uncle 'Orace ain't gonna like bein' tol' 'e don't 'zist.

  • Loren Pechtel (unregistered)

    I've seen one real-world scenario that does something approximating justifying concatenated strings in a varchar (at least I assume it was a varchar underneath, I didn't actually look.) This was an ERP system meant to be field configurable to whatever was wanted. The actual handling of the product IDs was a very long string that contained all the information to describe any given item. Items for which the strings matched were identical, if they didn't match they weren't.

    The reason the strings made some sense is that as you progressed down the expansion from the ordered product to all the bits that made it up you didn't need the same fields at each point. This made trying to build sensible database fields hard--the program needed to generically manipulate data whose structure changed. Thus each type of item had it's own mapping instructions that could extract fields from the string.

    While it would be unlikely to contain a block of booleans it's the same basic concept.

  • (cs) in reply to OzPeter
    OzPeter:
    The sample strings are 82 bits long. I did a cursory search on google and I can't see any popular DB (MSSQL, MySQL or Orace) that supports 96 bit integers. So storing the result in a varchar column isn't totally in the realms of stupidity. The alternatives would have been to split the value up into multiple columns, which then creates the issue of trying to ensure that the columns are assembled in the correct order when you are doing a query.

    Of course I bet that there may have been another way to encode the information so you didn't have to jump through all of these hoops.

    In Microsoft SQL Server, if you make 82 columns with the bit datatype, it will store them packed into 11 bytes.

  • illtiz (unregistered) in reply to NetTears
    NetTears:
    TRWTF is that this code is covered by an NDA. You will be hearing from our lawyers.
    Wow. Alex signed an NDA with you guys?
  • tristique (unregistered) in reply to jjs
    jjs:
    Zylon:
    <comment redcated>
    <reply redacted>
    <defense of original poster's comment redacted>
  • eubv (unregistered)

    well, embedded systems don't have filesystems so they cannot store anything besides 0s and 1s

  • (cs)

    Man, I love when articles make me feel like a good programmer. It's great for the self-esteem to be able to look at something and say "Man, I've done some dumb shit in my time, but holy hell I've never done anything THAT bad."

  • Buddy (unregistered) in reply to m a t t
    m a t t:
    student:
    The only thing I could think of while reading this was that I had already solved this problem. Store the damn value as an integer and just do a quick conversion. (I use it to determine admin privileges).
    Doesn't that make it difficult to run queries against? If the business really has that many flags on an object, then it is only sensible to slap them all in the database in seperate bit columns. I would only convert to an int for sanity in the code.

    Looking at the code snippet, it appears as though most of the values are zero. I'd look at saving only "1" values in a redesigned schema. For example, only a few columns with the identifier of the "1" field as one of them.

    E.g.

    ID A B C D E F G H I J K L M N
    ------------------------------
    23 0 1 0 0 1 0 0 0 0 0 0 1 0 0

    Becomes:

    ID FLAG
    -------
    23 B
    23 E
    23 L

    A few methods to abstract out, and then a chunk of business logic where all the ugly dependencies can go. If the dependencies are linked logically, say like components of an assembly, then those can be represented in the DB too.

    I've seen lots of code like this, the cause is usually a rushed developer against tight deadlines. The end result is the evolution of a logical temporary hack into a monster.

  • Jay (unregistered) in reply to (A different) Mike
    (A different) Mike:
    Procedural:
    Mike:
    I stopped reading halfway down. If I had a job that involved this code, my next words would be "I quit".

    Ah, the generic throwaway comment; how appreciated.

    Two things:

    1. Hmmm, no you wouldn't; I'm sure it sounds great to say it at the brewery with the boys (or muttering on the sofa at night in front of the telly), but in reality, no you wouldn't.

    2. If you did you wouldn't be worth employing anyway; this code needs refactoring. Do you not consider refactoring part of your job ? Do you only take jobs to fix and improve code that is already good ? Perhaps you can't reengineer your way out of a few lines of code ? What good are you to a project then ?

    I propose that we relabel all the "I'd quit" posters that pollute every single darn story as incompetent and lazy prima donnas. Take up gardening or something.

    At least the original poster only wasted 2 seconds of our lives with his comment. That's a lot less time than I wasted reading your overwrought and totally unnecessary over-analysis of it. Just something for you to consider next time you're thinking of rebutting a useless comment with a considerably longer useless comment.
    Ouch, burned. But for the record I agree, can't bitch about useless comments when you're making one yourself.

  • Buddy (unregistered) in reply to decoder
    decoder:
    if code works... that guy is a genius ;-)

    If he can debug it, he's a super genius!

    Brian W. Kernighan:
    Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
  • Tomatoman (unregistered)

    At least this code fragment is self-explanatory. The code is so well-structured that any comments would be superfluous.

  • Halo (unregistered) in reply to OzPeter
    OzPeter:
    The sample strings are 82 bits long. I did a cursory search on google and I can't see any popular DB (MSSQL, MySQL or Orace) that supports 96 bit integers. So storing the result in a varchar column isn't totally in the realms of stupidity. The alternatives would have been to split the value up into multiple columns, which then creates the issue of trying to ensure that the columns are assembled in the correct order when you are doing a query.

    Of course I bet that there may have been another way to encode the information so you didn't have to jump through all of these hoops.

    Microsoft SQL Server supports the BIT data type which can represent either 0 or 1. These are stored internally within the table as bitmasks so that up to 8 of these columns will occupy only a single byte for as many of the columns as you want. In this case it would mean 82 different columns but it would also mean that querying individual values are very simple. Also, technically the BIT data type can be treated as a ternary type as it can be NULLable, with NULL being tracked within the bitmask in the row header.

    Also, all of these DBs generally support NUMERIC(x) or DECIMAL(x) for integral values larger than any specific bit-ness. NUMERIC(25) would be sufficient to hold a bitmask of 82 values, assuming the client application can work with such values. However, in those cases it probably would be better to use multiple 32-bit or 64-bit integral fields and to handle them as separate bitmasks. You'd need to understand the order of the values within the bitmasks anyway so no real additional burden is involved with splitting it across multiple bitmask values.

  • RBoy (unregistered)

    Egads... I could just imagine TopCod3r's justification for this...

    It's enough to make Mara cry.

  • RBoy (unregistered) in reply to procedural
    procedural:
    (A different) Mike:
    Procedural:
    Mike:
    I stopped reading halfway down. If I had a job that involved this code, my next words would be "I quit".

    Ah, the generic throwaway comment; how appreciated.

    Two things:

    1. Hmmm, no you wouldn't; I'm sure it sounds great to say it at the brewery with the boys (or muttering on the sofa at night in front of the telly), but in reality, no you wouldn't.

    2. If you did you wouldn't be worth employing anyway; this code needs refactoring. Do you not consider refactoring part of your job ? Do you only take jobs to fix and improve code that is already good ? Perhaps you can't reengineer your way out of a few lines of code ? What good are you to a project then ?

    I propose that we relabel all the "I'd quit" posters that pollute every single darn story as incompetent and lazy prima donnas. Take up gardening or something.

    At least the original poster only wasted 2 seconds of our lives with his comment. That's a lot less time than I wasted reading your overwrought and totally unnecessary over-analysis of it. Just something for you to consider next time you're thinking of rebutting a useless comment with a considerably longer useless comment.

    Nah, definitely the same Mike. Go back to work.

    I doubt it, as I think you are quite the twit as well.

    Of course, only a prima donna would think that there's only one person in the world who doesn't agree with you.

  • Airhead (unregistered) in reply to highphilosopher
    highphilosopher:
    You can write some pretty elegant code in PHP. The real problem is that it has such a low learning curve that almost any idiot with a keyboard can write code in PHP.
    You mean, like, me?
  • Bender (unregistered) in reply to mike5

    I think I saw a 2...

  • (cs) in reply to Craig
    Craig:
    What's a "redcated" table name?

    Google: Did you mean: redacted Top 2 results shown

  • Gus Catalano (unregistered)

    Something inside of me died after reading this.

Leave a comment on “1's and 0's”

Log In or post as a guest

Replying to comment #:

« Return to Article