Splitting up large python module impact on performance?

Cameron Simpson cs at cskk.id.au
Wed Jun 13 00:08:35 EDT 2018


On 13Jun2018 13:35, Chris Angelico <rosuav at gmail.com> wrote:
>On Wed, Jun 13, 2018 at 1:23 PM, Rick Johnson
><rantingrickjohnson at gmail.com> wrote:
>> Bill Deegan wrote:
>>> I'm doing some refactoring on a fairly large python
>>> codebase. Some of the files are > 4000 lines long and
>>> contain many classes.
>>
>> I would argue that files of such size are a total pain to
>> navigate and thus, edit. I prefer to place only one -- or
>> only a handful of classes -- in each file. One class per
>> file is _most_ preferred. But if you have a small group of
>> classes that are closely dependent on one another, and, the
>> source definitions can fit comfortably in a single file,
>> well then, i say do it. You just have to decide what is
>> comfortable for _you_; your coworkers; and anyone who may be
>> forced to maintain your code in the future.
>
>A few thousand lines in a file is only a problem if you're using an
>editor that lacks a Find feature. Or if you use bad function/class
>names that you can't search for.

I was going to say something along these lines, but to some extent this feels 
like an unfair finger pointing exercise. Huge files can be a PITA; having 
something that aids moving around them reduces the pain, but doesn't remove the 
fact that sometimes something is too big.

The flip side is that editor support is amazingly important, or amazingly 
useful.

I'm a long time vi user, and its tags feature is outstandingly useful (go to 
identifier, type ctlr-[, you're transported to the file and line defining it, 
with luck).  I recently spent some time updating my support for this, getting 
ctags to run whenever I save a file, with good context for what to tag and 
not).

Recently part of that movitation came from spending a year as a software 
engineer in a fast moving agile environment, and seeing first hand just how 
much an advantage good tooling can be. Editor support. Multiple panes, 
autoformat on save, vim extensions for finding files (big codebase, many many 
files in a deep tree).

Tools matter, it turns out.

>"""However, know when to be inconsistent -- sometimes style guide
>recommendations just aren't applicable."""
>
>> I may exaggerate on this a bit more if you're interested.
>
>Isn't it normal for you to exaggerate everything?

Shhh! Don't discourage his restraint!

Cheers,
Cameron Simpson <cs at cskk.id.au>



More information about the Python-list mailing list