On Sun, Dec 29, 2019 at 10:56 AM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
>
> On 29/12/19 11:49 am, Chris Angelico wrote:
> > "Define before use" is a broad principle that I try to follow, even
> > when the code itself doesn't mandate this.
>
> I tend to do this too, although it's probably just a habit
> carried over from languages such as Pascal and C where you
> have to go out of your way to get things in a different
> order.

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.

> But strangely, I tend to do the opposite for methods of
> a class. I don't really know why. My instinctive idea of
> the "right" ordering just seems to flip over somehow
> between modules and classes.

That's curious. I have a similar sort of inversion in that __init__ is
usually going to be up the top (even though main() would be at the
bottom), although not a complete inversion: anything that __init__
calls will still go above it.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to