[Tutor] Re: Re: working code for adding line numbers -- request
denis.spir at free.fr
Mon Apr 19 14:15:49 EDT 2004
----- Original Message -----
From: Andrei <project5 at redrival.net>
To: <tutor at python.org>
Sent: Monday, April 19, 2004 3:15 PM
Subject: [Tutor] Re: Re: working code for adding line numbers -- request
> I agree there :). I don't quite agree with your choice of abbreviation
> "source" part is IMO more important than the "filename" part, yet the
> "source" is abbreviated to one letter, while the other part remains
> I'd rather use something like "sourcefn"/"source"/"sourcefile" than
> "sfilename", but it's not that bad - it would be bad if you'd named it "x"
> or something :)).
> This point is related to comments, since good variable names prevent the
> need for some comments. The line "source = getfilename()" makes it
> immediately clear that source is a file name of a source file, there's no
> need to comment the obvious - unless of course the getfilename method
> doesn't do what its name suggests :).
> One could argue that variable names which need comment to be explained
> aren't good names, but I'm not sure that's true in all cases :).
I agree there too :-)
Will just add that it's often useful to know what kind of object is hidden
behind the variable name. e.g. in your 'source' may be (supposed you know it
has something to do with a file !) the file object, the file name or the
data themselves -- and you may well need the three of them in the same piece
To avoid confusion, I use type (in the usual sense, not technical)
prefixing. In that case : fnSource or fn_source. I have a whole set of
semi-standard prefixes. Some of them beeing doubled, like n- or nbr- for
number (in the sense of a cardinal), i or num (french : numéro) for an index
(ordinal). But of course none has two meanings.
It's easier in french cause the "typing" words naturally come before the
"meaningful" words : "nom du fichier source" instead of "source file name".
But you can think at it as "file name of the source".
It may be strange but these prefixes don't lower the readibility -- once you
know they're prefixes. I don't see them unless I need them. Probably the
separations (capital letter or underscore) play their role properly.
More information about the Tutor