- 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
They have to do that all the time because Java doesn't have proper verbs.
Admin
OK, real first post from me then.
The nice thing here is the self-proclaimed WTF. Self-criticism is good thing, I'm starting to look at my old code immediately to try to qualify.
Admin
I don't see the WTF. The purpose seems to be to add "rules" to an object, maybe for some kind of form validation check. Uses "addrule" to... well, add a rule to any item that needs it, then "checkrules" and it checks them all, warning about any errors.
Admin
Oh, the lengths some of us go through to go down in the anals of WFT History! It makes me smile.
Note: do not reply and tell me I misspelled "annals".
Admin
Admin
TRWTF(tm) is that it's "their", not "there". And that's coming from non-native speaker.
Admin
lol, whut?
Admin
The real WTF is that Ben did not include more of the code context in the article. Of course this looks like a WTF alone.
Admin
Enjoy your mug
Admin
You mean that native speakers will never make this mistake? Hmmm... somehow I doubt that...
Admin
Yup, as I said yesterday, the editors on this site are a real WTF. Unfortunately, my post was deleted by those same editors and they just corrected their awful grammar.
Admin
Admin
If the only point of this code fragment was to check whether a single instance of a variable was null or not then, yes, it'd be a WTF.
Unfortunately, that's not what's shown here. It's perfectly obvious that this is an abstract rule that would be combined with other rules (of varying types) that would be validated at some future point.
For those with ASP.NET experience, think about the various different Validation controls that get invoked when required - it's exactly the same pattern.
The real WTF is that this (non-)WTFy article was posted as the CodeSOD. Pathetic.
Admin
Of course it's coming from a non-native speaker. You actually learned the rules of the language. Native speakers speaking their own language well, especially english? That's the real WTF!!
(I feel dirty)
Admin
This is actually a pretty neat system. Presumably the Rule interface defines the check() method, and the rule checker would then loop through all the Rules added, and execute the check method on each. Nice and simple. The code given is merely an example of how to set up a rule to check for an object not being null. But this system allows for any check, not just this trivial example.
So, not a WTF at all, but actually very clever.
Admin
TWTF is that "o" (and, therefore, whether or not o==null – we're not checking a mutable field here, and last time I checked Java doesn't let you overload "==") is set when the Rule is constructed. So, unless there's some reason you might want to later decide not to ever check() the rules, why bother with all the enterprisiness?
Still, respect to Ben for turning himself in.
Admin
Someone whose website I read used to think that Spanish spelling was easy – until he saw a sign written by a native speaker with about one misspelling for every three words.
TRWTF is that my spell-checker didn't know the word "website" until I right-clicked it and clicked "Learn Spelling".
Admin
Admin
At that point shouldn't you be using a rules engine? instead of trying to roll your own?
Admin
Are you talking about the line: "That code is still there"?
Because it should be 'there' and not 'their'. Otherwise, to WTH are you refering?
Admin
"...will go to 'enterprise up' there Java apps..."
"there" above should be "their". can't believe you didn't see that :)
Admin
It's so much worse when you notice that your mind is going...
Admin
The real WTF is that you did not provide a IRuleFactory that can initialize rules from a simple configuration file such as
<ValidationRules type="Initech.Practices.Enterprisey.Validation.ValidationRules, Initech.Practices.Enterprisey.Validation.dll, Version=1.1.2.3, PublicKeyToken=1e9a2c36f"> <addRule type="Initech.Practices.Enterprisey.Validation.NotNullRule,, Initech.Practices.Enterprisey.Validation.dll, Version=1.3.2.4, PublicKeyToken=1e9a2c36f" objName="myObject" objectRetriever="Initech.Practices.Enterprisey.ObjectRepository.NullableObjectRetriever, , Initech.Practices.Enterprisey.ObjectRepository.dll, Version=1.6.2.3, PublicKeyToken=1e9a2c36f" />Admin
Your first language doesn't happen to be German, does it? Also, you forgot the word "a".
Admin
Huh, didn't realize they had dll's in java
Admin
TRWTF(tm) is that it's "English", not "english". And that's coming from a non-native speaker.
Admin
Ok this has screwed me many times, How come there is a "Reply" and a "Quote" Next to every comment?
Why not do this: Remove the "Reply" button from each comment. Include the Input Boxes for a new comment at the bottom of the list of comments. If you are worried about some timeout for the captcha have a button that refreshes the captcha.
This way you can refer back to the comments while posting and can easily quote several comments without having to go back and forth
Admin
Yeah, get your .Net rules executed in Java!
Admin
So wait, TDWTF is a confessional now???
Admin
Winner.
You can't test for null now because the architect wants to add the rules now but have the ability to defer execution of the rules to a later point in time.
If java allowed you to pass a function as a parameter, then case closed.
Admin
Admin
The Real WTF(TM) is that objName and o are being initialized to null when declared. In Java, instance object vars are always initialized to null automatically, so this is redundant.
Admin
Admin
I can see this making sense in some cases, where different parts of the system have different constraints so you'll want to compare the object against a different set of rules depending on the context. So their whole rules engine thing might not be tooooooo crazy.
The biggest WTF here is that there is a rule to check for null. If 'xml' is null, then my guess is that it's in a bad enough state that no one can use it and the program should just throw an exception/move on. I can just imagine a new Rule object instantiated after this one that tries to dereference this pointer and bombs the whole system.
In fact, I suspect the author submitted this because he found himself making "Rule" objects for the simplest things, such as the GreaterThan rule, or the IsNotEqualsOrNull rule. I bet these Rule things work great when there is some complex validation being done but simple checks like this would definitely be filed under "over-engineering."
Admin
Admin
At least it's addRule(NotNull(obj)), being called presumably from some other object.
would be truly enterprisey
Admin
Firefox, middle mouse click. Your friend and mine.
captcha: haero usage: haero r fire, don't matter to me.
Admin
Because I try to learn something from all the WTFs, let me be crystal clear on this: the problem is that Java does not have an analog to C# "delegates" or C++ function pointers/callbacks. So if I wanted to implement a rules engine like this in C#/C++, I would maintain a list of delegates/callbacks, one per rule, then fire them all off at test-time. And since Java doesn't implement a callback-type functionality, it has to be done with interfaces.
Did I get that right? Did this wind up as a WTF because there's a better way to do it in Java?
Admin
Admin
To do the above with base/sub-classes:
Admin
Thanks. I think I mentally skipped over that line like I skip the commentary between the pictures in the "Error'd" posts. :)
Admin
Instead of setting up frameworks, shouldn't you simply, you know, check rules? Maintainability is NOT the result of hiding each single piece of code separately in a gazillion layers of abstraction.
Admin
Constructing an object whose sole purpose is to check a whether one of the constructor parameters is non-null is silly. The result surely won't change, as you've copied the reference you're comparing against. If it was referring to an external field and checking that to see if something finally got initialized properly, then it might make some sense.
Admin
I thought the same as IceFreak when I first read the code, but you're perfectly correct :)
This could be used in C++ though and might be quite a neat system:
You could set up rules to validate class members or something if you want to check the integrity of an instance. It would be horribly wasteful though, since every instance would have to maintain its own rule list, might as well just have a function like:
Admin
<Preaching>That compiler warning would be a Good Thing (TM), because in your code snippet, xxx would not be set at all if someParam == 0. I'll go out on a limb here and say that if your compiler goes through the trouble of following all the branches of your code to determine if a variable may not have been set, then you should use that feature to your advantage wherever possible, rather than disabling it by setting an object to null when it is declared. In your example above, I would add an extra else clause that throws an exception or sets xxx to yetAnotherValue.</Preaching>
Admin
Often on this site, when people submit posts, they meant to put their "their" there, but put "there" instead. There is where they're mistaken...
Admin
It's more enterprise to use the short assembly name and no PublicKeyToken, that way you can load your rule validator in a new appdomain for every call and slip-stream in new rule assemblies without shutting down the app! Five 9s here we come!
Admin
Last time I worked with Java, that was an error, not a warning.
Instance variables are initialised to null but variables within methods (which this is an example of) are not. Hence, the requirment for explicit initialisation. The compiler checks this, and the bytecode verifier might too.
Admin
Yes, you can do this using a worker class & interface with a method signature for the worker to call.
Suppose you have a RulesProcessor "worker" class & a RuleChecker interface. Then, everything that implements RuleChecker can use the RulesProcessor like so:
// User class is "A". class A implements RuleChecker { ... // Apply checks on oneself using RulesProcessor. void checkRules(RulesProcessor p) { p.checkAll(this); } }
class RulesProcessor { ... boolean checkAll(RuleChecker c) {...} }
The function pointer is instead an object reference of "type" RuleChecker with a checkRules() function. Type checking is strict as hell in Java!
Admin
Why in the world would anybody, under any circumstances, want to put themselves through this unholy side-show, and then throw an entirely different, and unexpected exception? Under any circumstances?
In any case, just about any other "Rule" I can think of would throw a null reference exception as a side-effect. Thus, either
(a) There are other rules, and this one is unnecessary and misleading, or (b) There are no other rules, and this is just a supremely heavyweight and misguided way of asking "is this object null, or what?" or (c) There is noooooo... Rule C.
Huge brownie points to the OP, by the way. We all do loopy things like this that appear to make sense, and then regret it. The rest of this thread is frankly rather worrying.