4 ms·
> It’s foolish to say that just because a data structure superficially satisfies some API (like being passable to min), that it “ought to have” some behavior th
by dnautics 8y ago
> It’s foolish to say that just because a data structure superficially satisfies some API (like being passable to min), that it “ought to have” some behavior that the author wants.
I disagree. There is also a concept of "principle of least surprise". To take an extreme example, let's say you wrote a standard library where push!(array, item) actually takes the array and deletes it. Would it be foolish to say this is bad design because it shouldn't "ought" to have some behavior, it's up to the user to know what's going on under the hood?
- bvrmn 8y agoThere is no surprise in passing iterator and it's exhausting.
- mlthoughts2018 8y agoThat’s a silly abuse of the idea of least surprise. Documented, long-lived built-in data structures like generators that support behavior like exhaustion and mutation in a time-tested way are _clearly_ not some kind of surprising and useless or pedantic quirk. I mean, consider implicits in Scala. It’s hard to think of a worse violation of least surprise, but because it’s documented and time-tested and becomes a de facto standard in that language, the argument of least surprise becomes nothing but a preference debate. The behavior where max raises an exception on an exhausted generator is not at all surprising, from the point of view of language documentation, ubiquitous and popular advice on that data structure, etc. etc. And besides all that: if you did happen to find a serious design bug that created a surprise problem, there are tons of ways to solve that problem in a dynamically typed language that wouldn’t require static typing or borrow checking or any explicit state management. It still would not be evidence that those things are a superior way to solve it.