is there any principle when writing python function
gordon at panix.com
Fri Aug 26 11:40:40 EDT 2011
In <7b47ca17-d3f1-4d91-91d1-98421e8708cd at ea4g2000vbb.googlegroups.com> rantingrick <rantingrick at gmail.com> writes:
> Furthermore: If you are moving code out of one function to ONLY be
> called by that ONE function then you are a bad programmer and should
> have your editor taken away for six months. You should ONLY create
> more func/methods if those func/methods will be called from two or
> more places in the code. The very essence of func/meths is the fact
> that they are reusable.
That's one very important aspect of functions, yes. But there's another:
If I'm writing a module that needs to fetch user details from an LDAP
server, it might be worthwhile to put all of the LDAP-specific code in
its own method, even if it's only used once. That way the main module
can just contain a line like this:
user_info = get_ldap_results("cn=john gordon,ou=people,dc=company,dc=com")
The main module keeps a high level of abstraction instead of descending
into dozens or even hundreds of lines of LDAP-specific code.
John Gordon A is for Amy, who fell down the stairs
gordon at panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
More information about the Python-list