Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75312

Re: one to many (passing variables)

From "Neil D. Cerutti" <neilc@norwich.edu>
Subject Re: one to many (passing variables)
Date 2014-07-28 09:34 -0400
References <CAHXoDSB+-Vkggfd57nb9eLSK7Pb_fbuycGTJZM=+6=4VZo3F0w@mail.gmail.com> <8561innkmw.fsf@benfinney.id.au> <53D308CB.8030900@cdreimer.com>
Newsgroups comp.lang.python
Message-ID <mailman.12388.1406554496.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 7/25/2014 9:47 PM, C.D. Reimer wrote:
> Thank you for the link. I'm curious about one item mentioned in the
> article: "Avoid return values that Demand Exceptional Processing: return
> zero-length array or empty collection, not null"
>
> Isn't a zero-length array, empty collection and null all the same thing?
>
> Or does the "Demand Exceptional Processing" comes from testing to see if
> the object is empty versus being null?

This seems like a specific application of a more general rule (I think I 
remember it from The C Programming Language by Kernighan and Ritchie): 
Whenever possible, manage special cases with data rather than with code. 
Doing so makes your data processing code simpler, and may help prevent 
errors.

This should apply to any programming language.

A mundane example is managing multi-line street addresses in a system 
storing addresses: most applications choose to store address lines as 
Street Address 1, through Street Address N, for some finite value of N, 
even though it results in special cases to handle. This is probably 
because it is more efficient: non-normalised data can be an efficiency 
win. Also, forgetting or refusing to handle the case of multi-line 
street addresses works "well enough" most of the time.

You could instead store multi-line street addresses as a list of 
components in the street address: Forgetting to handle the "special 
cases" would then be impossible. In order to do a cheesy job you'd have 
to explicitly retrieve street_address[0] and ignore the rest.

-- 
Neil Cerutti

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: one to many (passing variables) "Neil D. Cerutti" <neilc@norwich.edu> - 2014-07-28 09:34 -0400

csiph-web