You can convey a lot about a function’s purpose with its name, much like that of a variable. Here are some guidelines – not hard-and-fast rules – about how you should name subroutines.


  1. If they’re primarily about performing an activity, name them with a verb, for example, summarize or download.
  2. If they’re primarily about returning information, name them after what they return, for example, greeting or header.
  3. If they’re about testing whether a statment is true or not, give them a name that makes sense in an if statement; starting with is_… or can_… helps, or if that isn’t appropriate, name them with an adjective: for example, is_available, valid, or readable.
  4. Finally, if you’re converting between one thing and another, try and convey both things. Traditionally this is done with an 2 or _to_ in the middle: text2html, metres_to_feet. That way you can tell easily what’s being expected and what’s being produced.

Above excerpted from “Beginning Perl“, by Simon Cozens,

technology/programming/functionnaming.txt · Last modified: 01.12.2009 23:58 by
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki