4 ms·
I only programmed .NET in the days of 2.0, so my problems with it come from an older less capable framework. Nonetheless, when your language of choice requires
by iskander 16y ago
I only programmed .NET in the days of 2.0, so my problems with it come from an older less capable framework. Nonetheless, when your language of choice requires you to distinguish between:
- IComparable
- IComparable(Of T)
- IEquatable(Of T)
- IStructuralEquatable
- IStructuralComparable
- IEqualityComparer
- IEqualityComparer(Of T)
- IComparer(Of T)
- overriding Object.Equals
- overriding operators <,>, <=, >=, =, <>
...it's time to find a new language.
edit: Just imagine you encounter a new collection BozBag(Of T) which has to test your objects for equality. Without looking at documentation could you as a coder possibly know if BozBag uses x.Equals(y), x = y, x.CompareTo(y) = 0? Heck it could even use x.Equals(DirectCast(y,Object)) or x.CompareTo(DirectCast(y,Object)). The only way to really know is to dig through documentation.
- snprbob86 16y agoSaying that you need to understand and differentiate between all of these is disingenuous. - The "Structural*" types are new in .Net 4.0, you never had to understand them before and you probably don't need to even know they exist now. - Many of these listed are just generic vs non-generic. The generic ones subclass the non-generic ones, so contraviance eliminates the need to really understand the distinction upfront. - Compare means Compare(a,b):int which returns -1, 0, 1. - Equals means Equals(a,b):bool - If it ends in "er" it is a functor which operates on two free objects instead of "able" which means one subject of comparison is "this". - Overriding individual operators gives you more flexibility than Compare(a,b):int because you can use specific algoritms for specific comparisons. Maybe it's time to find a new arbitrary reason to hate .NET?
- iskander 16y ago>- The "Structural*" types are new in .Net 4.0, you never had to understand them before and you probably don't need to even know they exist now. You're right, I scooped those off MSDN and never use them myself. All the others, however, have made numerous appearances in my code. I think that the preponderance of comparisons is a language smell-- it's not close to my only problem with .NET development but I think it captures the essential headache-inducing inelegance of C#/VB programming. That language-blob has little regularity but much accretion. There are rarely sane defaults nor any overarching design for your mind to latch onto. After time spent with saner languages (Python, Haskell, Ruby, OCaml, etc...) coding in .NET feels terrible.
- snprbob86 16y agoJava also has Comparer and Comparator in both generic and non-generic flavors. Java lacks Equatable, which is a problem. Haskell, for example, has both Eq and Ord. It is frequently possible and convenient to be able to implement Eq in terms of Ord and part of Ord in terms of Eq, but these are orthogonal concepts. As someone who has done A LOT of professional C# development: I've found that with only a few exceptions, the .NET base class libraries are very well designed with entirely reasonable defaults. I use Python primarily now and, in general, the core .NET libraries seem to be better designed than most of the older Python libraries (many of which are getting properly cleaned up in Python 3). Every environment has its cruft.