(no subject)


(John Siracusa) #1

Chris Lattner wrote:

When introducing a feature like this, I think it would be useful to survey
a range of popular languages (and yes, even perl :wink: to understand what
facilities they provide and why (i.e. what problems they are solving) and
synthesize a good swift design that can solve the same problems with a
hopefully simple approach.

Travis Tilley wrote:

​Perl and Erlang are unique in that valid code in either language looks
essentially like line noise. I'd rather take inspiration from languages
like ruby, python, and elixir.​

Jokes aside, the ability to choose delimiters for strings and other
language constructs that surround some value is a huge boon to code
readability.

For example, RegExp literals in JavaScript:

var regex = /^\/usr\/local\//; // gross

An even simpler example, which applies to many languages: a string literal
that contains all of your possible string delimiters within it. This is not
an exotic thing in English.

message = "\"I don't like this,\" she said."; // nope
message = '"I don\'t like this," she said.'; // still nope

Then, of course, there's your escape character itself:

escapes = "Some escapes: \\n, \\t, \\a"; // sigh

There are many time-tested solutions to these syntactic/cosmetic problems.

* Different delimiters with different interpolation rules (e.g., single
quotes not honoring any backslash escapes and not doing variable
interpolation)

* Matched-pair delimiters that don't require anything to be escaped as long
as the delimiters are absent or matched within the string. (These alone
solve a huge range of problems.)

* Heredocs for long literals where you get to pick the end token.

* Heredocs modified by delimiters around the end token to control
interpolation within the long literal.

Which language looks like line noise now?

$messasge = q("I can't believe how nice this is," she said (quietly).);

$regex = qr(^/usr/local/);

$escapes = 'Some escapes: \n, \t, \a';

My take: once you use a language where you pretty much never have to
backslash-escape a character you can easily type to get it into a string,
it's really hard to go back.

-John


(Chris Lattner) #2

Chris Lattner wrote:
When introducing a feature like this, I think it would be useful to survey a range of popular languages (and yes, even perl ;-) to understand what facilities they provide and why (i.e. what problems they are solving) and synthesize a good swift design that can solve the same problems with a hopefully simple approach.

Travis Tilley wrote:
​Perl and Erlang are unique in that valid code in either language looks essentially like line noise. I'd rather take inspiration from languages like ruby, python, and elixir.​

Jokes aside, the ability to choose delimiters for strings and other language constructs that surround some value is a huge boon to code readability.

I agree.

My take: once you use a language where you pretty much never have to backslash-escape a character you can easily type to get it into a string, it's really hard to go back.

In all seriousness, Perl is one of the best languages in the world at text and string processing, and Swift has a lot to learn from it and its community on this topic. For anyone looking to work on string processing (including string literals and regex's), Perl is really the best game in town. We have a long ways to go at the moment, but Swift should aspire to be *better* than Perl at string processing and manipulation - comparing to other languages may be interesting but the baseline should be set by Perl.

OTOH, there are some other things that Perl isn’t good at - like shipping on schedule. Let’s not aspire to following its approach there… :-)

-Chris

···

On Dec 11, 2015, at 8:52 AM, John Siracusa via swift-evolution <swift-evolution@swift.org> wrote: