Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Dan Sommers Newsgroups: comp.lang.python Subject: Re: Status of side-effecting functions in python Date: Sun, 26 Oct 2014 13:41:23 +0000 (UTC) Organization: A noiseless patient Spider Lines: 23 Message-ID: References: <438d510f-05ae-47dd-bcda-42a8b777c99b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Injection-Date: Sun, 26 Oct 2014 13:41:23 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="7afa85ad1f051434641aa58aa18198d3"; logging-data="21691"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OASQs9DX6yxX/zznsxPNMw98saJfA/bs=" User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508 git://git.gnome.org/pan2) Cancel-Lock: sha1:WwhlCCMqUSrYdhkkYD8i8M5a8bo= Xref: csiph.com comp.lang.python:79714 On Sun, 26 Oct 2014 00:45:49 -0700, wxjmfauth wrote: > Ditto for .write(). Why should it return "something" ? > >>>> with open('z.txt', 'w') as f: > ... f.write('abc') > ... > 3 OTOH, why shouldn't it return something? In this case, it returns the length of the string written. This value is analogous to the value returned by the underlying OS function (at least on a POSIX-like system, where write(2) returns the number of bytes written). This value can be useful for detecting when things have gone wrong; e.g., disk full, network down, pipe broken, etc. Practicality definitely beats purity. At one time, on a huge project, millions of lines of C and assembly code, we had a local guideline *not* to write void functions. The idea was to return something that might be useful later, even if it seemed unlikely now. A simple success flag was sufficient; as functions grew, often did their failure modes. Dan