On Sat, Nov 26, 2016 at 5:40 AM, Edward K. Ream <[email protected]> wrote:
> On Friday, November 25, 2016 at 7:59:56 AM UTC-6, rengel wrote:
>
>> Why use two functions, when one suffices?
>>
>> def strip_lws(s):
>> return '\n'.join([z.lstrip() for z in s.splitlines(False)])
>>
>
> Beautiful. I'm going to make this change today.
All conclusions are provisional pending unit tests, which just failed ;-)
The present definitions, which do work, are:
def strip_lws(self, lines):
'''Strip leading whitespace from all lines.'''
return [self.lstrip_line(z) for z in lines]
def lstrip_line(self, s):
'''
Delete leading whitespace, *without* deleting
the trailing newline!
'''
# This fixes a major bug in strip_lws.
assert s, g.callers()
return '\n' if s.isspace() else s.lstrip()
The following does *not* work:
def strip_lws(self, lines):
'''Strip leading whitespace from all lines.'''
return [z.lstrip() for z in lines]
but it could be recast:
def strip_lws(self, lines):
'''Strip leading whitespace from all lines.'''
return ['\n' if s.isspace() else s.lstrip() for z in lines]
And this has just passed all importer unit tests. In short, we are getting
to matters of style. Imo, this:
return [self.lstrip_line(z) for z in lines]
is slightly preferable to:
return ['\n' if z.isspace() else z.lstrip() for z in lines]
precisely *because* an "extra" method is involved. The method's name
clarifies the code, and the method itself provides a place to put asserts
and traces, should they ever be needed.
Aside from eliminating gross performance bugs, performance differences
matter not at all.
Reinhard, this has been a great discussion. Seemingly minor differences and
distinctions are the foundation of big collapses in complexity.
EKR
--
You received this message because you are subscribed to the Google Groups
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.