- 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
I don't know this programming language.
Did the Senior Programmer invent it?
Admin
I wrote this comment, therefore it is good enough.
All of your comments will need to be rewritten.
Admin
If this is C or C++ (and I'm quite sure it is), comparing NaN does not throw exceptions, it simply returns false for any comparison; heck, C doesn't even know about exceptions.
Also, I doubt you need an assembler function for the rare cases where you need 3 way comparison without doing an if/else right behind anyway.
Admin
I used to work with a girl like that. She wrote every single thing she needed for any project. She would never read or write any documentation and her libraries had all kinds of quirks that made a nightmare to use them.
Example: 2 different functions that happened to return strings, one of them demanded that the string was pre-allocated by the caller but the other allocated the string itself so we would have to delete it later. And this was random, no valid reason was ever given.
She never delivered a project on time. Strangely the boss trusted her and always nominated her to lead all projects. And I can't see why, because she was so very NOT hot!
Admin
C++ says non-zero coerces to true while zero coerces to false. Strictly, the type of the expression in a controlled statement (if, while, etc) is bool in C++, int in C. I can't remember if C++ standardizes the result of (int)true, or whether it's left implementation-defined.
You may well find that your compiler does produce 1 in debug builds, but in optimized release builds, it may be some other value depending on the expression.
Anyway, don't do any mathematical expressions relying on the value of truth. You will get some unexpected answers.
Admin
Let's see..."If I didn't write it, then it must suck.", "If the project doesn't have my code in it, then it must suck.", and "We have to get this project done RIGHT NOW." I may have worked with people like that before...
Admin
C (at least) does say the !0 is 1, in section 6.5.3.3 of the standard, paragraph 5:
But of course you're right to say that using the numerical value of truth in arithmetic is not nice.
Admin
Admin
[quote user="mxxIf this is C or C++ (and I'm quite sure it is), comparing NaN does not throw exceptions, it simply returns false for any comparison; heck, C doesn't even know about exceptions.
Also, I doubt you need an assembler function for the rare cases where you need 3 way comparison without doing an if/else right behind anyway.[/quote]
It's C++
Admin
My apologies for the confusion, this was written a few weeks ago and I didn't check back to see if it was up.
These are two different examples. I guess that could have been made more clear. One for double comparisons one for string comparisons.
The WTF being rewriting code that is unnecessary and slower than what the average bear would do. The double check is roughly 10 times slower than letting the compiler optimize a standard if else if else check.
This is what happens when good programmers go unchecked.
Admin
Admin
Fucomi, is it only me or does it really sound like a Japanese developer trying to swear in English.
Admin
Which adds to the WTFery. 1) The compiler can't optimize this function because it's already been written in stone--er, ASM. 2) The function performs 2 memory loads and then a store. If you've seen the NS-EEL library for Winamp's visualizers, you would recognize this kind of "generic function" programming. It is several times slower than what an optimizing compiler would produce using knowledge of context and machine tricks. 3) Wanna bet this function is called in a tight loop? 4) Why even mess with AH? There are ASM conditional jump instructions that can already do everything he wanted to do, without that AH test. So if that's the function as it really is, then it's not only slow, it's wrong. If there is a missing LAHF, then the function is even slower than it should be.
Admin
Errr what?? Unless you use a totally broken compiler / STL implementation, STL (or SC++L as it's called now) is the way to go.
Admin
First! All of your comments have been superseded. captcha: venio, how appropriate!
Admin
Turn in your programmers guild card immediately.
Admin
Admin
I second that. Try and write something faster than the STL libraries - I'll stick with the highly optimised, better-than-anything-I-can-dream-of-writing, library code :)
Admin
The only justification for the StringUtil_Compare function that I can fathom is the old "fortify your subsystems" strategy that Steve McGuire espoused in "Writing Solid Code." You can guard yourself against any bugs in the libraries, you can add counters if you want to look for memory leaks, etc.
However, that's usually done using #DEBUG directives, and the release versions generally call the libraries directly.
Plus if he's the sort to throw hissy fits, then it's more an ego thing, not a coding-practices thing.
Admin
Pictures or it didn't happen! There are no girls in IT. ;)
Admin
Admin
http://thread.gmane.org/gmane.comp.version-control.git/57643/focus=57918
Sorry, I just had to post this link :)
Admin
Yes, the ! operator is doing a boolean evaluation of the integer that it was passed, so 0 becomes true (1) and any other number becomes false (0). This is a nice legacy of C not having a actual boolean type.
Yes, just using the actual equality operator is much clearer to me as well.
Compiled with:
Results in:
Admin
I can believe that "senior programmer" == Linus Torvalds here. He's full of it.
Admin
I don't know about that. That approach leaves cruft in code base. Why not just delete the function and fix all places where code doesn't compile if you are worried about missing something?
Admin
(!0)! = 1! = 1 !(0!) = !1 = 0
Admin
Wow, is he talking about software or is he trying to make a profound philosophical comment?
Admin
http://xkcd.com/322/
Admin
For God's sake, will you all stop saying that !0 = 1. Everybody knows that it is. The poster questioning it was suffering from pre-coffee coffee deprivation and admitted so. So that's it, OK? You don't have to keep repeating that !0 = 1 in hopes that it makes you look knowledgable.
There, look what you made me do. I said it twice. Happy now?
Admin
Can we rewrite the comments the same way?
Admin
The code doesn't have an FUCOMI in it, though. It has an FCOMIP, which compares the top two registers on the stack, then pops both and throws a floating point exception if either is NaN. It also pushes onto the stack twice (the two FLD instructions), but pops three times (two in the FCOMIP instruction, and again in the superfluous FSTP, which both stores a value when none was calculated, and stores it into an automatic variable that will go away as soon as the function returns. Also, I think this does not calculate a three-way compare correctly, since the superfluous AND AH,20h instruction will overwrite the flags before the JNZ instruction.
Admin
Actually, although it depends on the compiler, usually
!0 != 1
Most often, !0 is defined as MAX_INT (or something similar), so for a 16 bit system:
!0 == 0xFFFF
Much better to use the compiler defined TRUE and FALSE, or define your own as #define FALSE 0, and #define TRUE !FALSE and let the compiler decide what ! means and do the same thing every time.
Admin
WOW! This reminds me of that one XKCD about Little Billy Tables. OMG has anyone else seen that?!? LOLOLOLOLOL!
Admin
So he is basically a knight who says NIH. And we all know how to fight them: with the word IT.
So tell him next time: "Ok, but we here in IT use standard functions."
Admin
bool = !!var
to force the value to be exactly 0 or 1? I have.
Admin
Great! Thread closed... we are all done here and ready for the next one on monday.
Admin
Not enough people these days do. The reason I say this is that sometime someday people will be looking for a faster way. Those proficient enough with assembly will be able to tell you. That doesn't mean I'm encouraging assembly, because if you're going to write C code, you should stick to C unless for constraints you're in embedded systems and the only way to do something is assembly. However, if I gave you two functions, both one line of code, somebody with knowledge of assembly would be able to look at the generated instructions and give me a rough answer on which one will perform better and why.
Admin
Like base 5000?
Admin
Whatever happened to:
if(someDouble <insert condition here> otherDouble) { }?
Assembler or not, without some serious context that could possibly justify it, that function is ridiculous. Aside from the fact that it will actively defeat any attempts of the compiler to inline and optimize the compare, what's the point? You still now have to compare the result of the function against 3 possible return values!
And WTF is up with "and ah, 20h?"
Yea, definitely...WTF.
Admin
; ; PWC - PRINT ; WITTY ; COMMENT ; ; E: - ; A: - ; ; ;
PWC:
CALL UP ; OS CALL!
DEFM '#WITTY COMMENT STARTS' ; # = PRINT TEXT ; TEXT = WITTY COMMENT DEFB 13 DEFB 10
NOP ; END WITH 0
CALL UP DEFM '#PAY PER LOC RULEZ' DEFB 13 ; CR DEFB 10 ; LF NOP
RET ; JUMP BACK
Admin
(You may be thinking of Microsoft Visual Basic, which does indeed define True as 0xFFFF, but is not in fact a C compiler.)
Admin
For the people wondering how a function that compares doubles has anything to do with a function that compares strings...
Now, my ASM is a little rusty, but it looks to me like he's taking the pointer values to the strings as doubles. In other words, the new function is taking RAM addresses as parameters (in a very annoying manner). It's then comparing the values stored at those two RAM locations and comparing them.
It also looks like some stuff might have been cut out during anonymizing.
So, it probably works (for sufficiently small values of "work"), but I doubt that it works reliably.
Admin
No. Just no. Go read the C standard for the ! operator (and all of the relational operators), and sin no more.
Admin
numerical values of truth...
Back on the Commodore 64, I used to write expressions like:
CL = (-20 * (INT(I/4) = I/4)) + (-20 * (INT((I+2)/4) = (I+2)/4)) + (-40 * (INT(I/2) = I/2))
(might not be exactly correct, but the intent is to distribute items over four columns, exploting 'true' being -1, and 'false' being 0)
Admin
Admin
"Libraries like STL?" I've never heard a bunch of headers called a library before ... except, obviously, by Stepanov.
What next? Re-implement libc.so.6? It's obviously in dire need of re-implementation. How hard could it be to do so in self-modifying MML assembler so that it copes with calls to libc.so.5, libc.so.4, etc ... and then just add a back-end to the assembly language of choice?
Admin
Admin
I believe OS2 also used that schema for TRUE.
I thought it was evil when I first saw it, but then came to realize it's beauty. It lets you use bitwise operators intermingled with binary values, and have it be correct for that bit.
That said, in all my projects, !0 = 1, and 1 = false;
Admin
Admin