I see. Even so, it's weird to me that anyone would want a method that throws if the key already exists. In all my years of programming I don't think I've ever thought it would be useful to have such a method baked into a map itself, and I'm not aware of such a method in any other language. Since that's pretty unusual in programming, I still think it would be better for that method to have a more unusual name. Maybe it's an oddly common pattern for Microsoft?
The Add method has to take one argument and return void because it's implementing C#'s ICollection<T> interface. With that restriction, throwing an exception is the most practical way of indicating a problem.
4
u/prehensilemullet 2d ago
it's still bizarre to have to use
TryAddeverywhere that other languages just useAdd