Re: Appropriate Name Question
On Apr 12, 12:27 am, r...@zedat.fu-berlin.de (Stefan Ram) wrote:
blargg....@gishpuppy.com (blargg) writes:
void delete_files(); // verb phrase: functions that do something
void disk_count(); // noun phrase: function that returns value
=BBProcedure names should reflect what they do;
function names should reflect what they return.=AB
Rob Pike; =BBNotes on Programming in C=AB; February 21, 1989
That's actually not too bad, but only if you understand the
distinction between "procedure" and "function" at an abstract
level: a function returns a value, and does nothing else
(doesn't modify state---with the possible exception of things
like rand()). Formally, the Posix function read is a function,
not a procedure, but I wouldn't like to see it named "count",
even if that's what it returns. (Conceptually, it's a
procedure, of course---it does something, and the value it
returns is, in many ways, incidental.)
There's also the convention that predicate functions start with
"is", "are" or "has". This is very necessary if symbol names
are based on English, since it's often ambiguous whether
something is a verb or not, e.g.: a function named "isEmpty"
clearly returns true if whatever is empty; a function named
"empty" probably empties something. (And yes, the standard
library is full of bad examples.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34