- 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
Dan was refering to the sig in the post two above his, where Brillant is spelled Brilliant.
Admin
var_dump(false == NULL) // bool(true)... sh*t!
Admin
Not true either, depending on the language.
Of course you could break apart calculations, etc. But I don't see how that would help in this case. Comments could be also useful, but that is not _code_.
Let me know, when you've become one of those ... experienced coders I mean.
l.
Admin
Going Postal starts off serious, but the last third will have you in splits. Not as funny as the initial few books, but still good.
Admin
yup. shoulda been:
function invert_bool($val)
{
if($val === true) { return false;}
if($val === false){ return true; }
return $val;
}
Admin
The $ prefix for variables is certainly not meaningless. I have no problem with people pointing out valid issue's they have with the language, it's by no means perfect, but at least have the courtesy of actually knowing what you're talking about before you label part of a language as stupid.
Admin
If this guy was writing the same code for C/C++ he would get a compiler error "Not all control paths return a value" or something similar.
Instead he could have written:
function invert_bool( $val ){
if( $val == true )
return false;
return true;
}
-Mike
Admin
There are two zeroes in floating-point land. -0 and +0 are equal, but if you divide one by them, you get two different results.
1.0/-0.0; -> -Infinity
1.0/+0.0; -> Infinity
Well, this works as above in the JavaScript Console under Firefox. Some languages consider dividing by zero to actually be an error. Funny that.
Anyway, this is good for amusing your mathematically inclined friends. Just ask them to find two floating-point numbers a and b that satisfy:
(1) a == b
(2) 1/a != 1/b
It's a real WTF for people who think floats work like reals in math.
Admin
So you need experience to forget about boolean algebra.... that's interesting. I always knew there was something wrong with doing things the shortest way possible.
Admin
You are correct.
But not today.
As you subtly implied, you see yourself as an experienced coder. You should know then, that as far as coding practices go, there are no absolutes. You can be right sometimes, rarely, or most of the time. But this case is extremely simple and doesn't qualify as a "coding practice".
The function is a pure wrapper around the ! operator. It does nothing extra. Hence there are no situations where it is actually useful.
Admin
Then he should have used the Win32 character map util and copied each "!" :P
Admin
Or even neater:
function invert_bool($val) {
return !(bool)$val;
}
Admin
Speaking of not liking exclamation points, I often wish that modern languages had the "until (condition)" statement, defined as "while (!condition)".
instead of
or
instead of
Admin
Nice.. If I git this, you want:
until($arg==false){}
vs
while($arg==true){}
Since you've started a wish list, I'd like to see ( in crude syntax ):
skip(these){}
vs
for(each){}
Admin
Ruby does. It also has an "unless" statement which is (as you'd have guessed) the opposite of "if", and condition-inversion for one liners (taken from perl):
Which are respectively equivalent to
Admin
Ruby is quirky. o_O
I hope it doesn't go the same route as PHP what with all the 'added features' and 'handy tools'. PHP is virtually 1-dimensional and the string functions reference page is a couple screens long for just the functions.
I mean, at some point, a language is complete, and you can build your features yourself.
But I suppose, a to-die-for feature native to a language is probably better than what I can come up with. :)
Admin
Not that quirky in fact (and much of the quirkiness I found in it seems to come from perl, I don't like the reverse condition for example and it comes straights from perl). One thing it pushes forward, though, is the sheer english pronunciation of the code: try reading the 2 forms out loud, you'll realize that post-condition is an exact translation of usual natural language constructs.
Well, given the fact that Ruby has no function and hates built-in functions (i'm not sure there is any built-in functon in Ruby apart from basic IO things like puts, and even them are methods of a global "base" object) it won't.
The ruby guys don't even use loops anyway (if/unless tests are another matter), the ruby-way is to use iterators and "blocks" (FP-inherited constructs functions as first-class objects with read/write closure over their context)
I still prefer Python atm, but Ruby's cool and very straightforward (Ruby's mostly follows the PoLS, the Principle of Least Surprise, and it's syntax is geared towards this goal).
Admin
omgplz! the return_bool function gotta look like this: function return_bool($val) { return invert_bool(invert_bool($val)); }
everything else would be plain wrong
Admin
As you say. There are two zeroes in floating-point land.
Thus if:
a is -0
b is +0
and
-0 and +0 are equal.
and if
1.0/a; -> -Infinity
1.0/b; -> Infinity
then the challenge to satisfy both
(1) a == b
(2) 1/a != 1/b
suggests that zero is not stable, but has tendencies. funny how that works.
Admin
at least they could have used else if or at least just else. This is a good one though... lol.
Admin
Read the code to a friend over the phone and have him type it down.... If the types it right the first time its good code.
"CAPTCHA Validation Incorrect".... :P
Admin
Precisely. The real wtf is the post itself! Lol.. or maybe it was a "trick" post? ;-)
Admin
Surely, someone should have simply settled for: