• (cs)

    Perl hashes, brought to managed code.

  • Brian Kemp (unregistered) in reply to Maurits

    So what's worse...generic databases, or generic types?

    Be specific. ;)

  • Randolpho (unregistered) in reply to Maurits

    But... by... being... generic ...... it's not tied to any code!!!

     

    WTF???!?!

  • Fregas (unregistered)

    Fucking ar-tard!

    3rd post?

  • Randolpho (unregistered) in reply to Maurits

    Maurits:
    Perl hashes, brought to managed code.

    Managed code has had Perl hashes since day one. :)

  • (cs)
    Alex Papadimoulis:
    His colleague scoffed, insisting he already knew this and had been doing it for years in C++
    I feel sorry for the minions left to maintain of the colleague's legacy.
  • (cs) in reply to Randolpho

    Generics sound really really neat. So many times, I've written custom classes that were boilerplate lists or maps restricted to a specific type, and thought if only we had generics a lot of cookie-cutter code would disappear. I'm sure generics will be wonderful. But I really do fear an entirely new species of WTF<Exception>

  • diaphanein (unregistered) in reply to FriedEggs

    I think its safe to file this one away under the "Just doesn't get it" category.

  • (cs) in reply to FriedEggs
    FriedEggs:
    I feel sorry for the minions left to maintain of the colleague's legacy.
    No, really, English is my first language!  I got caught up in figuring out this posting software and sadly, my grammar checking went out the window.
  • (cs)

    i love it when they go against the grain .. just I hope that the tree lands on this programmer and rids the world of his unmanageable code!!!

  • Randolpho (unregistered) in reply to diaphanein

    Anonymous:
    I think its safe to file this one away under the "Just doesn't get it" category.

    <Dr. Evil>Scott, you just don't get it, do you?</Dr. Evil>

  • John Hensley (unregistered)

    So given that C++ has no basic Object class...
    what was this guy doing in C++?

  • (cs) in reply to John Hensley

    Anonymous:
    So given that C++ has no basic Object class...
    what was this guy doing in C++?

    Void pointers, baby!  Woohoo!

  • John Hensley (unregistered) in reply to zip
    zip:

    Anonymous:
    So given that C++ has no basic Object class...
    what was this guy doing in C++?

    Void pointers, baby!  Woohoo!


    My brane just exploded.
  • Judah (unregistered) in reply to John Hensley
    Anonymous:
    zip:

    Anonymous:
    So given that C++ has no basic Object class...
    what was this guy doing in C++?

    Void pointers, baby!  Woohoo!


    My brane just exploded.

    Meh bane jut splode

  • Gnome (unregistered) in reply to OneFactor

    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<Integer> myList = new ArrayList<Integer>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.

  • (cs) in reply to Judah

    Void pointers are wonderful for things like that, especially when they are not used. How do people like that get any kind of guru status? I would guess money, but who pays them?

  • Ragnar (unregistered)

    I write code that looks like that all the time, and it's not entirely stupid (although how he was doing in C++...who knows).  Depending on the warning level the Java compiler is set to, it will bitch at you for declaring

    Dictionary = new Dictionary();
    instead of
    Dictionary<Object, Object>  = new Dictionary<Object, Object>();
    Eclipse will, too, and the Sun people recommend you do it, too.  Of course, that doesn't mean that's why this guy was doing it...

  • (cs) in reply to Gnome
    Anonymous:
    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<integer> myList = new ArrayList<integer>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.


    If this really does as you say, then it would, in my opinion, be a defect in the implementation of generic programming in C#. C++ would not accept such nonsense. You do not want a supposedly modern, managed language to be less safe than a volcano language like C++. Why aren't the template/generic/type parameters for list2 inferred from the type definition of myList? It should be blindingly obvious to the compiler! And why does C# allow a generic class to be instantiated without proper template/generic/type parameters? Does the compiler at least emit a warning? What's the point of a static language if the compiler doesn't perform bondage-style static checks? Why not just use a fully dynamic language then?
    </integer></integer>
  • (cs) in reply to Athas
    Athas:
    Anonymous:
    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<Integer> myList = new ArrayList<Integer>();
    List list2 = myList;
    list2.add(new String());
    <integer><integer>

    Code compiles, now iterate through your genericized myList and see what happens.


    If this really does as you say, then it would, in my opinion, be a defect in the implementation of generic programming in C#. C++ would not accept such nonsense. You do not want a supposedly modern, managed language to be less safe than a volcano language like C++. Why aren't the template/generic/type parameters for list2 inferred from the type definition of myList? It should be blindingly obvious to the compiler! And why does C# allow a generic class to be instantiated without proper template/generic/type parameters? Does the compiler at least emit a warning? What's the point of a static language if the compiler doesn't perform bondage-style static checks? Why not just use a fully dynamic language then?
    </integer></integer>


    I believe he's referring to Java, not C#.  In C#, there is no non-generic form of the List class.  So line #2 above causes a compilation error.

    -ds
  • (cs)

    DUH!!!!

  • Zach M (unregistered) in reply to Gnome

    That's not exactly true, at least with Java 1.5. Depending on the compiler options you give it (or annotations) you can ignore the compilation errors. In Eclipse however, I have to specify I want the compiler to ignore these errors otherwise it will have issues. This is true since java has it's own issues with casting collections.

    List<Integer> newList = (List<Integer) oldList

    You see this a lot when working with Hibernate.

    -Zach

  • Gnome (unregistered) in reply to DisturbedSaint

    DisturbedSaint:

    I believe he's referring to Java, not C#.  In C#, there is no non-generic form of the List class.  So line #2 above causes a compilation error.

    -ds

    You're right, it's Java.

  • Zach M (unregistered) in reply to Athas
    Anonymous:
    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<integer> myList = new ArrayList<integer>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.
    </integer></integer>

    Do I meant to quote this in my previous post.

    -Zach
  • Zach M (unregistered) in reply to Zach M
    Anonymous:

    List<integer> newList = (List<integer) oldlist="">


    Well I just keep making mistakes I don't know how to display tags in here but I'm meaning something like

    List {Integer} newList = ( List {Integer}) oldList

    please replace { } with greater than, less than signs.

    -Zach
    </integer)></integer>
  • Andrew F (unregistered) in reply to Gnome
    Anonymous:
    Generics may sound great but, in Java, really they are a dirty hack that does not actually provide any type saftey at all.

    List<integer> myList = new ArrayList<integer>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.


    There, Fixed that for you.
    </integer></integer>
  • (cs) in reply to Zach M

    Anonymous:
    That's not exactly true, at least with Java 1.5. Depending on the compiler options you give it (or annotations) you can ignore the compilation errors. In Eclipse however, I have to specify I want the compiler to ignore these errors ...
    -Zach

    The real WTF here is that Java lets you ignore compilation errors.  I can see it now:

    <grommet> How do I make my code compile?  I'm getting this error...

    <guru> Ignore the error.

    <grommet> AWESOME, thanks!  Now why doesn't it work?

    Worse... I can see that happening in a business setting.

  • Zach M (unregistered) in reply to Corwinoid
    Corwinoid:

    Anonymous:
    That's not exactly true, at least with Java 1.5. Depending on the compiler options you give it (or annotations) you can ignore the compilation errors. In Eclipse however, I have to specify I want the compiler to ignore these errors ...
    -Zach

    The real WTF here is that Java lets you ignore compilation errors.  I can see it now:

    <grommet> How do I make my code compile?  I'm getting this error...</grommet>

    <guru> Ignore the error.</guru>

    <grommet> AWESOME, thanks!  Now why doesn't it work?</grommet>

    Worse... I can see that happening in a business setting.



    That's true. That's why I sort of butt heads against Annotations in some respects because to me their are glorified pre-processor directives. However seeing some things with frameworks like Stripes [Stripes] They have some uses.
  • (cs) in reply to Gnome
    Anonymous:

    DisturbedSaint:

    I believe he's referring to Java, not C#.  In C#, there is no non-generic form of the List class.  So line #2 above causes a compilation error.

    -ds

    You're right, it's Java.


    That's not to say that C# doesn't have its own issues with generics...

                List<Int32> myList = new List<Int32>();
                IList myList2 = myList;
                myList2.Add("Hello World!");

    That compiles, but will at least throw an exception when line 3 is hit.

    -ds
  • (cs) in reply to Corwinoid
    Corwinoid:
    The real WTF here is that Java lets you ignore compilation errors.


    They probably needed it as a feature to win over the On Error Resume Next-crowd from Visual Basic. Or perhaps the Java spec writers had heard of this site and wanted to ensure amusing code for the next many years.
  • mol (unregistered)

    Alex Papadimoulis:

    In the last year or so, we saw the concept of generics in managed code. Microsoft introduced them in their .NET 2.0 platform and Sun brought them into Java 5.

    Java generics are actually much older than Microsoft's. IIRC there existed independant prototype implementation for long time and than there was JSR14 prototype compiler from Sun Early Access available something like year before 1.5 final.

     

     

    Something didn't quite work out ...
    - CAPTCHA Validation Incorrect

  • anonymous (unregistered) in reply to DisturbedSaint

    It doesn't work with lists (at least when I tried it), but List<t> implements both IList<t> and IList interfaces. So you could do:

    List<int> myList = new List<int>();
    IList list2 = myList;
    list2.Add("");
    

    and it will compile fine and dandy (it will throw an exception at runtime on line 3).

  • Ragnar (unregistered) in reply to Corwinoid

    I might be wrong here but I'm pretty sure Java doesn't let you ignore errors.  It lets you ignore warnings, which is what the java compiler gives you if you don't properly (in its view) genericize things.

  • ChiefCrazyTalk (unregistered) in reply to Athas

    Athas:
    Corwinoid:
    The real WTF here is that Java lets you ignore compilation errors.


    They probably needed it as a feature to win over the On Error Resume Next-crowd from Visual Basic. Or perhaps the Java spec writers had heard of this site and wanted to ensure amusing code for the next many years.

     

    Reminds me of about 10 years ago, when I was programming in Delphi.  We joked that we could solve all of our bugs by just having the code look like (I forget exact syntax)

     

    Try {

    Application.Run()

    }

    catch(...) {

    }

     

    Brillant!

     

     

  • (cs) in reply to anonymous

    Java does NOT let you ignore compilation errors!

    The case here is that casting a parametrized type to a raw type merely issues a warning, not an error. The reason is backwards compatibility. If you couldn't cast a List<Integer> to a List, how would you pass it to a pre-Java 5 library that uses the raw type?

    But of course, if you ignore warnings, it's your own bloody fault. Never ignore warnings! When they occur, check the code carefully, make sure it's really what you want. Then add a SuppressWarning annotation to mark the fact that you've double-checked.
    http://blogs.msdn.com/michkap/archive/2006/01/30/519993.aspx

  • Randolpho (unregistered) in reply to DisturbedSaint

    DisturbedSaint:
    That's not to say that C# doesn't have its own issues with generics...

                List<INT32> myList = new List<INT32>();
                IList myList2 = myList;
                myList2.Add("Hello World!");

    That compiles, but will at least throw an exception when line 3 is hit.

    That's less of a generics issue and more of an inappropriate use of IList issue.

    Plus, I think you'll get a warning. Need to test it, though.

  • Randolpho (unregistered) in reply to Randolpho
    Anonymous:

    DisturbedSaint:
    That's not to say that C# doesn't have its own issues with generics...

                List<INT32> myList = new List<INT32>();
                IList myList2 = myList;
                myList2.Add("Hello World!");

    That compiles, but will at least throw an exception when line 3 is hit.

    That's less of a generics issue and more of an inappropriate use of IList issue.

    Plus, I think you'll get a warning. Need to test it, though.

    Actually, now that I look at it again, that shouldn't compile because you forgot to cast myList to IList. Looks like I need to get an account. :)

  • Paula Bean (unregistered)

    "Brilliant", said Paula Bean.

  • Brian Schkerke (unregistered) in reply to DisturbedSaint
    DisturbedSaint:

    That's not to say that C# doesn't have its own issues with generics...

                List<int32> myList = new List<int32>();
                IList myList2 = myList;
                myList2.Add("Hello World!");

    That compiles, but will at least throw an exception when line 3 is hit.

    -ds


    That doesn't compile.  IList is treated as a generic and requires a type declaration.

    Using the generic type 'System.Collections.Generic.IList<T>' requires '1' type arguments

    Even if you have a code sample of that form that does compile, I'd vote the problem is with the developer, not the language.  List<> has to implement the IList interface in order to be usable; using the interface to access the object and intentionally trying to break it seems silly.



    </int32></int32>
  • Brian Schkerke (unregistered) in reply to Brian Schkerke
    DisturbedSaint:

    That's not to say that C# doesn't have its own issues with generics...

                List<int32> myList = new List<int32>();
                IList myList2 = myList;
                myList2.Add("Hello World!");

    That compiles, but will at least throw an exception when line 3 is hit.

    -ds


    </int32>Bah.

    Ok, it compiles and does throw an exception.  You just have to include System.Collections as well as System.Collections.Generic.

    I still vote it's misuse of an interface. :)

    </int32>
  • (cs) in reply to CornedBee
    CornedBee:
    Java does NOT let you ignore compilation errors!

    The case here is that casting a parametrized type to a raw type merely issues a warning, not an error. The reason is backwards compatibility. If you couldn't cast a List<integer> to a List, how would you pass it to a pre-Java 5 library that uses the raw type?

    But of course, if you ignore warnings, it's your own bloody fault. Never ignore warnings! When they occur, check the code carefully, make sure it's really what you want. Then add a SuppressWarning annotation to mark the fact that you've double-checked.
    http://blogs.msdn.com/michkap/archive/2006/01/30/519993.aspx


    You're right, it's not a compiler error, but a warning. In Eclipse I modded up those particular warnings to be error in code. Similar to x = x or Unused Imports, and added the @SuppressWarnings("unchecked") for bringing things out of Hibernate.

    -Zach
    </integer>
  • Pinguis (unregistered) in reply to John Hensley
    Anonymous:
    So given that C++ has no basic Object class...
    what was this guy doing in C++?

    Maybe he created a class Object, and derivied all other classes from that one? its a good way to ensure generic and polymorphic data structures in c++

  • (cs) in reply to OneFactor
    OneFactor:
    But I really do fear an entirely new species of WTF<exception>


    I bet someone who was kicked out of C++ development due to gross misuse of C++'s template features will find a way to... dare I even suggest... replicate C++'s... expressivity... that both MS and Sun vehemently denied that generics would have.

    Today's post was pathetic in that regard, it was almost readable. Hope someone tries harder. Come on! Something worse? You know,  remove-a-space-from-a-funny-location-and-it-won't-compile worse?


    </exception>
  • (cs) in reply to Brian Schkerke

    Anonymous:
    DisturbedSaint:

    That's not to say that C# doesn't have its own issues with generics...

                List<INT32> myList = new List<INT32>();
                IList myList2 = myList;
                myList2.Add("Hello World!");

    That compiles, but will at least throw an exception when line 3 is hit.

    -ds


    </INT32>Bah.

    Ok, it compiles and does throw an exception.  You just have to include System.Collections as well as System.Collections.Generic.

    I still vote it's misuse of an interface. :)

    </INT32>

    Use or misuse, it means the advertising hype of "type-safe collections" is a myth. It means that "provably safe casting" is right up there with believing in the tooth-fairy.

    The entire point of Generics is to trap these casting errors at compile time rather than runtime. If all we do is reclassify these runtime errors as misuses we haven't really accomplished anything.

    Making the generic lists implement the old list interfaces for backwards compatibility is just daft. Reminds me of the "refused bequest" bad smell in code. Except now the smell is ingrained in the core language of both Java and .Net

    My ILists, the Generics, they do nothing!

  • Mike (unregistered) in reply to OneFactor

    > if only we had generics a lot of cookie-cutter code would disappear.

    Check out Ruby or Python.  It will asplode your brane. 

  • jmcqk6 (unregistered) in reply to Brian Schkerke

    You're right that it doesn't compile, but does throw an exception.

    I don't know why you would do this in a 'production' piece of code, but I guess that is what this website is all about.

    long time reader, first time poster :)

  • George (unregistered) in reply to Athas

    Athas:
    Anonymous:
    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<INTEGER> myList = new ArrayList<INTEGER>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.


    If this really does as you say, then it would, in my opinion, be a defect in the implementation of generic programming in C#. C++ would not accept such nonsense. You do not want a supposedly modern, managed language to be less safe than a volcano language like C++. Why aren't the template/generic/type parameters for list2 inferred from the type definition of myList? It should be blindingly obvious to the compiler! And why does C# allow a generic class to be instantiated without proper template/generic/type parameters? Does the compiler at least emit a warning? What's the point of a static language if the compiler doesn't perform bondage-style static checks? Why not just use a fully dynamic language then?
    </INTEGER></INTEGER>

     

    That code does compile, sure, but as others have pointed out - it does give you a warning.  If you ignore the compiler warning then of course it's your own responsibility to be type-safe!

  • George (unregistered) in reply to CornedBee

    CornedBee:
    Java does NOT let you ignore compilation errors!

    The case here is that casting a parametrized type to a raw type merely issues a warning, not an error. The reason is backwards compatibility. If you couldn't cast a List<INTEGER> to a List, how would you pass it to a pre-Java 5 library that uses the raw type?

    But of course, if you ignore warnings, it's your own bloody fault. Never ignore warnings! When they occur, check the code carefully, make sure it's really what you want. Then add a SuppressWarning annotation to mark the fact that you've double-checked.
    http://blogs.msdn.com/michkap/archive/2006/01/30/519993.aspx

     

    yeah!  What he said!

  • Tony Morris (unregistered) in reply to Gnome
    Anonymous:
    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<integer> myList = new ArrayList<integer>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.


    Assuming you are referring to Java, you are right on one point - generics are a hack. The point where you are wrong is the assertion that they do not provide type-safety in your provided case. The Java generics implementation makes the following guarantee: "Your parameterized types will not fail at runtime provided you receive no compile-time warning" - your case meets this contract, since it will generate a compile-time warning - in which case, you have left the context of the generics contract.

    On the issue of the flaws of generics, I cannot reveal everything, since after all, I recently left my job implement the spec., working with JSR groups, etc, and I will upset The Filth that I was up until recently employed by, but I can take a type such as java.util.ArrayList (as you have provided) and ask you to try implementing it  yourself without receiving a compile-time warning  - good luck with it :) When you fail, ask yourself "why?" - then you will discover one of many "generics hacks".
    </integer></integer>
  • (cs) in reply to Gnome
    Anonymous:
    Generics may sound great but really they are a dirty hack that does not actually provide any type saftey at all.

    List<integer><Integer> myList = new ArrayList<Integer><integer>();
    List list2 = myList;
    list2.add(new String());

    Code compiles, now iterate through your genericized myList and see what happens.


    As others have said, if you're ignoring warnings from the Java compiler, you deserve what you get.

    Of course, if you have no control over who's going to be messing with your list, this will force it to stay "pure":

    List<Integer> myList = new ArrayList<Integer>();
    myList = Collections.checkedList(myList, Integer.class);
    // Go ahead and ignore compiler warnings, but it will throw an exception when you try to "pollute" it at runtime

    You did read the "New Features and Enhancements" section of the JDK's documentation, right?  You did notice the new methods mentioned in http://java.sun.com/j2se/1.5.0/docs/guide/collections/changes5.html , right?
    </integer></integer>

Leave a comment on “Generic Generics”

Log In or post as a guest

Replying to comment #:

« Return to Article