[swift-evolution] multi-line string literals.

Rainer Brockerhoff rainer at brockerhoff.net
Mon May 2 09:47:46 CDT 2016


On 5/2/16 09:53, Brent Royal-Gordon via swift-evolution wrote:
> 	When you are embedding enormous string literals in source code, you 
> 	must put undistorted representation of the string above all other 
> 	considerations. If the design which best permits the string to be 
> 	written verbatim is ugly, bulky, unlike other language constructs, 
> 	disruptive to code readability, error-prone, arbitrary, difficult to 
> 	parse, or otherwise a wart on the language, that is simply the price we 
> 	have to pay for that feature.

+1. I've tried to write this up a few times, but couldn't find a
satisfactory syntax; still, how about introducing "named comments" or
"footnotes in comments" like this:

/*#label#
...N lines of unescaped, as-is text
#*/

and elsewhere in source referring to this with some #construct(label)
syntax?

> 	But it's a different story for short multiline strings. When you are 
> 	writing a little bit of text, but still more than one line, you don't 
> 	want to disrupt your code's indentation, add whole lines just for 
> 	delimiters, insert bizarre or cryptic tokens into your code, or create 
> 	syntax errors which take ten minutes to trace back to their source. You 
> 	want a different feature, with different tradeoffs.

At least for Xcode having a "paste as escaped string" would solve this,
other platforms/editors could have a standard macro with the same
effect. Of course readability of the pasted literal would suffer.


-- 
Rainer Brockerhoff  <rainer at brockerhoff.net>
Belo Horizonte, Brazil
"In the affairs of others even fools are wise
In their own business even sages err."
http://brockerhoff.net/blog/



More information about the swift-evolution mailing list