[Python-ideas] Implicit string literal concatenation considered harmful?
Christian Tismer
tismer at stackless.com
Sat May 11 20:37:12 CEST 2013
On 11.05.13 19:24, M.-A. Lemburg wrote:
> On 11.05.2013 19:05, Christian Tismer wrote:
>> I think a simple stripping of white-space in
>>
>> text = s"""
>> leftmost column
>> two-char indent
>> """
>>
>> would solve 95 % of common indentation and concatenation cases.
>> I don't think provision for merging is needed very often.
>> If text occurs deeply nested in code, then it is also quite likely to
>> be part of an expression, anyway.
>> My major use-case is text constants in a class or function that
>> is multiple lines long and should be statically ready to use without
>> calling a function.
>>
>> (here an 's' as a strip prefix, but I'm not sold on that)
> This is not a good solution for long lines where you don't want to
> have embedded line endings. Taken from existing code:
>
> _litmonth = ('(?P<litmonth>'
> 'jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec|'
> 'mär|mae|mrz|mai|okt|dez|'
> 'fev|avr|juin|juil|aou|aoû|déc|'
> 'ene|abr|ago|dic|'
> 'out'
> ')[a-z,\.;]*')
>
> or
> raise errors.DataError(
> 'Inconsistent revenue item currency: '
> 'transaction=%r; transaction_position=%r' %
> (transaction, transaction_position))
>
> We usually try to keep the code line length under 80 chars,
> so splitting literals in that way is rather common, esp. in
> nested code paths.
>
Your first example is a regex, which could be used as-is.
Your second example is indented five levels deep. That is a coding
style which I would propose to write differently for better readability.
And if you stick with it, why not use the "+"?
I want to support constant strings, which should not be somewhere
in the middle of code. Your second example is computed, anyway,
not the case that I want to solve.
cheers - chris
--
Christian Tismer :^) <mailto:tismer at stackless.com>
Software Consulting : Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/
14482 Potsdam : PGP key -> http://pgp.uni-mainz.de
phone +49 173 24 18 776 fax +49 (30) 700143-0023
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Python-ideas
mailing list