Thursday 9 September 2010 14:15
It was recently pointed out to me (unfortunately, I can't remember where) that a good way to distinguish functional and procedural versions of similar functions is to use adjectives for the functional version and verbs for the procedural version.
For instance, consider functions that sort a list. The functional version would be called
sorted, and returns a sorted copy of the list:
some_list = [2, 0, 1] sorted_list = sorted(some_list) # some_list == [2, 0, 1], sorted_list == [0, 1, 2]
On the other hand, the procedural function would be called
sort, and modifies the list in-place:
some_list = [2, 0, 1] sort(some_list) # some_list == [0, 1, 2]
This is probably obvious to everybody else, but I'd never really thought it too much before.
Topics: Software design