• drx (unregistered)

    This code is a precursor to the data structures used in the Matrix.

  • Sam (unregistered)

    Holy crap. I've never seen such... dystopia.

  • Kir Birger (unregistered)

    That would have been fine if he'd had the sense to declare a special class for it.

  • (cs)

    What a HASH mess!!

    I like the 'superHashMap'. Does he wear a mask or a red cape?

  • Bombe (unregistered)

    There probably would have been a better (readable) way to store his data structures.

  • (cs)
    HashMap<Long, HashMap<Timestamp, Vector<HashMap<String, Object>>>>

    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?

  • Treeki (unregistered)

    This reminds me of C++ too badly.

  • Ciaran McCreesh (unregistered)

    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.

  • ClaudeSuck.de (unregistered)

    Fast First, Frust!

  • (cs) in reply to Treeki

    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.

  • (cs) in reply to Ciaran McCreesh
    Ciaran McCreesh:
    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.

    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!

  • MooseBrains (unregistered)

    Now would be a good time to write your own fucking data structure

  • (cs) in reply to Volmarias
    Volmarias:
    I'm being VERY explicit about what's going on, and it shuts the compiler up.
    /**
     * Warning! This class contains VERY explicit language, 
     * due to all of the compiler warnings I was getting...
     * Sheesh!
     */
    
  • Cope with IT (unregistered) in reply to MooseBrains
    MooseBrains:
    Now would be a good time to write your own fucking data structure
    ...definition language.

    No wait! We already have that: XML!

  • Rich (unregistered)

    Gah, introducing Vector usage in Java 5? Inexcusable. It's been ArrayList since 1.2 y'know...

  • Joe (unregistered)

    Fifteenth!

  • The Java Inquisition (unregistered)

    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.

  • Tonio (unregistered)

    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?

  • commenter (unregistered)

    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.
  • Dirk (unregistered)

    I know, he should be using interfaces. (And what is that: Vector?)

    Map<Long, Map<Timestamp, ? extends List<Map<String, Object>>>> superHashMap =
        new HashMap<Long, Map<Timestamp,? extends List<Map<String,Object>>>>();
    

    Looks much better...

  • robert (unregistered)

    "

    That's better, I can breathe now.

  • Merijn Vogel (unregistered)

    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 ;)

  • Rich (unregistered) in reply to The Java Inquisition
    The Java Inquisition:
    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.

    Hmmm, something tells me that elsewhere in this class we'll have methods defined thusly:

    public void doStuff(Vector<HashMap<String, Object>> listMapThing)
    {
      // Do stuff here.  Interface?  What's an interface?
    }
    

    Nasty.

  • prod (unregistered) in reply to Volmarias

    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

  • (cs)

    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.

  • notme (unregistered)

    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.

  • (cs) in reply to prod
    prod:
    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

    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!

  • zombiekitty (unregistered)

    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.

  • Smash (unregistered) in reply to Raedwald
    Raedwald:
    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.
    I can't tell whether you're dead serious or ultimately sarcastic here. I hope for the latter, or I pity your cow-orkers
  • Johan (unregistered)

    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.

  • DKO (unregistered) in reply to Volmarias
    Volmarias:
    Ciaran McCreesh:
    Ah yes. No-one will ever need typedef (...)

    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.

    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:

    1. There is no typedef. The code would be much more cleaner as
    SuperHero marypoppins = new SuperHero();

    Of course, in Java you just create Yet Another Class to mimic a typedef.

    1. 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.

    2. 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.

  • Jon B (unregistered)

    public void DoNothing<T>(T eyewear) where T : goggles {}

  • TraumaPony (unregistered) in reply to Smash
    Smash:
    Raedwald:
    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.
    I can't tell whether you're dead serious or ultimately sarcastic here. I hope for the latter, or I pity your cow-orkers
    Wow, how witty.
  • prod (unregistered) in reply to Volmarias
    Volmarias:
    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!
    Um.. ya... and? Your argument is the same and it's a non sequitur quite frankly. Those features you mention are helpful language constructs removed from Java purposefully, so in that sense Java is more like returning to assembly.

    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!).

  • Jim T (unregistered)

    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 ...

  • Ritchie (unregistered)

    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.

  • Robin Message (unregistered) in reply to prod

    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.

  • (cs) in reply to DKO
    DKO:
    1) There is no typedef. The code would be much more cleaner as
    SuperHero marypoppins = new SuperHero();
    Of course, in Java you just create Yet Another Class to mimic a typedef.
    'mimic'? Classes (and interfaces) are how you define types in Java. This is not a case of the language not having the necessary tool, it's a case of the language having the tool and the programmer not using it.
    DKO:
    The other characteristics pointed Volmarias are present in many other languages, not just C++;
    And none of them have anything to do with the WTF at hand.
    DKO:
    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.
    Where? I have never seen a Java programmer start a rant against C++ based on nothing at all, while the reverse is a daily occurence pretty much everywhere I've seen the two meet.
  • h (unregistered) in reply to yuumei
    yuumei:
    HashMap<Long, HashMap<Timestamp, Vector<HashMap<String, Object>>>>

    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?

    It's still not superHashMap enough...

  • Milivoj (unregistered) in reply to yuumei

    Would be nothing wrong with that if it was readable... doesn't Java have something along the lines of C++'s typedef?

  • Smash (unregistered) in reply to TraumaPony
    TraumaPony:
    Wow, how witty.
    Great! Let the Flame Wars begin. And since it's my turn, I guess I'll throw an infamous yo'mama joke now.

    Captcha: valetudo. That's a fighting style. Oh the irony...

  • foo (unregistered) in reply to yuumei
    HashMap<Long, HashMap<Timestamp, Vector<HashMap<String, Object>>>>
    So the long is the universe, the timestamp is the time, the vector is the dimension and the string is the key.
    What ever problem it is that really, truly, honestly, _needs_ a solution like this... that needs to distinguish between objects created in the same thread and the same name inside the same millisecond... SHOULD NOT be solved with Java. The programming language to succinctly solve this problem does not exist... and is not intended for mortals. That would be a nightmare problem even for Haskel... or any language. Hell, I think staring into the face of Chluthlu for an hour would be easier. Defining the data structure is simple enough... working with it would drive a mortal to madness.
  • (cs) in reply to Ritchie
    Ritchie:
    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.

    In front of you: the correct ways to do it, which are either:

    1. 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.

    2. 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.

  • foo (unregistered) in reply to Ritchie

    They need groovy: http://groovy.codehaus.org/ ... many of those problems don't exist in hybrid Java/Groovy code.

  • (cs)

    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

  • Tim Ward (unregistered)

    Is this another way of saying:

    "Why hasn't Java got typedef?"

  • immitto (unregistered) in reply to brazzy

    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.

  • (cs) in reply to DKO
    DKO:
    I see Java programmers flaming C++ much more often than C++ programmers flaming Java.

    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.

    DKO:
    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++.

    Java doesn't have lambda functions as far as I understand it. Does that mean that Java programmers should lament their fate?

    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.

    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.

  • XyC (unregistered) in reply to yuumei

    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

  • Val (unregistered) in reply to Ciaran McCreesh

    Best critic of Java, ever!

Leave a comment on “Very Specific Generics”

Log In or post as a guest

Replying to comment #193717:

« Return to Article