• dp.design (unregistered)

    As a student, I was definitely responsible for much worse crap than this. I don't think it's fair to pick on learner's mistakes.

  • KattMan (cs)

    Yeah not fair, I made much worse assumptions while learning. Now if the student was contracting himself out for a profit, he's free game.

  • Malfist (unregistered) in reply to KattMan
    KattMan:
    Yeah not fair, I made much worse assumptions while learning. Now if the student was contracting himself out for a profit, he's free game.

    Agreed.

  • AC (unregistered) in reply to KattMan
    KattMan:
    Yeah not fair, I made much worse assumptions while learning. Now if the student was contracting himself out for a profit, he's free game.

    Yeah. There once was the "rule" of "no bad student code" - those where the good old WTF days...

  • TSK (unregistered)

    It is the typical code of people which don't know the internal representation of data types and bit manipulation. They think that strings and numbers are totally different in the computer and there is no way that someone can use operators on both datatypes. A "bit" is a magical entity, it is like saying that a man consists of "atoms"; like bits I don't see it, it seems to be irrelevant for programming and I don't understand it, but the teacher said it so, so it must be true.

    So they think out complicated roundabouts, converting like mad from numbers to strings and back and do pointless 1:1 comparisons. But still some of them can be cured if they are willing to delve in.

    The problem with the code: little- and big-endian architecture.

  • Joe Blow (unregistered)

    The name 'Worse Than Failure' is the real WTF here.

  • Edss (unregistered)

    "Worse that failure" is what's worse than failure.

  • dave (unregistered)

    char strDigit[1]; //store 1 digit //and don't worry about where the //goddamn string terminator ends up //getting written to

  • ElectroDruid (cs)

    Same as the other guys have said, I don't understand why student work has suddenly become "fair game". We were all beginners once. Is this site running out of decent submissions or something?

  • Joe Blow (unregistered)

    Do we know which corporate entity that Alex sold the site out to forced the lame-ass name change?

  • Hit (unregistered)

    Ah, you gotta love also how he converts the freaking string into a char array and then using strcmp. Of course, if this is a class teaching C++, he shouldn't even know about that method, as str == "foo" surely seems a lot easier to use to me. That's more like a sub-wtf though, since last I checked C++ (like C) can read hex strings and turn them into numbers.

  • headshit (unregistered)

    "It wasn't pretty and it certainly wasn't efficient, but it worked. And that, folks, is worse that failure."

    Stop trying to shoehorn in the New! Improved! and Fantastic! name of the site. Seriously, what the fuck?

  • Cable (cs)

    students are poor bastards. they suck at coding, try to reinvent the wheel (over and over) and then someone comes and blames them for learning. i think i can feel sympathy for this paar student, on my opinion the grader is the one that chose teaching the same crap over and over again (in many cases was the teaching capability of many of my teacher worse than my crappy codingskills and at least i learned how to code, they never learned to teach)

  • Ornedan (unregistered) in reply to dp.design
    dp.design:
    As a student, I was definitely responsible for much worse crap than this. I don't think it's fair to pick on learner's mistakes.
    Considering it's the Software Engineering project, it is fair to pick on the mistakes. You're not supposed to be learning to code by then anymore, that's what the previous labworks and courses were for.
  • Hit (unregistered) in reply to Hit
    Hit:
    Ah, you gotta love also how he converts the freaking string into a char array and then using strcmp. Of course, if this is a class teaching C++, he shouldn't even know about that method, as *str == "foo" ([i]fixed[i]) surely seems a lot easier to use to me. That's more like a sub-wtf though, since last I checked C++ (like C) can read hex strings and turn them into numbers.

    Actually, this is a SE course, isn't it. So the WTF extends even further than the course, into where this student supposedly learned C++. c_str() should only be used for one purpose: to call C code that takes char* pointers. Any other use, (especially the abomination here) is abuse and/or misunderstanding of the language.

  • Chambers (unregistered)

    Horrible code is horrible code, and this is it.

    There is one simple solution for all of you complaining about recent submissions: Send in your own!

  • Mcoder (cs)

    Well, there is the problem of not caring about where the string terminator will go, thus making any non trivial code that uses this function fail on a completely unrelated way - that is funny to do. There is also the ifs, lots of them, when he should have used a switch, and using strings where he should be using chars. Tipical student code.

    But I fail to see a problem with the use of 'pow' (except for it being sligtly slow) and portability (there is no problem of architecture endianess here, there would be if he didn't used 'pow'), unless you want to port it to a different color coding.

  • antonrojo (cs) in reply to ElectroDruid
    ElectroDruid:
    Same as the other guys have said, I don't understand why student work has suddenly become "fair game". We were all beginners once. Is this site running out of decent submissions or something?

    I think the student part of the story was an analogy. Kind of like 'there are three kinds of people in the world...'.

  • Akerbos (unregistered) in reply to Cable

    Students are made to reinvent wheels all the time. I suppose it's for understanding them so we can use them later, in whatever shape or color they roll towards us. Or command somebody to use them. SE is not about coding, it's about managing coders. But then, an software engineer should be capable of coding to some level. Poor job done there.

    Alarm?!

  • KattMan (cs) in reply to Ornedan
    Ornedan:
    dp.design:
    As a student, I was definitely responsible for much worse crap than this. I don't think it's fair to pick on learner's mistakes.
    Considering it's the Software Engineering project, it is fair to pick on the mistakes. You're not supposed to be learning to code by then anymore, that's what the previous labworks and courses were for.

    The point is, he is still a student, no practical world experience, coursework in a lab does NOT replace this.

    Of course if this was a guy that was in the field for a while then went back for a degree then this is an atrocious habit that should have been caught a long time ago. We don't have that information and can only assume he is still without that experience.

    We all know that the work you do in these courses is far from a true review. Most of the time it is a works/don't work aspect to getting a grade. I will commend the instructor here on actually reviewing the code, now instead of posting it here and laughing, try teaching the class why this is bad.

  • snoofle (cs) in reply to dp.design

    Worse Than Failure!? I think not!

    This student might have been practicing for the OMGWTF programming contest. I mean honestly, how many of us could turn: sscanf(hexString,"%x",&someUnsignedInt); into about 50 lines of code using multiple calls to a power-function?

  • vt_mruhlin (cs)

    I hate it when stuff on WTF is essentially the same as stuff I've written.....

    //------------------------------------------------------------
    //Hex2Bin: Converts a string of hex digits to chars.
    //         i.e. "01F6" becomes {0x01,0xF6}
    char* UC_Crypt::Hex2Bin(const char* pHex, unsigned int nSize){
         unsigned int nOutSize = (nSize+(nSize%2))/2 + 1;
         char* pBin = (char*)malloc(nOutSize);
         memset(pBin, '\0', nOutSize);
         
         for(unsigned int i=0; i< nSize; i+=2){
              pBin[i/2] = Hex2Char(pHex[i])*16 + Hex2Char(pHex[i+1]);
         }
         
         return pBin;
    }
    
    //-------------------------------------------------------------
    //Hex2Char: converts hex to a decimal. i.e. 0x0A becomes 'A'
    char UC_Crypt::Hex2Char(char nHex){
         switch(nHex){
              case '0': return 0;
              case '1': return 1;
              case '2': return 2;
              case '3': return 3;
              case '4': return 4;
              case '5': return 5;
              case '6': return 6;
              case '7': return 7;
              case '8': return 8;
              case '9': return 9;
              case 'a':
              case 'A': return 10;
              case 'b':
              case 'B': return 11;
              case 'c':
              case 'C': return 12;
              case 'd':
              case 'D': return 13;
              case 'e':
              case 'E': return 14;
              case 'f':
              case 'F': return 15;
         }
         
         return 0;
    }
    

    .... It's at least more efficient than what the other guy wrote...

  • JamesCurran (cs)

    I think you are missing the bigger picture here. The method signature shows that this is C++ code --- except the author quickly strips it of all C++-ness, and writes the function using strictly C library functions.

    IOW, the author is actively refusing to use the very features the course is supposed to be teaching him.

  • antonrojo (cs) in reply to vt_mruhlin

    The WTF coder is not a student based on "I can only imagine that Ken would have been in this latter group"

    Anyone else have this problem? Neither the 'Subscribe to article' nor the user icons are showing up in Firefox 2.0.0.3

    //too lazy to use IETab

  • dkf (unregistered) in reply to snoofle
    snoofle:
    Worse Than Failure!? I think not!

    This student might have been practicing for the OMGWTF programming contest. I mean honestly, how many of us could turn: sscanf(hexString,"%x",&someUnsignedInt); into about 50 lines of code using multiple calls to a power-function?

    Indeed, the whole problem is really just a one-liner (which might need a little more work to add more C++ goodness, as I'm a C programmer):

       if (sscanf(hexString, "%2x%2x%2x%2x", &r,&g,&b,&a) < 4) a = DEF_ALPHA;

    Now, I'd not expect a student to know such things, but come on you pros! No excuses for not knowing such things! This is exactly what sscanf is good at.

  • JamesCurran (cs) in reply to vt_mruhlin
    vt_mruhlin:
    //Hex2Char: converts hex to a decimal. i.e. 0x0A becomes 'A'
    

    er..um... You are aware that this code does the exact opposite of what the comment claims it does, right?

  • Zylon (cs)

    What the fuck. WHAT the fuck. WHAT THE fuck. WHAT THE FUCK. FUCK FUCK FUCK FUCKITY FUCK-FUCK.

    Sorry, had to get that nasty "worse than failure" taste out of my mouth.

  • Bob the builder (unregistered)
    <color red="255" green="127" blue="0"/>

    Why write code when you can use XML the way it was intended?

  • The MAZZTer (cs) in reply to Bob the builder
    Bob the builder:
    <color red="255" green="127" blue="0"/>

    Why write code when you can use XML the way it was intended?

    Well because... umm... err....

    ....

    This man makes an excellent point.

  • duuuuuude (unregistered)

    Wow. This site has seriously gone downhill. I feel truly bad for the poor guy if he ever comes to this place and sees his beginner mistakes (which we all have made, face it) being paraded all over the place like that.

    You guys should seriously rethink your policies.

  • AdamTheBuilder (unregistered) in reply to Bob the builder
    XML:
    <color red="255" green="127" blue="0"/>

    Why write code when you can use XML the way it was intended?

    Because this is shorter:

    <color hex="FF7F00"/>
    That's a 46% increase in storage efficiency!
  • mrprogguy (cs)
    Most of the students were actually alright programmers;

    Whatever the hell that means. "All right" is two words, not one. Does anyone do copy editing anymore?

    And, while I'm here, it's "no one," not "noone." "Noone" (first name, Peter) was the lead singer for Herman's Hermits in the 60's.

    You'd think as anal as this lot gets about coding, they'd be anal about spelling as well (communication is communication is communication), but nooooo....

  • ssp (unregistered)

    To me this code looks like it was written by a smart person who had never written C++ in his life before.

    His task is to convert a hex string to an integer, and he knows he can do that by multiplying each digit with its corresponding power. However, knowing no C++ he doesn't know about sscanf() and doesn't know how to extract the the first character from a string. He does know about strcmp() though.

    If this is indeed someones first attempt at C/C++, frankly, I think he did a decent job.

  • Lastchance (cs)

    //Should I crash or not?????

    I'm putting this in all my code, in random locations, from now on.

  • cognac (unregistered) in reply to vt_mruhlin
    vt_mruhlin:
    I hate it when stuff on WTF is essentially the same as stuff I've written.....
    //------------------------------------------------------------
    //Hex2Bin: Converts a string of hex digits to chars.
    //         i.e. "01F6" becomes {0x01,0xF6}
    char* UC_Crypt::Hex2Bin(const char* pHex, unsigned int nSize){
         unsigned int nOutSize = (nSize+(nSize%2))/2 + 1;
         char* pBin = (char*)malloc(nOutSize);
         memset(pBin, '\0', nOutSize);
    
     for(unsigned int i=0; i< nSize; i+=2){
          pBin[i/2] = Hex2Char(pHex[i])*16 + Hex2Char(pHex[i+1]);
     }
     
     return pBin;
    

    }

    //------------------------------------------------------------- //Hex2Char: converts hex to a decimal. i.e. 0x0A becomes 'A' char UC_Crypt::Hex2Char(char nHex){ switch(nHex){ case '0': return 0; case '1': return 1; case '2': return 2; case '3': return 3; case '4': return 4; case '5': return 5; case '6': return 6; case '7': return 7; case '8': return 8; case '9': return 9; case 'a': case 'A': return 10; case 'b': case 'B': return 11; case 'c': case 'C': return 12; case 'd': case 'D': return 13; case 'e': case 'E': return 14; case 'f': case 'F': return 15; }

     return 0;
    

    }

    .... It's at least more efficient than what the other guy wrote...

    If that switch is supposed to be c or c++, it features a nice bug. ;)
  • jman (unregistered) in reply to dp.design

    Wow, has this site really slipped. First the lame-ass name change. Now we're reverting to student code?

    It's no wonder I rarely visit anymore...

  • Gazzonyx (unregistered) in reply to Hit
    Hit:
    Hit:
    Ah, you gotta love also how he converts the freaking string into a char array and then using strcmp. Of course, if this is a class teaching C++, he shouldn't even know about that method, as *str == "foo" ([i]fixed[i]) surely seems a lot easier to use to me. That's more like a sub-wtf though, since last I checked C++ (like C) can read hex strings and turn them into numbers.

    Actually, this is a SE course, isn't it. So the WTF extends even further than the course, into where this student supposedly learned C++. c_str() should only be used for one purpose: to call C code that takes char* pointers. Any other use, (especially the abomination here) is abuse and/or misunderstanding of the language.

    I call bull on this! I use it to open files all the time. You can't open a file in C++ without converting a string to a char*. At least not in the standard libraries, and not that I'm aware of; if someone else knows differently, please let me know! It's been bugging me for quite some time, now!

  • Arancaytar (cs)

    It reminds me of the PHP script I just cleaned up.

    I wanted to strangle the one who wrote it, but it's kind of tough to do that. Self-preservation kicks in.

    Also, I eventually forgave myself for it. That was a year ago, I didn't know much of PHP back then.

  • David (unregistered)

    Software Engineering courses should be fair game. The course is usually a culmination of four to five years of study in computer science & programming. The next week that "student" could be writing production code for some company.

    Flaws like project management and inadequate testing and even overall design shouldn't be considered because they're taught IN the course. Anything regarding code (which they should have learned freshmen, sophomore, or junior year) is fair game. Put it up here and let us giggle a bit and remember all the silly code we wrote back then. Chances are (if they become or are currently a good programmer) they'll think the exact same thing, laugh it off, and go back to code.

    Would you consider that computer-genius nephew of-the-CEO programmer (who has no formal training whatsoever) a student? What about someone who has no knowledge of the language they’re using (such as C-Pound). They're still clearly learning. Why do they not get the no-student benefits? The fact that they hired them in the first place is one thing, but throwing up code written by someone like that would violate the "no student" philosophy.

  • Book Worm (unregistered) in reply to mrprogguy
    Comment held for moderation.
  • Morgan (unregistered) in reply to mrprogguy
    mrprogguy:
    Most of the students were actually alright programmers;

    Whatever the hell that means. "All right" is two words, not one. Does anyone do copy editing anymore?

    And, while I'm here, it's "no one," not "noone." "Noone" (first name, Peter) was the lead singer for Herman's Hermits in the 60's.

    You'd think as anal as this lot gets about coding, they'd be anal about spelling as well (communication is communication is communication), but nooooo....

    al·right Pronunciation[awl-rahyt] –adverb all right.

    —Usage note The form alright as a one-word spelling of the phrase all right in all of its senses probably arose by analogy with such words as already and altogether. Although alright is a common spelling in written dialogue and in other types of informal writing, all right is used in more formal, edited writing.

    I remember getting this wrong on a 4th grade spelling test where I wrote "all right" and the teacher said "alright" was the correct spelling. "All right" may be more formal, but I'd say "alright" is the more common usage these days by far.

  • seejay (cs) in reply to David
    David:
    Software Engineering courses should be fair game. The course is usually a culmination of four to five years of study in computer science & programming.

    My Software Engineering course was a fourth year course when I was in university.

    We did no coding in it whatsoever. Talk about annoying and disappointing. :(

    Seejay

  • Grauenwolf (cs)

    I don't think picking on students is fair.

  • slamb (unregistered)

    Wow, that's a nice WTF.

    I had to walk myself through the floating point use in the pow() line to convince myself it does actually work for all numbers. I was initially suspicious because on 64-bit platforms, sizeof(int) exceeds the size of the fraction of a double value. But then I realized the obvious - in 16^n, the fraction is always 0, so those bits aren't needed anyway. And the conversion to int happens right after the call to pow (before the multiplication or addition). So, yeah, it works.

    The portability bug is probably this:

       int power = intHexLength - 1;
       char strDigit[1];
    

    then writing two characters (including NUL) to strDigit. Depending on the direction the stack grows in memory, that could:

    • zero a byte of unused stack area harmlessly, unless ** the compiler puts extra temporary values on the stack, a byte of which would be zeroed incorrectly ** or a system call/interrupt starts using the stack right there rather than keeping a "red zone". the zero would turn into something else and strcmp would incorrecty return false, yielding a digit of 0)

    • or overwrite one byte of "power" (either the LSB or MSB depending on endianness). If it zeroes the LSB, the answer will be wrong.

  • Welbog (cs)

    To you guys saying that soft eng students should be fair game: in my university, there's only one required course called "Software Engineering", and it's a second-year, first-term course. Not all universities are the same.

  • A. N. Consultant :p (unregistered)
    //Should I crash or not?????
    • I laughed so hard I left a bit of pee under my desk :p
  • android (unregistered) in reply to ssp
    ssp:
    However, knowing no C++ he doesn't know about sscanf()...

    If this is indeed someones first attempt at C/C++, frankly, I think he did a decent job.

    Well at least he knows enough about C++ (well actually C) to know that scanf is the wrong way to do this. Still, nobody has managed to stumble across the right C library function to convert a hex string to an unsigned numeric value.

    That's why they're lousy students and will be lousy programmers. Because you're supposed to know that if you've written 20 lines of code to do some common, repetitive task like converting a hex string into a number that there will be a library function for it. Sure, it might not be called ConvertHexStringIntoAnInteger() but it will be there and you should be smart enough to find it.

    strtol(), Look it up, people.

    CAPTCHA: Burned, like I get when I see code like this and how the employers will be when they hire these clowned

  • Skybert (cs) in reply to cognac
    cognac:
    vt_mruhlin:
    //-------------------------------------------------------------
    //Hex2Char: converts hex to a decimal. i.e. 0x0A becomes 'A'
    char UC_Crypt::Hex2Char(char nHex){
         switch(nHex){
              case '0': return 0;
              case '1': return 1;
    ...
              case 'F': return 15;
         }
         return 0;
    }
    
    ....
    If that switch is supposed to be c or c++, it features a nice bug. ;)
    Looks ok, works ok. What's the bug? (I don't count missing default or misleading method-name as bugs).
  • gentian (cs)

    I posted that Daily WTF (remember that?) Jumped the Shark with the soft coding thing a couple of weeks ago. If it hadn't for me, this might have done it.

    As others have said, it's a student. The key difference is that s/he is not being paid to write this code, they are paying (the University) to get the chance to learn from their mistakes.

    And code that is horrible and inefficient is not "Worse Than Failure." Now I could go for What The F..., but not Worse than Failure.

  • Asgeir (unregistered) in reply to Skybert
    Skybert:
    cognac:
    vt_mruhlin:
    //-------------------------------------------------------------
    //Hex2Char: converts hex to a decimal. i.e. 0x0A becomes 'A'
    char UC_Crypt::Hex2Char(char nHex){
         switch(nHex){
              case '0': return 0;
              case '1': return 1;
    ...
              case 'F': return 15;
         }
         return 0;
    }
    
    ....
    If that switch is supposed to be c or c++, it features a nice bug. ;)
    Looks ok, works ok. What's the bug? (I don't count missing default or misleading method-name as bugs).
    If you pass any ascii value other than from the (0..9, a..f, A..F) set into it, it will return zero.

Leave a comment on “That'll Show the Grader”

Log In or post as a guest

Replying to comment #:

« Return to Article