|
|
|
| CSS/XHTML Gurus, Web Designers, PHP Devs: You + Zootoo (NJ)? |
| « Prev | Page 1 | Page 2 | Next » |
|
They have to do that all the time because Java doesn't have proper verbs.
|
|
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. |
|
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.
|
|
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". |
Re: The Enterprisey Null Test
2008-02-22 08:21
•
by
Kluge Doctor
(unregistered)
|
I did misspell WTF, of course! :-) |
|
TRWTF(tm) is that it's "their", not "there". And that's coming from non-native speaker.
|
Re: The Enterprisey Null Test
2008-02-22 08:47
•
by
NeoMojo
(unregistered)
|
|
lol, whut?
|
Re: The Enterprisey Null Test
2008-02-22 08:47
•
by
Thomas
(unregistered)
|
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. |
Re: The Enterprisey Null Test
2008-02-22 08:52
•
by
Cpt
(unregistered)
|
You mean that native speakers will never make this mistake? Hmmm... somehow I doubt that... |
Re: The Enterprisey Null Test
2008-02-22 09:08
•
by
Jamie
(unregistered)
|
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. |
Re: The Enterprisey Null Test
2008-02-22 09:22
•
by
claudiu
(unregistered)
|
This will be OK for a validation framework if you passed the object to be tested in the the call to check() like check(Object o) not in the constructor of the rule. Because it is in the constructor you need to recreate the rule every time you validate a new object. |
|
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. |
Re: Native speakers
2008-02-22 09:31
•
by
yanni
(unregistered)
|
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) |
|
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. |
Re: The Enterprisey Null Test
2008-02-22 09:41
•
by
Sam
(unregistered)
|
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. |
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". |
Oh, come on. He could have written "they're". But it wouldn't have been caught by a spell-checker. "couln't" on the other hand... |
Re: The Enterprisey Null Test
2008-02-22 09:58
•
by
T604
(unregistered)
|
At that point shouldn't you be using a rules engine? instead of trying to roll your own? |
Re: The Enterprisey Null Test
2008-02-22 10:01
•
by
notJoeKing
(unregistered)
|
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? |
|
"...will go to 'enterprise up' there Java apps..."
"there" above should be "their". can't believe you didn't see that :) |
|
It's so much worse when you notice that your mind is going...
|
|
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" /> |
Re: The Enterprisey Null Test
2008-02-22 10:37
•
by
notme
(unregistered)
|
Your first language doesn't happen to be German, does it? Also, you forgot the word "a". |
Re: The Enterprisey Null Test
2008-02-22 10:52
•
by
Mizchief
(unregistered)
|
|
Huh, didn't realize they had dll's in java
|
Re: Native speakers
2008-02-22 10:57
•
by
German B.
(unregistered)
|
TRWTF(tm) is that it's "English", not "english". And that's coming from a non-native speaker. |
Re: The Enterprisey Null Test
2008-02-22 11:00
•
by
Mizchief
(unregistered)
|
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 |
Re: The Enterprisey Null Test
2008-02-22 11:03
•
by
Chesterton Wendelbury
(unregistered)
|
Yeah, get your .Net rules executed in Java! |
Re: The Enterprisey Null Test
2008-02-22 11:05
•
by
Chesterton Wendelbury
(unregistered)
|
|
So wait, TDWTF is a confessional now???
|
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. |
TRWTF is non-native speakers are often much clearer and make fewer errors than some of the people who learned English as their first language. |
|
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.
|
This may be necessary to work in threaded environments. Without more context, there's no way to know if this is appropriate. |
Re: The Enterprisey Null Test
2008-02-22 11:28
•
by
Outlaw Programmer
|
|
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." |
True, but compiler-warnings of xxx may not have been initialized are annoying...
|
|
At least it's addRule(NotNull(obj)), being called presumably from some other object.
would be truly enterprisey |
Re: The Enterprisey Null Test
2008-02-22 11:46
•
by
GF
(unregistered)
|
Firefox, middle mouse click. Your friend and mine. captcha: haero usage: haero r fire, don't matter to me. |
|
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? |
Interfaces are the way Java implements callbacks. The only difference is that you can't have a standalone method, so it always needs to be enclosed in a class. More boilerplate, sure. But with local or anonymous classes (classes that are defined within a method and have access to all variables in that method's scope), it's not that much more verbose than a "real" function pointer or even a closure. |
Not quite. You can do callbacks in Java with either base/sub classes or interfaces:
To do the above with base/sub-classes:
|
Re: The Enterprisey Null Test
2008-02-22 12:05
•
by
notJoeKing
(unregistered)
|
Thanks. I think I mentally skipped over that line like I skip the commentary between the pictures in the "Error'd" posts. :) |
Two future architects, I see. 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. |
Re: The Enterprisey Null Test
2008-02-22 12:12
•
by
Thuktun
(unregistered)
|
This makes the most sense. I can see using Rule objects if you're allowing runtime configuration of validations to be assembled on-demand for something, and I can see the message constant rather than a hard-coded string. 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. |
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:
|
Re: The Enterprisey Null Test
2008-02-22 14:22
•
by
Dave
(unregistered)
|
<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> |
Re: The Enterprisey Null Test
2008-02-22 14:47
•
by
Christophe
(unregistered)
|
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... |
Re: The Enterprisey Null Test
2008-02-22 16:36
•
by
NoOneKnows
(unregistered)
|
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! |
Re: The Enterprisey Null Test
2008-02-22 16:40
•
by
AC
(unregistered)
|
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. |
Re: The Enterprisey Null Test
2008-02-22 17:53
•
by
Andrew
(unregistered)
|
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! |
Re: The Enterprisey Null Test
2008-02-22 19:01
•
by
real_aardvark
|
Not being a Java expert, I'm confused. I was under the impression that the language itself checks to see whether an object is null, and then throws one of those all-too-frequent "null reference" exceptions (which are either checked or not checked -- I can't be bothered to look up the difference). 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. |
| « Prev | Page 1 | Page 2 | Next » |