• urza9814 (unregistered) in reply to Nico

    Clearly this programmer does not understand how to use bits like this properly, therefore all they did was create a new problem. So they went from one problem to two...but they're doing it in binary now so they went from one problem to 10.

  • urza9814 (unregistered) in reply to Nico

    Ah crap I screwed up my quotes. Should have been:

    Nico:
    I don't get that... Shouldn't it be

    "You have two problems. You think "I know, I'll use bits." Now you have 10 problems."

    Clearly this programmer does not understand how to use bits like this properly, therefore all they did was create a new problem. So they went from one problem to two...but they're doing it in binary now so they went from one problem to 10.

  • Paul Neumann (unregistered) in reply to dtech
    dtech:
    That... or just:
    int size; // E.g. rules.size() or something
    for(int i=0;i<size;i++) {
        rules[i] = inputInt & (1 << (size-i));
    }
    </pre>
    

    (Parentheses added for clarity, not actually necessary)

    CodeAnalyses sees your unnecessary parentheses and throws a compiler error upon gated check in. :( I hate VS/TFS/CodeCop

  • (cs) in reply to Jaloopa
    Jaloopa:

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    Usually they think code is charged by the line, therefore for me to sit and write code that might not get used, or hasn't been budgeted for is a great expense, compared to me sitting in the office reading and posting on TheDailyWTF.

  • Jack (unregistered) in reply to Reggie
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
    I think you've just captured the thesis of this entire site.

    /comment /thread /article /tdwtf

  • Daniel (unregistered)

    And to make his live easier, he wrote a code generator that simply wrote this stuff out... without just using the code generators code in his function.

  • David (unregistered) in reply to Reggie

    Don't you mean 8 problems. Unless you are running this: http://en.wikipedia.org/wiki/Ferranti_Mercury

  • (cs) in reply to goom
    goom:
    Assuming that the endianess is required, I would do something like this:
    rules[0] = inputInt & 128;
    rules[1] = inputInt & 64;
    rules[2] = inputInt & 32;
    rules[3] = inputInt & 16;
    rules[4] = inputInt & 8;
    rules[5] = inputInt & 4;
    rules[6] = inputInt & 2;
    rules[7] = inputInt & 1;
    
    Close but it won't give you the output in 1 and 0 values.

    You could either use a ternary notation or a bit shift to fix that.

  • the guy with a name (unregistered)

    Wow. Just waste those 256 bytes and generate them into a static array first. It's still terrible tho'.

    var rules = rulesArray[inputInt];
    
  • (cs) in reply to dgvid
    dgvid:
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.
    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    A major factor in the rift between IBM and Microsoft over OS/2 was that IBM was pressuring Microsoft to write more lines of code. Bill Gates likened it to paying for a new aircraft design by the pound. Of course, that's still not any individual being paid by the line, but I assume that IBM's coders on OS/2 were being incentivized in some way to write more lines.

    That's probably true, but it doesn't explain why, ironically, Windows was the far more bloated product. I mean, I knew people who actually managed to run OS/2 on 4 MB machines-- but with Win 95, that was an absolute horror.

  • Ralph (unregistered) in reply to operagost
    operagost:
    on 4 MB machines-- but with Win 95, that was an absolute horror.
    Surely that was a typo, and you mean 4 GB, right?

    (My first computer had 8 KB. And we liked it.)

  • Long Version Please (unregistered)

    Can some one please post this code with the snipped lines ? Too lazy to do it myself, offcourse.

    FYI, I am being paid by lines of code, and am planning to copy paste this code. It will be my December bonus!

  • Matthew (unregistered) in reply to Snowrat

    I especially like the ski jumping snowman in the second line.

  • ¯\(°_o)/¯ I DUNNO LOL (unregistered)

    This is so awesome! They should add it to PHP!

    input_int_to_rules(input_int) - returns rules as an array
  • (cs)

    I guess that he wasn't "bit-wise"

  • some guy (unregistered) in reply to Rodnas

    Unless that was an intentional comical spelling, I think you'll find the word is poofters.

  • Santa (unregistered)

    whats most interesting is that someone actually had the knowledge to do binary conversion yet they did not had the sence to do it properly.

  • Sheldon Cooper (unregistered) in reply to noname
    noname:
    Well, that's impressive 2304 lines of code. One cent per line makes it $23.04. If he takes longer than half an hour he wasted his and his employers money.
    (a) If you're paid by the line, you should demand a little more than 1 cent per line (unless you're Nagesh). (b) He did waste his employer's money, no matter what.
  • RFoxmich (unregistered) in reply to TheSHEEEP

    TRWTF is it only handles a byte. Keep on going for 4,294,967,040 >more< cases for my 32 bit machine...and I don't even want to think about this for my 64 bit systems.

    Now the programmer who's savvy with bits would just write a program to write that code for an arbitrary number of bits right :-D

    TheSHEEEP:
    What... uh... oh god... *strange noise*

    I don't see the WTF here.

    I only see a vast green pasture with some happy animals on it. It seems very peaceful and looking at it comforts me and restores my inner balance.

  • Wyrm (unregistered) in reply to Reggie
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
    That's a good one. Too bad binary jokes only work when written.
  • Dazed (unregistered) in reply to dgvid
    dgvid:
    Jaloopa:
    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    A major factor in the rift between IBM and Microsoft over OS/2 was that IBM was pressuring Microsoft to write more lines of code. Bill Gates likened it to paying for a new aircraft design by the pound. Of course, that's still not any individual being paid by the line, but I assume that IBM's coders on OS/2 were being incentivized in some way to write more lines.

    I have read that some of IBM's code-quality tools included counts of entity X per 1000 lines of code and compared them to some arbitrary maximum. And the coders would then bulk the code up with silly lines to get it to pass the quality checks.

  • Alex (unregistered) in reply to David

    I'll say it...

    you've got 64 problems and a bit's every one.

  • Yet Another Steve (unregistered) in reply to pencilcase

    I've never been paid by the line, but a former COBOL shop I worked in (back when the Earth was still cooling) required the programmers (I was 1 of 3) to submit weekly status reports showing how many lines of code we produced per week/day/hour. If we dropped below a certain average, we had to justify where our time went.

    Or we just produced more lines.

  • (cs) in reply to Wyrm
    Wyrm:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
    That's a good one. Too bad binary jokes only work when written.

    Trying to read binary numbers as their decimal equivalent quickly runs into problems as the numbers get big.

    Here's how to count in binary:

    One, ten, eleven, one hundred, one hundred one, one hundred ten, one hundred eleven, one thousand...

    Reading hexadecimal numbers this way runs into the problem that 18 and 1A are homonyms (eighteen vs. "A"-teen). So I suggest reading them by reading the digits (one-eight, one-"A")

  • jay (unregistered) in reply to Jaloopa
    Jaloopa:
    Ron:
    Paid (or otherwise incentivized) by lines of code, I'll bet. This is why you have to reward what you want, not unrelated measures you think might get you closer to what you want.

    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    I once had a job where management discussed giving bonuses based on lines of code produced. I got my hopes up: I can easily think of dozens of ways to boost line count. Like, don't write "x=x+2", write "x=x+1" twice. Loops? Crazy idea. Make multiple copies of the code. Etc. Sadly, they dropped the idea.

    That said, there are plenty of companies out there that pay by the hour, and that's not a lot different.

    When I worked for the government, one project team was given an award, with a big ceremony and a high muck-a-muck presentating a plaque and all that, for producing the most paperwork. I don't mean that they fooled the higher-ups and all they ever really did was produce paperwork. I mean, the stated reason for them receiving the award, for which they were praised by the high officials, was that they had filled out more forms and produced more documents than any other project team. Oh, by the way, the actual software that they were supposed to produce? They never managed to implement most of the required functionality. They were supposed to support 20,000 users, but their system crashed whenever they got more than 7, and they were never able to get it to run with anything remotely resembling a realistic load. The project was eventually cancelled. But, hey, the filled out all the forms correctly.

  • jay (unregistered) in reply to dtech
    dtech:
    goom:
    Tronic:
    as far as code goes, I like the simple but readable version. var rules[]; for( int i = 0; i<8; i++){ rules=inputInt%(2^i); }
    That certainly works but as [i]daef pointed out the rules are big-endian while your loop puts them in little-endian order (or do I have it backwards?).

    Assuming that the endianess is required, I would do something like this:

    rules[0] = inputInt & 128;
    rules[1] = inputInt & 64;
    ...
    rules[7] = inputInt & 1;
    

    That... or just:

    int size; // E.g. rules.size() or something
    for(int i=0;i<size;i++) {
        rules[i] = inputInt & (1 << (size-i));
    }
    </pre>
    

    (Parentheses added for clarity, not actually necessary)

    I was thinking of the loop being i=0,j=1;j<255;++i,j*=2, but yeah, same idea.

    The difference between doing it with a 2- or 3-line loop rather than hundreds of lines of a big case statement is not just that the loop is easier to write, but more importantly that it is easier to verify. I can test the loop version with three or four cases and be confidant that it is correct. But with the "unrolled" version, how do I seriously verify that in all that typing or copy-paste editing, at some point I didn't make a mistake? I've seen exactly that in such code. Buried deep down inside somewhere, instead of saying "rule[0]=0; rule[1]=1;" it actually says "rule[0]=0; rule[0]=1;" and never sets rule[1], because someone made a typo.

  • urza9814 (unregistered) in reply to Ralph

    Uh, my Windows 98 box had only 64MB. And that was pretty decent at the time.

    I suspect you are talking about hard drive space. He meant primary memory. RAM.

    Of course even then, 4GB hard drive space would have been fairly large. Certainly more than the minimum for Win95, which I recall using on systems with only a gig of disk space. With 4GB I think you could even run XP (assuming you didn't plan on installing much else!)

  • (cs) in reply to Nonody
    Nonody:
    In fact you'll have 01100011 problems, but the bits aint one
    FTFY.
  • jay (unregistered)

    And in real life, the obvious follow on to this is that someone who's an even bigger idiot than the person who wrote the original code will say, Oh, there's a place where the value I pass in is the customer flags, but we just got a change request from the user that customer flag #4 should be treated as zero whenever flags 1, 2, and 3 are 1, 0, and 1 and the customer has account type W, so I'll just add this global that is true when the customer account type is W, and let's see, I think I'll call it "customer_account_type_w" ... no, that's too much to type, let's just call it "cw" ... and then inside case 13 I'll just add "if (cw) rule[4]=0 else rule[4]=1", and, yeah, that should take care of it.

    I have seen this scenario hundreds of times.

  • (cs) in reply to Reggie

    Generalized:

    You have n problems. You think "I know, I'll use bits." Now you have 2^n problems.

  • wiseass (unregistered) in reply to ParkinT

    Who said reinventing the wheel was a bad idea? If we would not have reinvented the wheel time and time again in the past, we would still have stone tires on our 'cars', would not be able to go faster than 10 mph, and would break said wheels after somewhere around 20 miles.

  • freealloc (unregistered)

    TRWTF is how bad all the solutions are in the comments also are. It's not hard, people. You don't need to overuse STL and definitely shouldn't hardcode the size of the output array.

    The closest was this one: rules[i] = inputInt & (1 << (size-i)); However, that will not set the lowest bit in each array element but bit being checked.

    Replace type with the desired data type.

    void toBitArray(type var, unsigned char* bitArray) { for( int i = 0; i < sizeof(type)*8; ++i) { bitArray[i] = (var >> i) & 1; } }

  • Jazz (unregistered) in reply to Foo Bar
    Foo Bar:
    EVERY possibility including sign, infinity and of course NaN
    You forgot File Not Found. Also, Poland.

    Dammit, I always forget Poland. What with it being all the way over in Europe, and all.

  • Jazz (unregistered) in reply to wiseass
    wiseass:
    Who said reinventing the wheel was a bad idea? If we would not have reinvented the wheel time and time again in the past, we would still have stone tires on our 'cars', would not be able to go faster than 10 mph, and would break said wheels after somewhere around 20 miles.

    And now you have discovered the difference between reinventing and merely iterating.

    (Captcha: erat - I smell erat!)

  • Brian (unregistered)

    Unless the person had a reason for doing so, it's not even semantically correct. The bits are in reverse order.

    Captcha: erat = Electronic Rat

  • Bob (unregistered) in reply to LoremIpsumDolorSitAmet
    LoremIpsumDolorSitAmet:
    Antti Nagesh:
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.
    This should be a featured comment!
    And now it won't be, you insensitive clod.
    I had a son who was a featured comment, you insensitive clod. And let me tell you it was no laughing matter.
  • anon (unregistered) in reply to WhiskeyJack
    WhiskeyJack:
    Jaloopa:
    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    In a recent project I worked on, we weren't being paid for lines of code but management was very, very interested in keeping metrics on them. We would frequently have to submit statistics (or they would be calculated from tools we used). How many lines of code did you produce this week? How long did it take your peers to code review? Therefore, how many LOC/minute do they review? How many bugs came out of this section of code? How many LOC/bug? How many LOC in your module? Compared to every other module? etc, etc, etc. It was kind of nuts, but at least it didn't really get in the way of the job itself.

    They were trying to quantify things like, given an average of X lines impacted per bug, and it takes Y hours to fix, therefore how many bugs can a developer fix per day, therefore we can schedule in Z bug fixes per week...

    Long ago in the 80s, managers at Apple thought they could measure developer progress with the metric of "lines of code per week." They stopped doing that when the smartest guys in the room had gangbuster progress while simultaneously reporting negative 2000 lines in a week.

    www.folklore.org/StoryView.py?story=Negative_2000_Lines_Of_Code.txt

  • anon (unregistered) in reply to WhiskeyJack
    WhiskeyJack:
    Jaloopa:
    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    In a recent project I worked on, we weren't being paid for lines of code but management was very, very interested in keeping metrics on them. We would frequently have to submit statistics (or they would be calculated from tools we used). How many lines of code did you produce this week? How long did it take your peers to code review? Therefore, how many LOC/minute do they review? How many bugs came out of this section of code? How many LOC/bug? How many LOC in your module? Compared to every other module? etc, etc, etc. It was kind of nuts, but at least it didn't really get in the way of the job itself.

    They were trying to quantify things like, given an average of X lines impacted per bug, and it takes Y hours to fix, therefore how many bugs can a developer fix per day, therefore we can schedule in Z bug fixes per week...

    Long ago in the 80s, managers at Apple thought they could measure developer progress with the metric of "lines of code per week." They stopped doing that when the smartest guys in the room had gangbuster progress while simultaneously reporting negative 2000 lines in a week.

    http://www.folklore.org/StoryView.py?story=Negative_2000_Lines_Of_Code.txt

  • (cs) in reply to Vortico
    Vortico:
    Generalized:

    You have n problems. You think "I know, I'll use bits." Now you have 2^n problems.

    Whoooosh.

  • Anonymouse (unregistered) in reply to Reggie

    Ya got masking problems? I feel bad for you son. I got 1100011 problems But a bit ain't one. ;)

  • Tom (unregistered) in reply to Jaloopa
    Jaloopa:
    Ok, seriously - has anybody ever actually known a job where people are paid by the line? It comes up every time a verbose piece of code is featured but I find it hard to believe that even the pointiest haired of bosses would think it's a good idea

    I did have a job once where productivity - though not directly pay - was measured by lines of code.

    Same job where I was asked to make the internet 100% reliable, when dial-up was the standard (yes, this was years ago). It was like living a Dilbert comic.

  • Jack 27 (unregistered) in reply to Tronic
    Tronic:
    as far as code goes, I like the simple but readable version. var rules[]; for( int i = 0; i<8; i++){ rules[i]=inputInt%(2^i); }

    The operator ^ doesn't really do exponents in javascript does it? It's a bitwise XOR in every language I know.

  • Spewin Coffee (unregistered) in reply to Reggie
    Reggie:
    You have a problem. You think "I know, I'll use bits." Now you have 10 problems.

    And Microsoft is the result.

  • Jim Rees (unregistered)

    I call bullshit on this one. No one is that stupid. If they were, they wouldn't be able to use a keyboard.

  • Code and then some (unregistered)

    I'm working at a company where my boss is now a principal engineer and running a team. He has a degree in software engineering, but doesn't understand number bases. But loves UML design. In a company doing embedded systems. Go figure.

  • Vizzie (unregistered) in reply to Reggie

    Don't you mean "I know, I'll use bitmasks." Now you have 11 problems.

  • foo2 (unregistered) in reply to some guy
    some guy:
    I think you'll find the word is poofters.

    Is that you Bruce?

  • Nagesh (unregistered) in reply to Kanitatlan
    Kanitatlan:
    But just wait until you see the code to translate the rules back into a value, I have. Its munitions grade bad code and hence health & safety forbids posting it.
    Okay, I'll bite. Could it possibly be anything but:
    var outputInt;
    if( rules[0] == 0 &&
        rules[1] == 0 &&
        rules[2] == 0 &&
        rules[3] == 0 &&
        rules[4] == 0 &&
        rules[5] == 0 &&
        rules[6] == 0 &&
        rules[7] == 0 ) 
      outputInt = 0;
    } else if( rules[0] == 0 &&
               rules[1] == 0 &&
               rules[2] == 0 &&
               rules[3] == 0 &&
               rules[4] == 0 &&
               rules[5] == 0 &&
               rules[6] == 0 &&
               rules[7] == 1 ) {
      outputInt = 1 ;
    } else if( rules[0] == 0 &&
               rules[1] == 0 &&
               rules[2] == 0 &&
               rules[3] == 0 &&
               rules[4] == 0 &&
               rules[5] == 0 &&
               rules[6] == 1 &&
               rules[7] == 0 ) {
      outputInt = 2;
    /* SNIP */
    } else if( rules[0] == 1 &&
               rules[1] == 1 &&
               rules[2] == 1 &&
               rules[3] == 1 &&
               rules[4] == 1 &&
               rules[5] == 1 &&
               rules[6] == 1 &&
               rules[7] == 1 ) {
      outputInt = 255;
    }
    
  • anon (unregistered)
    var outputInt;
    
    if( rules[0] == 0 ) {
      if ( rules[1] == 0 ) {
        if ( rules[2] == 0 ) {
          if ( rules[3] == 0 ) {
            if ( rules[4] == 0 ) {
              if ( rules[5] == 0 ) {
                if ( rules[6] == 0 ) {
                  if ( rules[7] == 0 ) outputInt = 0;
                  else outputInt = 1;
                } else {
                  if ( rules[7] == 0 ) outputInt = 2;
                  else outputInt = 3;
                }
              } else {
                if ( rules[6] == 0 ) {
                  if ( rules[7] == 0 ) outputInt = 4;
                  else outputInt = 5;
                } else {
                  if ( rules[7] == 0 ) outputInt = 6;
                  else outputInt = 7;
                }
    ...
  • David (unregistered) in reply to Reggie

    I see what you did there.

    There are 10 kinds of people in the world, those they get binary, and those that don't.

Leave a comment on “A Bit Misguided”

Log In or post as a guest

Replying to comment #:

« Return to Article