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

Juan Pablo Romero Méndez jpablo.romero at gmail.com
Tue Aug 9 16:51:23 EDT 2016


2016-08-09 13:18 GMT-07:00 Rob Gaddi <rgaddi at highlandtechnology.invalid>:

> 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.
>


So as the writer of the function you expect the user to read the function
body to determine what is safe to pass or not?



>
> --
> Rob Gaddi, Highland Technology -- www.highlandtechnology.com
> Email address domain is currently out of order.  See above to fix.
> --
> https://mail.python.org/mailman/listinfo/python-list
>



More information about the Python-list mailing list