I just came into two functions of class Set
of Scala: head
to return the “first” element of the set, and last
to return the “last” element. Clearly, this is a case of unfortunate design. Since the elements of a set are not ordered, there is neither a first one nor a last one. I wonder why the Scala team made this design.
Although the documentation warns that the functions may return different values at different runs, I bet a lot of programmers still make the mistake of assuming the result of the functions would be stable. Pretty dangerous!
Tags: programming, scala, software design
Leave a comment