3 ms·
As a developer with experience in .NET, Java and Ruby, I'm curious as to what makes you say C# collections are a mess? At least relative to Java?
by garrettheaver 12y ago
As a developer with experience in .NET, Java and Ruby, I'm curious as to what makes you say C# collections are a mess? At least relative to Java?
- pjungwir 12y agoI haven't used either in a few years, but Java's are trivial to remember: * List: implemented by ArrayList and LinkedLink * Set: implemented by HashSet * Map: implemented by HashMap All are Collections. Then it's easy to get immutable versions, synchronized versions, Sorted{Set,Map}s (implemented by Tree{Set,Map}). They work with Comparator and Iterator in a consistent way. There is symmetry and unity. I don't even remember the C# analogues, but my recollection is that sometimes they come with an interface, sometimes not, the names are messier, generics are less consistent, and there isn't a unified way to get immutable versions etc. I don't think C#'s collections were that bad, and probably people here can correct my memory about some of the above, but they weren't as clean, and to me that was a motif throughout the framework. A messy collections API is no big deal really, but when it's the same story for I/O, networking, GUI, etc. . . . (I do think layout was a lot easier in WinForms than Swing though.) On balance I'd take C#'s rapid evolution over Java's slowness, but what Java got from its conservatism was purity and low cognitive overhead, which as a working programmer was pretty nice. That said, it'd still be really cool if I could write Rails apps in C# on Linux. With vim. :-)
- usea 12y agoIn C#: IList<T>: implemented by List<T> and T[] (arrays) ISet<T>: implemented by HashSet<T> and SortedSet<T> IDictionary<T,U>: implemented by Dictionary<T,U> all implement ICollection<T> and IEnumerable<T>. In the case of dictionary, it implements ICollection<KeyValuePair<T,U>>, IEnumerable<T> (.Keys) and IEnumerable<U> (.Values), etc It's all basically the same thing. Organized and unified. IList<T> is actually implemented by a lot of things, and the more general you go, the more things implement it. IEnumerable just allows you to get an iterator that will go through the elements. ICollection adds the ability to add and remove elements. IList further adds indexed access and order. The generic collections and operations on them are one of the best aspects of C# and the standard lib.
- pjungwir 12y agoThank you for your correction! I am still suspicious that there is some forgotten weirdness lurking in there, but I'm glad someone didn't let me propagate my mistaken recollections unanswered. :-)
- twic 12y ago> All are Collections. Except Map. See the section in the Java Collections API Design FAQ [1] on "Why doesn't Map extend Collection?". [1] http://docs.oracle.com/javase/8/docs/technotes/guides/collections/designfaq.html#a14 http://docs.oracle.com/javase/8/docs/technotes/guides/collec...
- pjungwir 12y agoHa ha, I knew I shouldn't have answered that question. :-)