[Tutor] functions--how long is too long?
Kent Johnson
kent37 at tds.net
Tue Dec 8 04:08:23 CET 2009
On Mon, Dec 7, 2009 at 8:37 PM, Che M <pine508 at hotmail.com> wrote:
> I have some functions that seem kind of long to me. One of them, with
> white space, comments, print statements, and some commented-out lines,
> is 118 lines long. If I remove all that, it is 57 lines long. I get the
> sense
> that is inappropriately long for a Python function.
>
> The length of it is due to a number of if statements--things it needs to
> check in terms of the state of the app at the time it is called. So there
> are a number of conditional (and "subconditional") parts to it, and what
> it does in response to those conditions. In fact the word "if" appears in
> it 12 times.
Perhaps you can extract some functions from the blocks that make up
the if statements, or move some of the conditionals themselves into
functions. Without seeing some code it is hard to be specific.
Kent
More information about the Tutor
mailing list