Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.bt.com!news.bt.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 18 Jul 2012 04:06:53 -0500 Date: Wed, 18 Jul 2012 10:06:51 +0100 From: Lipska the Kat User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20120410 Thunderbird/11.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.python Subject: Re: Encapsulation, inheritance and polymorphism References: <3vnfd9-343.ln1@satorlaser.homedns.org> <-8SdnVrXGqie25jNnZ2dnUVZ7qKdnZ2d@bt.com> <5005A103.9050802@stoneleaf.us> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Lines: 74 X-Usenet-Provider: http://www.giganews.com X-AuthenticatedUsername: NoAuthUser X-Trace: sv3-GooCqglh2M8ZhbJ8NJRD9BdJZ3Ei8R6QWN7Km7UKDcWwF0Oa4kCSf1HxiejpbobhLitXD4BajpZfEXi!ILv+UVaR6ZkqJK/9dxey1TINBoK2Ph/onqgrXZivlJQ8XDSUXM9s92/oFenr7qhDGyUBgTpggBg= X-Complaints-To: abuse@btinternet.com X-DMCA-Complaints-To: abuse@btinternet.com X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3292 Xref: csiph.com comp.lang.python:25561 On 18/07/12 01:46, Andrew Cooper wrote: > On 17/07/2012 19:36, Lipska the Kat wrote: >> On 17/07/12 19:18, Mark Lawrence wrote: >>> On 17/07/2012 18:29, Ethan Furman wrote: >>>> Terry Reedy wrote: >>>>> On 7/17/2012 10:23 AM, Lipska the Kat wrote: >>>>> snip > > Take for example a Linux system call handler. The general form looks a > little like (substituting C for python style pseudocode) > > if not (you are permitted to do this): > return -EPERM > if not (you've given me some valid data): > return -EFAULT > if not (you've given me some sensible data): > return -EINVAL > return actually_try_to_do_something_with(data) > > How would you program this sort of logic with a single return statement? > This is very common logic for all routines for which there is even the > remotest possibility that some data has come from an untrusted source. Eeek! well if you insist (type bound) someType -EPERM someType -EFAULT sometype -EINVAL someType -EDOSOMETHING //method someType checkSomething(data){ someType result = -EINVAL //or your most likely or 'safest' result if not (you are permitted to do this): result = -EPERM if not (you've given me some valid data): result = -EFAULT if not (you've given me some sensible data): result = -EINVAL else result = -EDSOMETHING return result } //cohesive, encapsulated, reusable and easy to read //later if(checkSomething(data) == EDOSOMETHING){ actually_try_to_do_something_with(data) } else{ //who knows } What do you think ? > > ~Andrew > > P.S. like the sig. thanks -- Lipska the Kat: Troll hunter, Sandbox destroyer and Farscape dreamer of Aeryn Sun.