[Python-ideas] Forward-References & Out-of-order declaration

Chris Angelico rosuav at gmail.com
Wed Aug 26 06:19:03 CEST 2015


On Wed, Aug 26, 2015 at 8:11 AM, Sven R. Kunze <srkunze at mail.de> wrote:
> The issue (not a huge problem again but annoying from time to time) is that
> the order of declaration in a module actually matters. IIRC other modern
> languages like C# don't require you do actually care about this anymore.
>
> Possible example (for whatever reason an author wants to do that -- also cf.
> stackoverflow):
>
> class UseThis(Base):
>     pass
>
> class UseThat(Base):
>     pass
>
> class Base:
>     pass
>
> In that regard, Python feels a bit rusty.

Frankly, I don't have a problem with this. You get a mandate that
requires you to do what's good practice anyway: lay things out in a
logical order. In the same way that Python's use of indentation for
block structure is generally just enforcing what you'd have done
regardless of language, this requires that you sort things in
dependency order. That tends to mean that the first use of any name in
a module is its definition/source. Want to know what 'frobnosticate'
means? Go to the top of the file, search for it.

Having that enforced by the language is a restriction, but how often
does good code have to be seriously warped to fit into that model? Not
often, in my experience.

ChrisA


More information about the Python-ideas mailing list