[Baypiggies] padding variable assignments, why is it bad?

Mark Voorhies mvoorhie at yahoo.com
Fri Aug 10 21:46:55 CEST 2012


On 08/10/2012 12:22 PM, Wai Yip Tung wrote:
> I definitely place high priority to keep the code readable than to keep the
> source control history neat. Lot more time and people will be reading code than
> researching the source code history. Overly obsess about source history hygiene
> may not be the best thing.
>
> Wai Yip

For large projects, I actually find that the history (e.g., viewed with 
gitk) is the easiest place to orient myself and that, when I do start
reading the source itself, it's really useful to apply history-based 
highlighting (e.g., with vc-annotate in emacs, a.k.a. "red bugs mode").

In the rare cases where formatting gets in the way of readability, it's
easy to generate a local copy with my preferred formatting.  The 
opposite (stripping line noise from an existing history) is much harder.

With the growth of GitHub, Google code, etc., I think that
"vcs as primary view" is becoming increasingly common.

--Mark

>
>> Kalb, Jon <mailto:jonkalb at a9.com>
>> Friday, August 10, 2012 12:13 PM
>> Imagine that I'm trying to do research in the source code repository on how,
>> when, and who modified "last_access." I see that a change was made to the the
>> last line in your example, but after wasting some of my time investigating it,
>> I discover that the only reason the line was touched was because a new member
>> with a long name was added and that caused this line to be touched to change
>> its white space.
>>
>> Treating lines of code independently has important advantages when "diff"ing
>> and tracing changes throw source code repositories.
>>
>> From: Wai Yip Tung <tungwaiyip at yahoo.com <mailto:tungwaiyip at yahoo.com>>
>> Date: Friday, August 10, 2012 12:01 PM
>> To: "baypiggies at python.org <mailto:baypiggies at python.org>"
>> <baypiggies at python.org <mailto:baypiggies at python.org>>
>> Subject: Re: [Baypiggies] padding variable assignments, why is it bad?
>>
>> 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.
>>
>> However by aligning them into columns, the pattern become immediately obvious.
>>
>> 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')
>>
>> It is clear that the code is applying similar operation on 4 items. It is a
>> lot easier to tell which of the 4 elements and if you should include more or
>> less into the list. It is a huge visualization improvement. PEP-8's suggestion
>> on this is not a good one in my opinion.
>>
>> The down side is it takes some effort to keep it neat and tidy. Of course I
>> have editor macro that does that. I think every decent text editor should have
>> some function to help people to align things.
>>
>> Wai Yip
>>
>>
>>
>>
>> Wai Yip Tung <mailto:tungwaiyip at yahoo.com>
>> Friday, August 10, 2012 12:01 PM
>> 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.
>>
>> However by aligning them into columns, the pattern become immediately obvious.
>>
>> 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')
>>
>> It is clear that the code is applying similar operation on 4 items. It is a
>> lot easier to tell which of the 4 elements and if you should include more or
>> less into the list. It is a huge visualization improvement. PEP-8's suggestion
>> on this is not a good one in my opinion.
>>
>> The down side is it takes some effort to keep it neat and tidy. Of course I
>> have editor macro that does that. I think every decent text editor should have
>> some function to help people to align things.
>>
>> Wai Yip
>>
>>
>>
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>
>
>
> _______________________________________________
> Baypiggies mailing list
> Baypiggies at python.org
> To change your subscription options or unsubscribe:
> http://mail.python.org/mailman/listinfo/baypiggies
>




More information about the Baypiggies mailing list