- 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
Note that actually trying to catch the exception can be problematic.
Admin
Where's the punchline? That Mr. Jay Smith has it in for this guy but completely fails to examplify it? The WTF here goes to Mr. Smith, not to the senior guy. What a laugh. :-D
Admin
I sincerely hope you had that nicely formatted and it got mangled when you submitted it, and this isn't actually your coding style. Apart from the missing } - which I presume goes at the end, it took me some minutes to work out what that last else was supposed to fit onto.
If you want to be concise, drop the else after return:
Otherwise, use that tab key, even if you're going to skimp on braces!
Admin
Ah, I forgot the "all compilers follow the (C) standard, and never have any bugs" camp. Please, please tell me you're not building medical devices or missiles that will make some error about !foe.
Maybe you've just been lucky, or are still in school, but there are some fairly stupid bugs in compilers sometimes. Use the #define's, or make ones yourself that are bulletproof. Don't assume that it follows the standard or you may end up explaining to the family how it's not really your fault the person died, it was the compiler that didn't follow the standard...see? Here's the quote from the standard! See!
Admin
If you have the need for very specific data structures (ie lists or whatever) its not incredibly hard to make them faster than the STL ones. Just that the STL stuff is guaranteed to work and cost a lot less developer time and is generally rather well known among people that know c++, so it incurs no extra time for learning a system for maintenance or whatever.
And unless its something that for some wierd reason has an absurd need for speed, then what little speed you will gain by writing it yourself will not be worth it. Maintainability first.
Admin
Fun with operators: !0 = 1 0! = 1 0 != 1 0 = !1
I think that's all of them. (1! unfortunately is not zero.)
Admin
I've seen it defined all sorts of ways. The best bet (IMHO) is to set one token (I suggest FALSE, or false if you must) to a value, say 0, then define the other token in terms of the negated first token, ie, TRUE = !FALSE. Then you are working with tokens not values for true and false. When people steadfastly assume they are values is when people get bit. (bad pun, sorry)
Admin
Legalize controlled statements (for er, uh, medical purposes...)!
Admin
Dammit, forgot to quote.
Legalize controlled statements (for er, uh, medical purposes)!
Admin
It's perfectly possible to write bad asm code that runs slower than "good" vb6 code.
Admin
Holy shiznit! I've never seen that many sandy vaginas since I went to Ibiza!
Admin
I have this terrible need to puree a Jicama root salad immediately. I can almost sense the VB6 Fear.
Yes, yes ... You're absolutely right. I need to talk to my friend, Mr Natural, right now.
Goddamnit, those lizards are exceptionally fast. I paid good money for that root. I need whiskey, and I need it now, and fuck the mojo wire.
I can see the Man down there, just by Seal Point ... He's always reliable. When I need "good" vb6 code, I need "good" vb6 code. The Man is always reliable. Best damn vb6 code in town ... or, for that matter, anywhere else.
Even here in a hellhole lash-up hotel at the western edge of the Civilised World, with the waves almost wiping out that goddamn Pit Chihauhua -- I told Juan he should've checked the dentistry first -- I can see this.
"Good" vb6 code is the way to go.
That, a quart of ether, some Ibogaine, a credit card with no limit, a very fast car, and the Fear.
Loathing can wait until later.
Admin
Admin
You do it by regular processes of testing, certification and verification. Measurable, repeatable, controlled scientific testing. Not superstitious garbage. If your compiler is so faulty that it can't do basic integer maths operations, AND YOU THINK YOU CAN MAKE IT ALL OK BY A COUPLE OF DEFINES, it is YOUR software that is going to kill people. And if your best plan is guessing rather than testing, that goes double
Admin
I had to read this sentence a couple of times before getting it, but now it makes more sense each time i read it.
Kudos for verbing wrong!
Admin
#define StringUtil_Compare(a,b) !strcmp(a,b)
Admin
How do these people get to boss around anyone, nevermind sensible people with brains?
If most of your code isn't application specific code then you're not using the right technology. Unless what you're making is in fact development tools including a compiler, a language, and a library to support it, it is nothing short of insanity to waste time and resources to recreate basic infrastructure code. It sounds like an ego trip on his own behalf, at the expense of shareholders, coworkers, customers - basically everyone but himself!
And spending the companys time, money, and human resources on an ego trip isn't what it means to be a professional.
Admin
that's the point of this daily WTF! :)
Admin
For the record, I have been programming away from school long enough to
(1) encounter two actual C compiler bugs (2) stop overengineering my code for platform bugs that exist only in my head (3) accept C as C, instead of trying to turn it into Pascal or Basic
Hopefully Greg will also someday reach the same skill level. For today's WTF coder, I have no such hopes.
Admin
STL is a massively broken hunk of crap, its cross platform support is a complete joke
Admin
StringUtil_Compare must be the dumbest name for that function imaginable, because it no longer compares the strings, it only tests if they're equal.
"perusing through" is an interesting expression. My dictionary says: peruse |pəˌruz| verb [ trans. ] formal read thoroughly or carefully : the pursed lips of an auditor perusing an unsatisfactory set of accounts.
So not only was it used in the 'wrong' meaning, the use of the preposition is also questionable at best. the author certainly was thinking along the lines of "skimming through". It's interesting how language develops along the weirdest paths.
Admin
No, seriously. Sure, I have encountered compilers with bugs, bugs that I had to program around. But I have never ever seen a C compiler with a bug as drastic as not returning 1 for !0, and where MAX_INT was defined as 0xFFFF too. Compilers with errors as bad as those don't survive for long. So, show me. I want evidence!
Admin
Well, I can understand not wanting to use Boost libraries. I have tried to use a few of them and turned away in absolute disgust. Even MFC is less user-hostile, especially when the Boost library in question uses more namespaces and who knows what else to carve things up for no apparent reason, forcing one to wear out the ':' key in no-time. Generic design and basic API are two terms most Boost libraries have never even considered apparently.
Yes, I did end up writing my own cross-platform library for my own needs. Sue me :P
As for using ASM where it isn't warranted, that's just bad practice. I also agree that using the STL is generally a good idea as it's easy to use, standard and easy to maintain. Premature and/or needless optimizations are still evil.
Admin
This guy doesn't fit my criteria for 'Competent and experienced'. In my experience, he sounds like a rookie with a talent for mashing code together. I expect he got the above function off the web somewhere. At the end of the day, commercial code has to go to a customer and then be maintained. And if a business does not understand that, they are sure to run into trouble. I would say that the bosses of this company don't really understand the processes of their own business - that is why this guy is allowed to continue to operate in this way. If they did understand just what he was doing (and then took action), then he would probably end up leaving to write lots of other 'clever' functions at another organisation where he was 'appreciated'. They probably see him as someone who is a 'doer' through his previous hacking efforts in the past. Without knowing that what in fact he is is basically a delinquent slinging code at their customers. Of course, when it comes to why the software can't be maintained in acceptable time scales, or why it doesn't scale etc then this guy will start blaming others. I expect he will then walk out on his colleagues siting 'stress'. So often these people can be left alone by others in the organisation who have seen them for what they really are - ticking bombs waiting to take the business and others down with them.
Admin
I haven't programmed FPU assembler since the DOS days, but doesn't the code of the comparison function have a serious bug, namely that it doesn't call fwait before the conditional jump?
I'm equally amazed that this crack programmer apparently couldn't figure out how to pop a value off the stack without writing it to memory.
Admin
Let's assume this isn't a troll.
Pick a platform, plus compiler. I'll write the fucking test program for you.
Admin
Every time I hear people talking about how nice a person Linus is, I look at his behaviour on technical mailing lists and snicker. Nice in comparison to whom? Idi Amin?
Admin
Only two? Hell, I had over a dozen in my first year out of school.
Admin
Admin
I thought that was !0==1
Admin
Yeah, But the Not Hot ones work harder horizontally.
Admin
Now we're talking politics?
Admin
He is a fairly nice guy. He also cares very greatly about programming and the functionality of code. I'd rather have someone tell me in rude ways that something I did was stupid than have them not care.
Though, some open source mailing lists are pretty much just epeen wagging and pissing contests. >.<
Admin
http://en.wikipedia.org/wiki/Standard_template_library Wonder why people call STL a library?
Admin
the real wtf is why the original coder isn't using strncmp.
Admin
You must be the one maintaining his code.
So when will you be moving up the chain and start writing new code. Maybe when you are able to show that you can do it and meet deadlines?
Admin
The real WTF is the writer of this story. He thinks the two pieces of code are interchangeable (because the target of this missive has a history of rewriting code).
Hello!! the function name and signatures are different so there is no way these two pieces of code are for the same use.
Admin
Admin
There's a difference?
Admin
Ok, that's just silly. Name a compiler that is still version 1.0 (not due standards changing). Can you name a compiler that has NEVER had a bug?
For the others that might read this, a classic was a Motorola C compiler for one of their DSP's where the pre-processor didn't recognize the literal '0'. Ie,
#define FALSE 0
Failed with FALSE being undefined. The work around for that version of the compiler was:
#define FALSE (1-1)
Any experienced software engineers care to explain why the expression is in ()'s? Maybe the kids still in school can learn something.
Admin
Still trying to weasel out of what you said, and pretend that you said something else. Just give it up.
Admin
Admin
#define six 1+5 #define nine 8+1 (...) printf("%d", six*nine);
where the result is 42. Does that answer your question?
Admin
The real issue with the assembler code, isn't that there may be a "bug" in the compiler, but that directly comparing two doubles is just a big no-no.
Anybody who writes mission critical real-time systems for aerospace or other industries that require number crunching would not do a direct comparison. And plus, if some sort of NaN or other code has crept into the calculation, that's the fault of the programmer and not the compiler.
It's far better to do something like
There's no need for error prone assembler, which is platform dependant. Your tool-chain would have to pretty fucking dire if it somehow messes up the above code.
Admin
In your case, it's more likely PEBKAC.
Admin
Admin
While I agree 100% with your sentiment, I disagree with your code. Your code is doing an absolute difference comparison, which is not very safe when using doubles. Sure, it can work well with a certain range of doubles, but CompareDouble(1e-10, 1e-50) will return EQUAL, but CompareDouble(100000000.000001, 100000000.000003) will return LESS. Probably not what most people would expect from a generic function.
A more generic way would be to do a relative difference compare and use a much tighter epsilon, such as 1e-10. It would more computationally expensive, but probably have fewer problems.
BTW, why 0.1e-6 and not 1e-7? Just curious.
Admin
Fundamentally it's not; the issue isn't with the comparison itself. The reason you do this isn't because the compare is broken, but because you know there is enough error in the numbers being compared that you want a deadband around them for purposes of comparison.
What's really fun is getting into discussions about how big the deadband needs to be.
Admin
The WTF I see is why the hell anyone wrote a damn wrapper function around strcmp() in the first place. You might as well write:
int sum_less_than(int left, int right, int sum) { return left + right < sum; }
It doesn't even simplify the code, because the function name isn't that clear, the function call will be longer than the resulting code, and the code itself is not even remotely confusing in the first place. :/
Admin