[swift-evolution] [Pitch] Improve String Literals

David Hart david at hartbit.com
Tue May 16 09:45:15 CDT 2017


> On 16 May 2017, at 16:20, Gwendal Roué via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I 
>> Le 16 mai 2017 à 15:39, Adrian Zubarev <adrian.zubarev at devandartist.com <mailto:adrian.zubarev at devandartist.com>> a écrit :
>> 
>> Well the main complain I had during the discussion with David was, that I previously had such a model in mind which will break up long double-quoted string literals. Please look up this design in the alternative section of our proposal. By adding slightly redundant multi-line string literal syntax for consistency renders that complain to zero. By allowing:
>> 
>> "
>> SELECT 'name'
>> FROM 'people'
>> WHERE age > 20
>> "
>> it becomes clear that the trailing backslash should only be used for escaping new line injection in multi-line string literals, but not for breaking up long strings (similar to other languages like JavaScript):
>> 
>> "SELECT 'name' \
>> FROM 'people' \
>> WHERE age > 20"
>> This also lets us adopt the C/Objective-C syntax instead. 
>> 
>> "SELECT 'name' "
>> "FROM 'people' "
>> "WHERE age > 20"
> 
> SE-0168 had one focus: long literals that contain newline characters. And it does a great job addressing it.
> 
> SE-0168 does not talk about hard wrapping. Make this the only focus of your proposal. Simplify your motivation section. Strip away redundant solutions. Become expert in hard wrapping, and please give us one correct solution. Don't forget to talk about trailing/leading newlines and text editor grammars, because those were two important discussion topics for SE-0168.

I’m okay with that goal. But I’m not convinced that trailing backslash in multi-line strings alone can solve hard-wrapping. Again, compare the two examples (already mentioned in previous email):

assert(condition, “””
    This is my message but after some point I need to go to the next line \
    and I need to escape newlines on every line.
    “””)

VS

assert(condition, “This is my message but after some point I need to go "
    "to the next line and I need to escape newlines on every line.")

> Gwendal
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170516/504fb379/attachment.html>


More information about the swift-evolution mailing list