- 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
Possible that this was intended to be a proper OO pattern (instantiate objects that have the behavior desired rather than run time checking of conditions scattered in the code) that had gone horribly wrong?
Admin
How can you still try to find excuses for something like this?
Admin
This a little extreme, but I've seen patterns like this done right and it does help. This is just stupid though.
Admin
Looks like a person told to use OO who did not understand what it meant.
Admin
A clever (or "clever") implementation of nullable booleans.
This would explain why they use the instanceof operator instead of an IsTrue method.
Admin
It's not really enterprisey. These classes need to be serializable and their instances loaded from an XML configuration file to even get close.
Admin
"The worst thing Java ever did was force class and package structures to mirror the filesystem. WHY WOULD YOU DO THIS?"
So I can easily locate the class that contains code that is wrong without doing a global search for it every time. And then when it turns out the offending code is in another class I don't have to look for that either.
Admin
Holy crap! Somebody got their panties in a bunch about something....
Admin
The Shortest Joke in the World
Blakeyrat.
Admin
What a great joke! I literally LOLed ... when scrolling through it.
Admin
Global searches are useful for many things (such as searching for a specific message to find where it comes from, or finding where some value is used etc.). If a global search is a problem, you're doing it wrong. Try adding a meg or two of RAM so it will fit in cache.
Admin
This is Oracle's fault. When they would have used C#, this wouldn't have happened. But it's open source, so what do you expect?
Admin
Think of the WTFery!!
Admin
WTF does that mean? It's not Oracle's fault that when you use their programming language you're an asshole who doesn't know WTF he's doing. Sorry, Blakeyrat, if you did this, it would be YOUR fault -- not Oracle's -- and it wouldn't matter if it was Java, C#, C++, Ada, or anything else because, clearly, you don't understand how to use these tools.
Admin
The ravenous Saar-Chasm claims yet another victim.
Admin
have anyone heard of bit fields?
Admin
Paid by line of code.
That would be a generous assumption.
I would rather be thought evil than stupid - which (stupidity and/or ignorance) is probably the real cause for code like this.
I made this comment to my boss a while back when remarking on our codebase (which is similar, but worse, WTFery) and he looked at me like I was evil. At least he didn't think I was stupid.
Kill all humans and bite my shiny metal ass - I AM A ROBOT!
Admin
Paid by
linelength ofcodevariables.FTFY
Admin
You're not the real Blakeyrat, you're far too dumb. You haven't fooled anybody.
Admin
This is a poor implementation of the type-safe enumeration pattern. Java supports it natively. If you must do this, use the native enum type. I'm an enterprise Java programmer but I prefer the boolean.
Java doesn't require every class to be in its own file. The first class in the file must match the name of the file. Any following classes in the file can be called whatever they want, but they are all going to be in the same package. But if you do this on my project, you're fired. I haven't yet seen a decent argument for allowing file names and class names to differ, let alone stuffing more than one class in a file.
I see a lot of hate for Java here and there but most of it is irrational like "class names must match file names WTF whargarrbl!". Very little of the hate actually hits on valid criticisms of the language and even when they do they usually miss the context of the original decisions.
Admin
It has been my experience that those who hate Java don't understand it. Many of the people I have met who say Java sucks write code like this in other languages. I guess it's bad that Java adheres to its own rules and other languages allow you to write whatever you want?
Admin
"Java doesn't require every class to be in its own file."
What Remy said was "one public class per file" which is entirely correct. The rest of the classes can be called whatever and, yes, they will be in the same package, but they will not be public.
Admin
Actually Remy never mentioned the word public. He only said that each class must be in its own file. Which is incorrect.
Admin
Let's see:
"WHY WOULD YOU DO THIS? Why would you only allow one public class per file?"
I can definitely see the word "public" in there. Yep, it definitely sounds like, and I quote, "one public class per file". Which most assuredly seems like exactly the same quote I used previously.
Admin
"Looks like a person told to use OO who did not understand what it meant."
Nope, they got it entirely right. Imagine if you implemented toString() on those classes, it'd be using polymorphism perfectly. Implementing Enum or Boolean the way Java does is simply not OO.
What's broken here is the fact that OO falls apart with something as simple as representing 'true' and 'false.' You can argue, "oh, but Java provides a perfectly good Boolean class," but it's not perfectly good. It's not OO, it's not extensible, you can't restrict or extend it, etc., so none of the features of OO are actually available. And they have to be turned off for builtin types because you couldn't write a remotely stable program with them on. And when they're on, it's absurdly hard to do things like compare two values for equality:
"So it seems we are stuck. Is there a sane way to redefine equality on several levels of the class hierarchy while keeping its contract? In fact, there is such a way, but it requires one more method to redefine together with equals and hashCode. The idea is that as soon as a class redefines equals (and hashCode), it should also explicitly state that objects of this class are never equal to objects of some superclass that implement a different equality method. This is achieved by adding a method canEqual to every class that redefines equals."
Source: http://www.artima.com/lejava/articles/equality.html
TRWTF is that OO is broken at the most fundamental level.
Admin
Psh you never said you meant from the HTML comments, which I never ever check.
Admin
It's still content written by Remy. It is, thus, stuff that Remy said. You chose to ignore that and then complained that "it's not something Remy said".
I don't even understand "I don't even read stuff" defence. You chose to ignore it. It's like saying "Oh, it's from the second paragraph - I never read that". I don't even see "but it's hard to read the comments" as a valid defence: https://greasyfork.org/en/scripts/search?q=dailywtf
It's not like these haven't existed for YEARS.
Admin
You can also put in public inner classes, which works well if they are actually related to / support the outer class (but seem silly otherwise). E.g. Map.Entry.
Admin
Let's just say that Java has room for improvement, and much of the culture around it fetishizes "WET" code.
E.g. - I would really like something like a Pascal type alias clause for things like repeated "generics" descriptions for variable declarations. E.g. - FooCache = Map<String,Foo> without having to make a class and then fight with "? extends" and such, or a cleaner lambda syntax vs "BiFunction <ParmA, ParmB, RetVal>" (also repeated ad nauseum in some cases).
Admin
I actually can see some reason in this. The programmer tried to restrict the domain his truth values could operate in (a boolean from a door sensor doesn't make sense in the context of a file browser) or extend its semantics. (add a Unknown value).
Admin
Why one public class per file? Because Java is a sane language for intelligent people.
Admin
obviously not a problem in implementation, but design. Why in the world would you set a constant and assign it with "true", then run a conditional over it? The conditional is completely superfluous. Either it is a variable, or it's not variable and all the code in the example could be deleted.
Admin
I just read this with a jawdrop all the way through. Not even joking or exaggerating.