[Baypiggies] padding variable assignments, why is it bad?
simeonf at gmail.com
Fri Aug 10 21:23:40 CEST 2012
On Fri, Aug 10, 2012 at 12:01 PM, Wai Yip Tung <tungwaiyip at yahoo.com> wrote:
> Imagine your have some code like this
> row.name = encode(src.get('name'), 'xmlref')
> row.description = encode(src.get('description'), 'xmlref')
> row.enabled = encode(src.get('enabled'), 'xmlref')
> row.last_access = encode(src.get('last_access'), 'xmlref')
> This looks a mumbo jumbo lines of code.
I tend to think that repetition like that in my code indicates code that
can be refactored rather than just spaced better. Eg:
>>> for name in ['name', 'description', 'enabled', 'last_access']:
>>> setattr(row, name, encode(src.get(name), 'xmlref')
which makes it even more obvious that what is happening is the same thing
repeated over a list of names...
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Baypiggies