In Ruby, mutating methods (i.e. methods that modify self), by convention, marked bang (!), Separate them from similar methods that do not change self.
For example, it Array#sortreturns a sorted array, but Array#sort!changes the array on which it is called.
Now I began to study Swift. How can I name a mutating method to separate it from its non-mutating double?
I know that Python has sorted(list)vs list.sort(). Is this a good template i.e. .sorted()(not mutating) and .sort()(mutating)?
What about names that are not easily transformed in a way like String#nextvs String#next!?
source
share