- Feature Articles
- CodeSOD
-
Error'd
- Most Recent Articles
- Stop Poking Me!
- Operation Erred Successfully
- A Dark Turn
- Nothing Doing
- Home By Another Way
- Coast Star
- Forsooth
- Epic
- 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
This code is a precursor to the data structures used in the Matrix.
Admin
Holy crap. I've never seen such... dystopia.
Admin
That would have been fine if he'd had the sense to declare a special class for it.
Admin
What a HASH mess!!
I like the 'superHashMap'. Does he wear a mask or a red cape?
Admin
There probably would have been a better (readable) way to store his data structures.
Admin
So the long is the universe, the timestamp is the time, the vector is the dimension and the string is the key.
What's wrong with that?
Admin
This reminds me of C++ too badly.
Admin
Ah yes. No-one will ever need typedef, so let's remove it from the language! Also, operator overloading is clearly always evil, there are no legitimate uses of multiple inheritance, programmer-controllable memory management is pointless, stack allocation is a waste of time, const is silly, scope-controlled destruction doesn't help anyone, a common base class for everything is good and treating programmers like idiots is the best idea ever.
Admin
Fast First, Frust!
Admin
This may not be my code, but I've left plenty of little nuggets like that in the codebase from my last job, and I'm more than ok with it. I'm being VERY explicit about what's going on, and it shuts the compiler up.
Addendum (2008-05-08 08:25): It could/should probably be refactored a bit so that at least a chunk of that is it's own class, but without seeing the context I can't say.
Admin
Sounds like your "brillant" code was scrapped in favor of something written with Java, and you're Not At All Bitter Not Even A Little Bit.
Frankly, I don't see why you're happy with the wastefulness of C++. Why aren't you writing in assembly? I mean, have you SEEN the overhead that compilers create? And I don't see why we need to be told that we can't use a floating point number JUST AS IT IS as a pointer! Damnit, I know exactly what I'm doing, just let me do it!
Admin
Now would be a good time to write your own fucking data structure
Admin
Admin
No wait! We already have that: XML!
Admin
Gah, introducing Vector usage in Java 5? Inexcusable. It's been ArrayList since 1.2 y'know...
Admin
Fifteenth!
Admin
TRWTF is that he coded to the implementation rather than the interface. The line should read:
Map<Long, Map<Timestamp, List<Map<String, Object>>>> superHashMap = new HashMap<Long, Map<Timestamp, List<Map<String, Object>>>>();
Much better.
Also, Vector is deprecated, except that it's not.
Admin
I get it. The WTF is that the problem here isn't Generics at all, but data structures being nested on the fly (instead of being refactored out into their own class), right?
Admin
Hmmm. I suppose it's clearer or at least compile-time-safer than the equivalent non-generic code:
HashMap superHashmap = new Hashmap(); //of long to hashmap mapping from timestamp to vector of hashmaps mapping from string to object.
Admin
I know, he should be using interfaces. (And what is that: Vector?)
Looks much better...
Admin
"
That's better, I can breathe now.
Admin
HashMap<Long, HashMap<Timestamp, Vector<HashMap<String, Object>>>> superHashMap = new HashMap<Long, HashMap<Timestamp, Vector<HashMap<String, Object>>>>();
Be glad, very glad that this predecessor of yours used this notation. You wouldn't have none that this superHashMap was a seven-headed dragon if the definition read Map superHashMap = new HashMap();
Now at least you know you're in trouble; good luck though ;)
Admin
Nasty.
Admin
Shush you, he's talking about extra features that are helpful. That is the opposite of going back to assembly. typedef would sort this crap code instantly
Admin
Yeah, in C++ I'd introduce a typedef, but is this really so bad? By no means a Worse Than Failure. I guess we'll have an article about multi-dimension arrays next.
Admin
As a C++ programmer, this does not even faze me. Try using the STL a bit more and then look at how the types used end up being called by the compiler/linker at the end. The example in article is harmless.
Admin
No he's not, he's just complaining about how Java isn't exactly C++ and C++ has all sorts of really good stuff and Java is for idiots and newbies and it may as well be visual basic and did I mention that C++ won the war of 1812 with operator overloading but YOU wouldn't know about that with your fancy pants language for idiots that doesn't even have typedefs! Sheesh!
Admin
I'm not so concerned with the "very specific generics". I've done stuff like that mainly to just shut the compiler up.
My concern is with the horrid data structure. I've done a hash of a hash before, but never a hash of a hash of a vector of a hash. Surely that could have been organized into a better set of objects.
Admin
Admin
Hmm, I can't find anything worse than Map<String,Map<String,Map<String,Long>>> on the class I'm viewing now. But somehow I don't really consider it WTF-worthy.. Must be a thin line I have somewhere, or I'm slowly becoming a lesser programmer.
Admin
Looks like you (and the submiter) missed the point. The WTF is not that the guy is using generics. There are actually 2 (maybe 3) WTFs:
Of course, in Java you just create Yet Another Class to mimic a typedef.
The guy is not sensitive to pain anymore. Anyone who would dare to write that much code just to create an object has probably sold his soul.
Did the submiter suggest not using generics would be better? If so, that's an even bigger WTF than the code. Languages have types for a reason.
The other characteristics pointed Volmarias are present in many other languages, not just C++; maybe it's you that is the disgrunted programmer with an agenda to criticize C++. I see Java programmers flaming C++ much more often than C++ programmers flaming Java.
And thank god I don't have to code in Java. It's mostly Python for me. It has typedefs, operator overloading, multiple inheritance, const (through a bit of hacking), scope-controlled deterministic destruction, and no common base class for everything. And it doesn't treat me like an idiot.
Admin
public void DoNothing<T>(T eyewear) where T : goggles {}
Admin
Admin
I would rather have typedef in Java thanks. Then we could shorten this and give it some obvious semantic meaning very quickly, instead of resorting to creating a completely new data structure or wrapper class for it like other people say. It's the opposite of returning to assembly.
"PhoneBook" is much easier to understand than "map< string, string>" (which could mean anything!).
Admin
It's kind of a shame how all that effort is put into making this very specific data structure, which at the end of the day, stores a load of Objects ...
Admin
Have to say that the real WTF is the Java language itself. You can't typedef this, so you're stuck between writing out a long generic definition, getting RSI writing out a whole load of class definitions which makes the calling code smaller but the called code ten times more complicated and error prone, or creating a derived class which might look like the generic version some of the time, but will bite you in the ass when you discover it isn't.
On your left, a rock. On your right, a hard place.
Admin
class PhoneBook extends map<string,string> {}
It's slightly verbose, but it's basically a typedef. Plus it has the advantage of making the language more orthogonal.
Admin
Admin
Admin
Would be nothing wrong with that if it was readable... doesn't Java have something along the lines of C++'s typedef?
Admin
Captcha: valetudo. That's a fighting style. Oh the irony...
Admin
Admin
If you just want to search for entries that match a specific Long, Timestamp and String: collate them into a single class with appropriate equals() and hashCode() methods so that instances can be used straightforwardly as a key in a simple HashMap.
If you want to do flexible partial-match searches: use a friggin' DBMS.
With your wonderful typedef, you'd still be writing WTF code, it just wouldn't be as obvious.
Admin
They need groovy: http://groovy.codehaus.org/ ... many of those problems don't exist in hybrid Java/Groovy code.
Admin
I actually had to do some hashmaps of vectors in C++ and discovered if you just go std::map<std::string, std::vectorstd::string> it gives you an error for nesting <'s
Admin
Is this another way of saying:
"Why hasn't Java got typedef?"
Admin
finally someone gets the point. A) the constructor is ugly (and there are proposals and many utils out there to mitigate the redundancy in the declaration) B) the declaration should be "Map<Long, Map<Timestamp, List<Map<String, Object>>>>" C) the structure is probably not the clearest even in that case
but think about the traversal. I'm omitting the Vector layer, since i can't figure out what that would be fore.
Long id = 1; Timestamp time =...; String key = "..."; Object value = superHashMap.get(id).get(time).get(key);
now make that null-safe
Object value = null; Map<Timestamp, List<Map<String, Object>>> tmp = superHashMap.get(id); if (tmp != null) { Map<String, Object> tmp1 = tmp.get(time); if (tmp1 != null) { Object value = tmp1.get(key); } }
At least with generics the traversal is compile-time type-safe. But still a horrible mess compared with what the user wants (and would get if they made a class, and which a typedef does not provide) of
Object value = superMap.get(id, time, key)
A typedef will not give you the clean & nullsafe traversal machanics you get by defining a class. And the typedef: A) does not give you compile-time type-check for one Map vs another Map typedef B) does not give you convenient, semantically clear, and safe traversal C) only adds clarity to the declarations, whhich also is better captured by the variable names. With "PhoneBook phonebook;... String phonenumber = phonebook.get(name);" the typedef doesn't change the later line at all. It's the variable names that make the meaning clear.
It is not the lack of typedef that makes this a WTF, it's the bad coder. Which is possible in any language by anyone at any time.
Admin
And I never see it, really, ever.
I think you're missing the point; rather than dealing with the WTF at hand (which isn't much of a WTF for that matter), you point out a laundry list of things that other languages have that Java doesn't, a good deal of them on purpose.
Java doesn't have lambda functions as far as I understand it. Does that mean that Java programmers should lament their fate?
I'm glad you're happy. Java doesn't treat me like an idiot either; I have yet to run into a problem that I couldn't solve just because of the language format. Java isn't C++, if you accept this fact you'll be fine programming in it. But, please, lets start a holy war over this because you don't like Java.
Admin
Looks like poo :) Ever heard of the adapter pattern? Allows you to hide even very complicated data structures and only a simple interface is public.
http://en.wikipedia.org/wiki/Adapter_pattern
Admin
Best critic of Java, ever!