- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
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.
Admin
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.
Admin
Agreed.
Admin
Yeah. There once was the "rule" of "no bad student code" - those where the good old WTF days...
Admin
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.
Admin
The name 'Worse Than Failure' is the real WTF here.
Admin
"Worse that failure" is what's worse than failure.
Admin
char strDigit[1]; //store 1 digit //and don't worry about where the //goddamn string terminator ends up //getting written to
Admin
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?
Admin
Do we know which corporate entity that Alex sold the site out to forced the lame-ass name change?
Admin
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.
Admin
"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?
Admin
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)
Admin
Admin
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.
Admin
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!
Admin
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.
Admin
I think the student part of the story was an analogy. Kind of like 'there are three kinds of people in the world...'.
Admin
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?!
Admin
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.
Admin
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?
Admin
I hate it when stuff on WTF is essentially the same as stuff I've written.....
.... It's at least more efficient than what the other guy wrote...
Admin
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.
Admin
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
Admin
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.
Admin
er..um... You are aware that this code does the exact opposite of what the comment claims it does, right?
Admin
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.
Admin
Why write code when you can use XML the way it was intended?
Admin
Well because... umm... err....
....
This man makes an excellent point.
Admin
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.
Admin
Admin
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....
Admin
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.
Admin
//Should I crash or not?????
I'm putting this in all my code, in random locations, from now on.
Admin
Admin
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...
Admin
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!
Admin
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.
Admin
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.
Admin
According to Answers.com, alright is non-standard but their "Spelling & Usage" entry says that
all right: honest and honorable alright: satisfactory or correct
captcha: alarm (maybe yours shouldn't go off so easily)
Admin
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.
Admin
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
Admin
I don't think picking on students is fair.
Admin
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:
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.
Admin
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.
Admin
Admin
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
Admin
Admin
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.
Admin