When you say for example filter odd numbers, does it mean you remove odd numbers or actually keep them and remove everything else?

Context: when I want to name some functions which do filtering, I always wonder, do I need to name the part it will remove, or part that it will keep. For example I want to keep only numbers in a string. So should I say filter_numbers or filter_non_numbers?

  • 2
    Your two paragraphs ask two different questions. Frame challenge on your first question. A process which reads a set S and writes just the odd numbers in S isn't filtering odd numbers or filtering everything but odd numbers, it's filtering S. The direct object of the verb "filter" is the input, not the output. Frame challenge on your second question. Consider names which don't contain the word "filter". For example, if your function reads a string and writes the result of keeping only the digits, perhaps call it something like digits_in_string.
    – Rosie F
    Oct 7, 2022 at 8:08
  • @RosieF thanks for suggestions!
    – Andrius
    Oct 7, 2022 at 8:11

1 Answer 1


Well, based on as if through a filter (Merriam-Webster), filtering something means removing it. But if we change our perspective, filtering something can also mean keeping the things or items we want.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.