When should a method with a present vs past participle be called, i.e., sorting vs, sorted or reversed or reversed?
Scala have a mutable Array class . It has methods sorted
and reverse
, from which it returns a new mutable array with the same elements in some order.
Is there some reason to have different forms for method names? Why is sorted
n't it called sort
? Or why reverse
, sortBy
etc. Not called reversed
, sortedBy
?
source to share
It's historical. Before collections were redesigned in 2.8, some collections had a method ( like a list ) called sort
. In 2.8, it was sort
deprecated and its functionality was placed in sortWith
, and sorted
was added to sorting without an explicit parameter.
You can imagine a principled way to do this (for example, use the past tense when creating a new collection, but when changing a mutable), but that's not exactly how it works. You just have to remember the little wrinkles for now at least.
source to share