2 ms·
Concrete example: Many languages's standard libraries have stuck methods for mutation into the base interface for collections of objects. This makes it awkward
by bunderbunder 9y ago
Concrete example:
Many languages's standard libraries have stuck methods for mutation into the base interface for collections of objects. This makes it awkward (at best) to try and use immutable collections. Either you create your own base interface, which makes you incompatible with the rest of the standard library, or you inherit the standard interface and then do something like throw an exception when someone attempts to mutate your collection, and just hope that never happens in production.
- d--b 9y agoExactly the example I've written in my other comment... I guess many people have been bitten by this!
- bunderbunder 9y agoIt seems like a pretty ubiquitous problem. I feel like it's actually just about the least painful in C#, since pretty much every collection interface derives from IEnumerable<T>. It doesn't define have methods for random access or getting the size of the collection, but it is at least immutable, so you can get away with using it quite a bit, maybe even most of the time. In Java, on the other hand. . . woof.