4 ms·
> I'm calling the high level sortDisplayedItems, (or sort_displayed_items) and there's a low level function that ACTUALLY sorts them (as opposed to handling the
by gknoy 11y ago
> I'm calling the high level sortDisplayedItems, (or sort_displayed_items) and there's a low level function that ACTUALLY sorts them (as opposed to handling the other bits).
You're absolutely right: naming things is hard. When I was writing Scheme long ago [in university], our convention was to name helper functions with `-helper` in the name:
sort-foos
sort-foos-helper
sort-foos-merge-helper
Now that I write mainly in Python, the convention seems to be to use underscores to indicate things that you should ignore. Usually that's done at a method level, where your consumers are calling the object's public API (sort), so the object's namespace helps reduce such name collisions. The addition of triple-quote docstrings for method comments helps a lot at clarifying purpose as well:
class FooSorter(object):
def sort(self, foos):
"""Sort an iterable of Foo objects"""
# ... sanity-check inputs ...
self._sort(foos) # do the sort operation
def _sort(self, foos):
"""
Sort things we already know are Foo objects.
This is a helper for sort(), which already
sanity-checked our inputs.
"""
# do the actual sorting