For review: PEP 308 - If-then-else expression

Paul Moore gustav at morpheus.demon.co.uk
Sun Feb 9 08:42:17 EST 2003


Paul Rubin <phr-n2003b at NOSPAMnightsong.com> writes:

> Think of how you actually call get_arg:
>
>     a = x.get_arg()
>
> In order to read that line you have to actually go check the
> definition of get_arg.

Only if get_arg is badly named (ie, it isn't obvious what it does from
the context and the function name). I'm not saying that badly named
functions don't exist (heck, I'm not good at picking names for things)
but I'm sick of people pointing at examples which use badly named or
out of context functions and use that as a justification for putting
the code inline.

You are aware of the concept of "encapsulation", I assume...?

> The conditional expression (maybe) simplifies your code, not by
> shortening the get_arg function, but by eliminating it.  You'd
> instead say
>
>    a = self.arg if (self.arg is not None) else 1
>
> or whatever.

OK. So let's remove function definitions from the language. Write all
code inline - it simplifies your code (you just said so!)

> Maybe that syntax is clumsy but it still seems preferable to having
> to scroll to some method definition several screens away in order to
> find a 4-line function definition that needs 3 lines of
> documentation to explain what it's doing.

Any function that simply encapsulates a conditional expression can
probably be documented by simply choosing an appropriate name. So you
don't *need* to look for the definition.

Paul.
-- 
This signature intentionally left blank




More information about the Python-list mailing list