[swift-evolution] multi-line string literals

Marc Knaup marc at knaup.koeln
Fri Dec 11 10:56:09 CST 2015


What I suggest is to support both:

   - standalone triple-quote will use indentation as in your first example
   - triple-quote which is not stand-alone will use indentation as in your
   second example


On Fri, Dec 11, 2015 at 5:52 PM, David Owens II <david at owensd.io> wrote:

> I really don’t like the left-edge being in the zero column as it is
> completely inconsistent with the formatting of the rest of the language.
>
> class CommandLineTool {
>     func showHelp() {
>         let text =
>             """
>             OVERVIEW: Swift compiler
>
>             USAGE: swiftc [options] <inputs>
>
>             MODES:
>               -dump-ast        Parse and type-check input file(s) and
> dump AST(s)
>               -dump-parse      Parse input file(s) and dump AST(s)
>               -dump-type-refinement-contexts
>                                Type-check input file(s) and dump type
> refinement contexts(s)
>               -emit-assembly   Emit assembly file(s) (-S)
>               -emit-bc         Emit LLVM BC file(s)
>
>             ...
>
>             """
>
>          print(text)
>      }
> }
>
> What you’re suggesting is that the above code should be this:
>
> class CommandLineTool {
>     func showHelp() {
>         let text = """
> OVERVIEW: Swift compiler
>
> USAGE: swiftc [options] <inputs>
>
> MODES:
>   -dump-ast        Parse and type-check input file(s) and dump AST(s)
>   -dump-parse      Parse input file(s) and dump AST(s)
>   -dump-type-refinement-contexts
>                    Type-check input file(s) and dump type refinement
> contexts(s)
>   -emit-assembly   Emit assembly file(s) (-S)
>   -emit-bc         Emit LLVM BC file(s)
>
> ...
>
> """
>
>          print(text)
>      }
> }
>
> That’s a compromise I’d rather not have to see in my code.
>
> Another use case for this is for the content of test cases. Having many of
> these string literals within that file that are all left-edge aligned
> reduces the readability of the code.
>
> -David
>
> On Dec 11, 2015, at 4:20 AM, Marc Knaup <marc at knaup.koeln> wrote:
>
> This example will break easily when tabs are used for indentation or when
> using refactoring tools to rename the variable:
>
> let text = """
>            This is ok.
>
>            """
>
>
> All that suggests is this form should be preferred:
>
> let text =
>>     """
>>     This is ok.
>>     """
>>
>>
> I write a lot of my text these days in markdown, so I’m pretty heavily
> influenced by the simplicity of that.
>
> -David
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151211/c756aba2/attachment.html>


More information about the swift-evolution mailing list