Managing import statements

Shane Hathaway shane at hathawaymix.org
Sat Dec 10 14:05:59 EST 2005


Chris Mellon wrote:
> On 12/10/05, Shane Hathaway <shane at hathawaymix.org> wrote:
>>I'm surprised this problem isn't more familiar to the group.  Perhaps
>>some thought I was asking a newbie question.  I'm definitely a newbie in
>>the sum of human knowledge, but at least I've learned some tiny fraction
>>of it that includes Python, DRY, test-first methodology, OOP, design
>>patterns, XP, and other things that are commonly understood by this
>>group.  Let's move beyond that.  I'm looking for ways to gain just a
>>little more productivity, and improving the process of managing imports
>>could be low-hanging fruit.
> 
> It is probably because most people don't regularly switch that much
> code around, or use that many modules. I think the fact that you move
> that much code between modules is probably a code smell in and of
> itself - you're clearly moving and changing responsibilities.
> Refactoring in smaller chunks, less extreme refactoring, correcting
> the imports as you go, and avoiding inline imports without a really
> good reason will probably help you a lot more than a new syntax.

That's an insightful suggestion, but I'm pretty sure I'm doing it right. 
:-)  I fill my mind with the way the code should look and behave when 
it's done, then I go through the code and change everything that doesn't 
match the picture.  As the code moves closer to production and bugs 
become more expensive, I add a step to the process where I perform more 
formal refactoring, but that process takes much longer.  The problems 
caused by the informal process are less expensive than the formal process.

> Yes. Spend an afternoon looking at PyLints options, get rid of the
> stuff you don't like, and use it regularly. PyDev has PyLint
> integration, which is nice.

Ok, thanks.

> I don't think I've ever imported more than a dozen modules into any
> given file. I rarely find it neccesary to move huge chunks of code
> between my modules - the biggest such I did was when I moved from a
> single-file proof of concept to a real modular structure, and that
> only took me an hour or so. If I'd done it modularly to start with it
> would have been fine.

Well, code moves a lot in the immature phases of large applications like 
Zope and distributed systems.

Shane



More information about the Python-list mailing list