What's the best way to minimize the need of run time checks?

Rob Gaddi rgaddi at highlandtechnology.invalid
Tue Aug 9 16:18:34 EDT 2016


Juan Pablo Romero Méndez wrote:

> 2016-08-09 12:06 GMT-07:00 Paul Rubin <no.email at nospam.invalid>:
>
>> Juan Pablo Romero Méndez <jpablo.romero at gmail.com> writes:
>> > In online forums sometimes people complain that they end up having to
>> > test constantly for None
>>
>> That's something of a style issue.  You can code in a way that avoids a
>> lot of those tests (not all of them).
>>
>
>
> This is exactly what I'm looking for :).  Do you have any resource (blog /
> book, etc) that discusses this style?
>

It's not a style, it's the absence of one.

def add2list(lst, elem):
    lst.extend([elem, elem])
    return lst

I did all the type checking I needed to there; none whatsoever.  If
passed a list, or something that behaves like one, that does the
expected thing.

If passed an ExtensionLadder, it probably does the wrong thing, but that
is no way my problem.

-- 
Rob Gaddi, Highland Technology -- www.highlandtechnology.com
Email address domain is currently out of order.  See above to fix.



More information about the Python-list mailing list