Friday Finking: Source code organisation
DL Neil
PythonList at DancesWithMice.info
Sat Dec 28 21:32:18 EST 2019
>>> "Define before use" is a broad principle that I try to follow, even
>>> when the code itself doesn't mandate this.
>
> IMO it makes the code easier to navigate even when it's not strictly
> necessary. As others have said, Python mandates that the functions be
> defined before they're CALLED, but I find that it's worth being
> stricter. As a general rule, any global name in my code (that includes
> constants, module-level functions, etc, etc) will have its definition
> as the textually-first instance of that name. Or, at worst, the first
> instance will be a comment immediately above the definition.
('Anonymised' because this is not 'aimed' at any particular individual)
I was somewhat amused at being 'corrected' in the "defined" cf "called"
discussion. The 'corrections' are more precise. However such
distinctions are machine-related, ie how does the Python interpreter behave?
The central topic of this (ideally, thought-provoking) discussion, is on
the person (not the machine). Yes, the author. Although, if you
subscribe to the philosophy that program(me)s should be written with
human-readers in-mind, then the likes of "beauty is in the eye of the
beholder" and "readability counts", apply!
Various 'gurus', probably even before the Agile/Gang-of-Four/OOP, have
talked of code craftsmanship having a number of characteristics. One of
which is that *my* code should appear pretty-much as *you* expect the
solution. When we were asked to discuss this, over-the-teacups (on
Friday, hence the "FF" moniker) the young fellow's question was phrased
"what do you guys expect [from me]".
(yes, he was quoting/abstracting from 'Uncle Bob' and "Clean Code"
[Prentice-Hall, 2009]).
We have a number of 'what do you expect'-s in Python. For example, there
is no "law" saying that we must use "self" within classes. Other
languages use similar but alternate terminology, eg "this". I could
decide to use "dn_was_here" and the interpreter will be perfectly happy
- but because you don't expect it and would be made to (unnecessarily)
comprehend, I doubt it would promote our friendship/mutual-respect!
So, do you hold any 'expectation' relating to the organisation of class
methods?
--
Regards =dn
More information about the Python-list
mailing list