- 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
#define HEX(frist) 0xfrist // "SIMPLIFY FIRST POST"
Admin
Admin
It's simple enough to understand: each time you invoke the visibility toggle, add another negation to the comment in the source code. Easy!
Admin
/*
/**
Admin
Clearly, $two = -funk; what's the problem?
Admin
Isn't the MutableBoolean just a way to make the boolean (value) type into a reference type ("box" it, in .NET terms)? Because values types are passed by uh... value, you can't change the original value, so it appears "constant".
Not that this is already covered by the java.lang.Boolean class or anything...
Admin
The MutableBoolean should be obvious for anyone familiar with the java wrapper classes. java.lang.Boolean is not Mutable so MutableBoolean is a good name for boolean wrapper with a public non final value field
Admin
It should be illegal and be subject to third party claims to claim copyright on public domain works.
Admin
the IsNotOkay parameter isn't as redundant as you might think. If the final destination of these properties is to be bound to a view (in XAML), it's much simpler to have two properties like this than to have to write a converter to invert the value.
Admin
TRWTF is that he should have written assignment operater overide methods for MutableBoolean.
Admin
It's appalling that Oracle provides "Hello World" as-in and without any warranty whatsoever. Shame on them! ;-)
Admin
Admin
I think I might kinda have maybe reverse engineered Oracle's code into a different language without even knowing it.
Have I broken some copyright law there?
Admin
The code is worse than the comments today. That doesn't happen very often.
Admin
Admin
And fucking of course the red-headed step child nobody loves or wants, akismet...
Admin
You would be interested in this site: techdirt.com.
Admin
"While taking a stroll through the code on a new project, I came across a fantabulous override of ToString," Jay writes, "I guess you never know when this will be null."
It turns out it is possible, though not in C# but still...
http://stackoverflow.com/questions/3143498/why-check-this-null
So my guess is author of "this == null" may be former MS employee...
Admin
Or more generally (for objects):
If you are really lazy you can use an array of size 1 instead. This is necessary due to Java's lack of pass by reference, as every primitive is pass by value, and every object is pass by value of reference.
Admin
Admin
Yep. That's Oracle.
Admin
Not that I am agreeing with this style or anything, but:
Admin
I've heard of Heinlein's Razor :)
Admin
Admin
They're the same thing. "Hanlon's Razor" is argued by some to be a corruption of the name "Heinlein's Razor".
But of course you know all this because you googled it.
Admin
Maybe the function:
public function addfunk($one, $two) { $val = $one - $two; return $val; }
is wrapped in a validation that requires parameter $one to be positive and $two to be negative? Which would still make it addition via double negatives? Probably a long shot but has a tiny chance of still being valid :)
Admin
It would also be useful if you want more than one class instance to share the same boolean (or any other primitive). It's not uncommon to do that in C++ where you would be able to store a pointer to a primitive in your class, and check it to see if someone, somewhere changed it. It could have been changed by any class and would not have gone through any of your object's code. You don't have pointers in (safe) C# and java, hence the "MutableBoolean" class which basically acts as a pointer. The only WTF here is that this is basically intentionally bypassing the safety features of your compiler.
Admin
This is like boolean math.
Let's see:
= "not non-uninvisible"
= "not" * "non-" * "un" * "in" * visible
= false * false * false * false * visible
Note 1: false * false = true
= true * true * visible
Note 2: true * true = true
= true * visible
= visible
It makes the dialog visible.
Admin
Admin
Admin
Admin
should work for all types except for typeof(Wife), which is never Mutable :)
Admin
I think MutableBoolean is useful and have had to use it at some point. Code snipper:
[code] final MutableBoolean a = new MutableBoolean(false);
Callback<xxx> callback = new Callback<xxx>() { public void onSuccess(xxx val) { if(a.value) { // do something } else { // do something else a.value = true; } } };
// Make two async calls that end up eventually calling callback.onSuccess. Note that this was written in GWT, so no concurrency issues.
Admin
Admin
This comment is not non-uninteligible.
Admin
Even though I've never used Java I immediately understood what was going on. It's not a WTF unless it's duplicating library functionality.
This allows pass-by-reference instead of pass-by-value.
Sharing it with a delegate, perhaps?
Admin
private boolean isLoggingEnabled() { return MAX_NUMBER_ATTACHMENTS != -1; }
I may need to get this on a t-shirt...
Admin
Funny use for the word "corrected" though. :)
Admin
Admin
So, naturally, there had to be two popular writers who said roughly the same thing who also happened to have similar names.
captcha: eros. Time Enough for Eros?
Admin
Always the same fuss over "this" being null. Keep in mind that "this" is merely syntactic sugar for another parameter implicitly passed to a function.
In C one might write
void class_A__method(object* this,int a,int b,int c) { class_A__othermethod(this,a,b,c); class_A__thirdmethod(a,b,c); }
whereas in C++ you might write
class A { void method(a,b,c); void othermethod(a,b,c); static void thirdmethod(a,b,c); }
void A::method(a,b,c) { this->othermethod(a,b,c); thirdmethod(a,b,c); }
It's all the same. Just because "this" is passed implicitly (and sometimes unnecessarily!) in object oriented programming, that doesn't mean it's always defined!
Normally in a class you'd define functions that don't require the object pointer as static methods. However, in some cases it's useful that a method can be called both with or without object pointer.
A bit exotic, no doubt. But there are perfectly legitimate uses for "this" being null.
Admin
Mutable variables are what are used when mime-encoding algorithms.
Then you put the code into an non-uninvisible box.
Then you dump the programmer into the scorpion pit.
--Joe
Admin
Admin
Admin
Invalid point. As MutableBoolean uses keyword "boolean" instead of "bool" we already know it can't be C#, probably it's Java code already.
Admin
The best usecase of using a MutableBoolean is when a method needs to return more than one value. E.g.
Admin
Admin
Admin
That Oracle header is a BSD license.
http://www.opensource.org/licenses/BSD-3-Clause
Admin
Yes, something like MutableBoolean allows you to bypass Java's pass-by-value paradigm, which arguably could be a tacit admission of a defect in Java. But it could also be used to "promote" a primitive to an Object, thus allowing it to be used in contexts where otherwise it would not be allowed. I think there's good reason for a primitive vs object distinction, but yes, it does create this extra complexity at times.
Here's a rather obvious example of where a MutableBoolean would be useful:
Yes, you could use a Boolean instead and create a new Boolean every time the value changes. But that's a lot of extra object creation and destruction, and it takes a few more lines of code to do. So this solution means fewer lines of code (equals easier to maintain) plus faster run time. Win/win.
I routinely create MutableIntegers for just this purpose. Then I can write
instead of
The first method can be read and understood in an instant. The second requires at least a few extra seconds of thought, and someone reading it quickly is more easily confused. (And yes, we could cram it all into one line of code and eliminate the temporary variables, like:
I guess it's debatable if that is better or worse.)
Okay, a couple of seconds isn't a lot. But when you have programs filled with unnecessary complexities, each of which takes an extra couple of seconds of your time to figure out, it adds up.
captcha: sino. I tried sqrt(1-cos2o), but for some reason it didn't accept that.