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

Dave Peticolas dave at krondo.com
Sat Aug 11 00:59:05 CEST 2012


2012/8/10 Duncan McGreggor <oubiwann at twistedmatrix.com>

>
>
> On Fri, Aug 10, 2012 at 2:52 PM, David Berthelot <
> david.berthelot at gmail.com> wrote:
>
>> So far I only read 1 pro, 1 con:
>> pro: readability (aligned variables make it clear)
>> con: vcs history can get confusing when looking for who changed a line
>>
>> So may be it's time for vcs tools to evolve and become language aware.
>> Readability was historically pythonic otherwise why rely on
>> indentation instead of curly braces ?
>>
>
>
> But readability means different things to different people. Python is
> highly readable for me due to the initial white space for indented code
> blocks.
>
> Reading                        something                            like
>                      this                     is not              highly
>                readable  for      me.
>
> Though I could certainly imagine that it would be for some folks...
> different tastes and all that.
>
> Code blocks help define scope visually. Column-aligned code does not serve
> the same purpose. When I read a list of variables, I get no additional
> information from the spacing of them. I also don't read variables
> vertically. I read them like I do English, from left to right. Large gaps
> of white space between the "words" is much less readable *for me* ;-)
>

Agreed! And, for that same reason, I think one of the (few) places where
column-aligned assignments makes is when you are defining, say, a set of
enumerated constants where the specific mapping of names to numbers is less
important than the fact that they are all different. Aligning the values in
a column highlights that fact and makes it easy to see what the next
constant should be. But for most assignments it is is the left-to-right
relationship that is more important and column-alignment obscures that, I
think.



> d
>
>
>>
>> On Fri, Aug 10, 2012 at 2:34 PM, Duncan McGreggor
>> <oubiwann at twistedmatrix.com> wrote:
>> >
>> > 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.
>> >>
>> >> 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
>> >>
>> >
>> > In addition to the other problems with this, you have another problem:
>> > you've now got a separate coding standard for variables than you do for
>> > other code blocks. White space in Python is syntactically meaningful
>> > *initially* not in the middle or the end. You've just made it meaningful
>> > (and dependent upon the length of the longest variable name) *medially*
>> and
>> > that's not Python.
>> >
>> > I actually find code that is column-aligned like that to be highly
>> > distracting. I find regular, PEP-8 code to be much more highly
>> readable. And
>> > there was a time in the 90s when I was writing column aligned variables
>> (for
>> > a short while!). Readability at the level of white space is simply a
>> matter
>> > of getting used to (people that hate it enough usually don't end up
>> using
>> > Python, when given the choice).
>> >
>> > d
>> >
>> > _______________________________________________
>> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20120810/0a7e01fc/attachment-0001.html>


More information about the Baypiggies mailing list