This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Why Martin hates string interpolation (Was: Re: Formatting Questions Summary)

14 replies
Jorge Ortiz
Joined: 2008-12-16,
User offline. Last seen 29 weeks 3 days ago.
So, today on the #scala IRC channel, the perennial question of how to do string interpolation in Scala came up.

The most recent student of Scala was informed that the feature as he expected it did not exist, but that "escaping from string and "+concatenating+" some "+variables+" had been declared just a character or two longer than the ${alternative}".

Now, I have a lot of respect for Martin's decisions about language design. It's not a blind respect. Over time I've learned that when I disagree with him, it often turns out that I was wrong. However, on the issue of string interpolation I've always found Martin's stance to be rather puzzling. It just -looks- ugly. And it's so hard to -type-!

And then it hit me. Maybe Swiss keyboards have much more convenient access to the "+ and +" key combinations needed to concatenate strings.

I did a little research, and indeed, they do:
http://en.wikipedia.org/wiki/Keyboard_layout#Swiss_German.2C_Swiss_French.2C_Swiss_Italian.2C_Liechtenstein.2C_Luxembourg

Typing "+ and +" are just Shift+2+1 and Shift+1+2 on the Swiss keyboard. Either can be completed with a quick flick of the left wrist. It's hard to imagine something more natural.

Compare to the situation on the standard US keyboard:
http://en.wikipedia.org/wiki/Keyboard_layout#United_States

Typing "+ and +" involves Shift+<comma (,)>+<equals (=)> and Shift+<equals>+<comma>. Not only does this require both hands to type naturally, but even then the last two keys involve a reaching pinky finger. (One the Swiss keyboard, the similarly-positioned keys would be Shift+<a-grave (à)>+<circumflex-diacritic (^)>.)

I don't know how other keyboards fare, but I doubt most of them are as blessed as the Swiss keyboard.

But there you go: once again, Martin was right. Scala really doesn't need better string interpolation. I just need a more-Swiss keyboard.

--j

On Mon, Mar 17, 2008 at 12:14 PM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
Hi all,

I agree with the formatting consensus, except for spaces around string
+. I am the one who proposed no spaces around + in strings. Let me
quickly explain my reasons (btw, I got this originally from Enno
Runne, several years ago).

1. When laying out strings, you want to be visually close to the
result you are getting. Compare:

   "test results: "+result1+", "+result2

with

   "test results: " + result1 + ", " + result2

Now, quickly: tell me where the spaces go: Is there a space before or
after the comma that gets printed? In the first version, this is
obvious, because the only spaces that are given are in the strings
themselves. And superfluous or missing spaces are one of
the most frequent source of errors in output.

2. With the new convention, the need for string substitution (often
put forward on Scala lists) all but disappears. Compare:

  "test results: ${result1}, ${result2}"

with the first version above. You have saved one character per
substitution, hardly worth a new syntax convention. In other words,
Scala's string substitution syntax is written

   "+...+"

instead of

  ${...}

or some other similar proposal. On the other hand, if you insist on
spaces around the +, the story becomes much less convincing.

3. String + is not the same as numeric +, and this often leads to
errors. A classical trap is:

  println("the sum is "+ x + y)

With the new convention, you'd tend to write:

 println("the sum is "+x + y)

This gives you a visual clue that something is wrong. So you'd
normally correct to:

 println("the sum is "+(x + y))

without having to run the program.

For all three reasons, I think an exception to the rule: ``put spaces
around all operators'' is warranted. Or otherwise said: + is
problematic as an operator on strings. Let's try not to write it as
one.

Cheers

L Jantzen
Joined: 2009-01-27,
User offline. Last seen 42 years 45 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

As a user with a norwegian style keyboard I have considered buying a US
keyboard in additon for doing programming. Should probably try to get hold
of a Swiss one instead. :wistle:

Jorge Ortiz-3 wrote:
>
>
> But there you go: once again, Martin was right. Scala really doesn't need
> better string interpolation. I just need a more-Swiss keyboard.
>
> --j
>
>

milessabin
Joined: 2008-08-11,
User offline. Last seen 33 weeks 3 days ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

On Fri, May 29, 2009 at 6:47 AM, Jorge Ortiz wrote:
> And then it hit me. Maybe Swiss keyboards have much more convenient access
> to the "+ and +" key combinations needed to concatenate strings.
>
> I did a little research, and indeed, they do:

I read this on the Metro on the way in to EPFL this morning and was a
little skeptical. But in the office I'm sitting in right now, one door
down from Martin's, there are two keyboards, one swiss, one generic,
and it is indeed exactly as you say: typing +" and "+ on the swiss
keyboard is a great deal easier on the swiss keyboard than on the
other.

I'm not sure what layout Martin has on his laptop ... I'll find out
when he gets in.

Cheers,

Miles

Carsten Saager
Joined: 2008-12-19,
User offline. Last seen 42 years 45 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting
I used to work in the US where I got a laptop with US-keyboard (naturally). Programming C++/Java at that time I can confirm that it is much better suited for programming in these languages than the German layout I was used to (the typical specials like "{[]}@~|\" are AltGr-keys)

14 years ago we thought in the company I worked for about choosing a modern language ( we used Oracle*Forms & PL/SQL which have a Pascal-like syntax) for the next generation of our product. C++ was an obvious favorite, but the use of {} for blocks raised serious concerns - typing begin/end appeared faster/more natural to most of us. Lisp and Smalltalk became serious candidates - perhaps as well because they were more accessible on german keyboards.

I am now in France and I recommended AppEngine to a french colleague - he was delighted about Python and the ease it lets him type in his little programms.

Perhaps not a coincidence that Pascal and Python had been conceived by non-english speakers.

-Carsten

On Fri, May 29, 2009 at 8:59 AM, L Jantzen <ljantzen [at] gmail [dot] com> wrote:

As a user with a norwegian style keyboard I have considered buying a US
keyboard in additon for doing programming.  Should probably try to get hold
of a Swiss one instead. :wistle:


Jorge Ortiz-3 wrote:
>
>
> But there you go: once again, Martin was right. Scala really doesn't need
> better string interpolation. I just need a more-Swiss keyboard.
>
> --j
>
>

--
View this message in context: http://www.nabble.com/Why-Martin-hates-string-interpolation-%28Was%3A-Re%3A-Formatting-Questions-Summary%29-tp23774178p23775163.html
Sent from the Scala - Debate mailing list archive at Nabble.com.


odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

On Fri, May 29, 2009 at 8:59 AM, L Jantzen wrote:
>
> As a user with a norwegian style keyboard I have considered buying a US
> keyboard in additon for doing programming.  Should probably try to get hold
> of a Swiss one instead. :wistle:
>
I did not know about the difference, I am using a US keyboard as well :-)

Cheers

odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

On Fri, May 29, 2009 at 10:03 AM, martin odersky wrote:
> On Fri, May 29, 2009 at 8:59 AM, L Jantzen wrote:
>>
>> As a user with a norwegian style keyboard I have considered buying a US
>> keyboard in additon for doing programming.  Should probably try to get hold
>> of a Swiss one instead. :wistle:
>>
> I did not know about the difference, I am using a US keyboard as well :-)
>
Maybe that's why I never write the space around the + in strings. I always write
"hello "+x+"!", say.

Cheers

James Iry
Joined: 2008-08-19,
User offline. Last seen 1 year 23 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting
Jorge,

Your theory is far too good to be damaged by mere facts.  I vote we throw this comment out as a...um.."statistical outlier".

On Fri, May 29, 2009 at 1:03 AM, martin odersky <martin [dot] odersky [at] epfl [dot] ch> wrote:
I did not know about the difference, I am using a US keyboard as well :-)

Cheers

Randall R Schulz
Joined: 2008-12-16,
User offline. Last seen 1 year 29 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

On Friday May 29 2009, James Iry wrote:
> On Fri, May 29, 2009 at 1:03 AM, martin odersky wrote:
> > I did not know about the difference, I am using a US keyboard as
> > well :-)
> >
> > Cheers
> >
> > -- Martin
>
> Jorge,
>
> Your theory is far too good to be damaged by mere facts. I vote we
> throw this comment out as a...um.."statistical outlier".

1 is prime
3 is prime
5 is prime
7 is prime
9 is prime ... experimental error
11 is prime
13 is prime

Ergo, all odd numbers are prime.

RRS

Robert Fischer
Joined: 2009-01-31,
User offline. Last seen 42 years 45 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

Someone could make a fine little side-business on selling "Scala" keyboards!

~~ Robert.

Miles Sabin wrote:
> On Fri, May 29, 2009 at 6:47 AM, Jorge Ortiz wrote:
>> And then it hit me. Maybe Swiss keyboards have much more convenient access
>> to the "+ and +" key combinations needed to concatenate strings.
>>
>> I did a little research, and indeed, they do:
>
> I read this on the Metro on the way in to EPFL this morning and was a
> little skeptical. But in the office I'm sitting in right now, one door
> down from Martin's, there are two keyboards, one swiss, one generic,
> and it is indeed exactly as you say: typing +" and "+ on the swiss
> keyboard is a great deal easier on the swiss keyboard than on the
> other.
>
> I'm not sure what layout Martin has on his laptop ... I'll find out
> when he gets in.
>
> Cheers,
>
>
> Miles
>

Bill Venners
Joined: 2008-12-18,
User offline. Last seen 31 weeks 5 days ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

Hi All,

On Fri, May 29, 2009 at 1:33 PM, Robert Fischer
wrote:
> Someone could make a fine little side-business on selling "Scala" keyboards!
>
I wonder how hard it would be to reprogram one function key to the be
the Unicode character for =>, another function key to be the Unicode
character for <-, and still another function key the Unicode character
for ->. That would make for a bit prettier code, and one could argue
it would make for more "functional" programming. Sorry about that last
one, but having some kind of downloadable file that would reprogram
function keys to make scala programming quicker might be useful.

Bill

> ~~ Robert.
>
> Miles Sabin wrote:
>>
>> On Fri, May 29, 2009 at 6:47 AM, Jorge Ortiz
>> wrote:
>>>
>>> And then it hit me. Maybe Swiss keyboards have much more convenient
>>> access
>>> to the "+ and +" key combinations needed to concatenate strings.
>>>
>>> I did a little research, and indeed, they do:
>>
>> I read this on the Metro on the way in to EPFL this morning and was a
>> little skeptical. But in the office I'm sitting in right now, one door
>> down from Martin's, there are two keyboards, one swiss, one generic,
>> and it is indeed exactly as you say: typing +" and "+ on the swiss
>> keyboard is a great deal easier on the swiss keyboard than on the
>> other.
>>
>> I'm not sure what layout Martin has on his laptop ... I'll find out
>> when he gets in.
>>
>> Cheers,
>>
>>
>> Miles
>>
>
> --
> ~~ Robert Fischer.
> Grails Training        http://GroovyMag.com/training
> Smokejumper Consulting http://SmokejumperIT.com
> Enfranchised Mind Blog http://EnfranchisedMind.com/blog
>
> Check out my book, "Grails Persistence with GORM and GSQL"!
> http://www.smokejumperit.com/redirect.html
>

Derek Chen-Becker
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formattin

Bill Venners wrote:
> Hi All,
>
> On Fri, May 29, 2009 at 1:33 PM, Robert Fischer
> wrote:
>> Someone could make a fine little side-business on selling "Scala" keyboards!
>>
> I wonder how hard it would be to reprogram one function key to the be
> the Unicode character for =>, another function key to be the Unicode
> character for <-, and still another function key the Unicode character
> for ->. That would make for a bit prettier code, and one could argue
> it would make for more "functional" programming. Sorry about that last
> one, but having some kind of downloadable file that would reprogram
> function keys to make scala programming quicker might be useful.

I'm on Ubuntu and I put together a small keyboard layout that extends US
basic:

partial alphanumeric_keys
xkb_symbols "scala" {

name[Group1]= "USA - Scala";

include "us(basic)"

key { [ comma, less, leftarrow, leftarrow ] };
key { [ period, greater, rightarrow, rightarrow ] };
// Double right arrow
key { [ equal, plus, 0x10021D2, 0x10021D2 ] };
};

This should generally work on any Linux system using XKB, although
configuration may be distro-specific. On Linux, you can paste the above
text at the end of /usr/share/X11/xkb/symbols/us, then for Ubuntu >=
8.10, edit /usr/share/X11/xkb/rules/evdev.xml and find "olpc2". Insert
the following XML after the tag for olpc2:

scala
Scala Layout

Now, if you open the keyboard preferences and add a layout, there should
be a new one under United States called "USA Scala Layout". Kinda crude
having to hack on these files, but it works.

Derek

Derek Chen-Becker
Joined: 2008-12-16,
User offline. Last seen 42 years 45 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formattin

Sorry, I should mention the mappings:

Right Alt + > = →
Right Alt + < = ←
Right Alt + = = ⇒

Derek

minhuang
Joined: 2008-08-20,
User offline. Last seen 2 years 44 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

Math pedantry says 1 is not a prime either.

On Fri, May 29, 2009 at 6:05 AM, Randall R Schulz wrote:
> On Friday May 29 2009, James Iry wrote:
>> On Fri, May 29, 2009 at 1:03 AM, martin odersky wrote:
>> > I did not know about the difference, I am using a US keyboard as
>> > well :-)
>> >
>> > Cheers
>> >
>> >  -- Martin
>>
>> Jorge,
>>
>> Your theory is far too good to be damaged by mere facts.  I vote we
>> throw this comment out as a...um.."statistical outlier".
>
>  1 is prime
>  3 is prime
>  5 is prime
>  7 is prime
>  9 is prime ... experimental error
> 11 is prime
> 13 is prime
>
> Ergo, all odd numbers are prime.
>
>
> RRS
>

Peter Niederwieser
Joined: 2009-01-15,
User offline. Last seen 42 years 45 weeks ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting

This reminds me of the (general) discussion whether optional semicolons are
really worth it. It's true that they only save one character per line, but
the result is much more readable. The same holds for string substitution:
"test results: ${result1}, ${result2}" is much easier to parse for the eye
than "test results: "+result1+", "+result2". One reason is that there is
only one pair of quotes involved, making it unnecessary for your brain to
judge if "+result1+" is inside or outside the string.

Cheers,
Peter

Jorge Ortiz-3 wrote:
>
> So, today on the #scala IRC channel, the perennial question of how to do
> string interpolation in Scala came up.
>
> The most recent student of Scala was informed that the feature as he
> expected it did not exist, but that "escaping from string and
> "+concatenating+" some "+variables+" had been declared just a character or
> two longer than the ${alternative}".
>
> Now, I have a lot of respect for Martin's decisions about language design.
> It's not a blind respect. Over time I've learned that when I disagree with
> him, it often turns out that I was wrong. However, on the issue of string
> interpolation I've always found Martin's stance to be rather puzzling. It
> just -looks- ugly. And it's so hard to -type-!
>
> And then it hit me. Maybe Swiss keyboards have much more convenient access
> to the "+ and +" key combinations needed to concatenate strings.
>
> I did a little research, and indeed, they do:
> http://en.wikipedia.org/wiki/Keyboard_layout#Swiss_German.2C_Swiss_Frenc...
>
> Typing "+ and +" are just Shift+2+1 and Shift+1+2 on the Swiss keyboard.
> Either can be completed with a quick flick of the left wrist. It's hard to
> imagine something more natural.
>
> Compare to the situation on the standard US keyboard:
> http://en.wikipedia.org/wiki/Keyboard_layout#United_States
>
> Typing "+ and +" involves Shift++ and
> Shift++. Not only does this require both hands to type
> naturally, but even then the last two keys involve a reaching pinky
> finger.
> (One the Swiss keyboard, the similarly-positioned keys would be
> Shift++.)
>
> I don't know how other keyboards fare, but I doubt most of them are as
> blessed as the Swiss keyboard.
>
> But there you go: once again, Martin was right. Scala really doesn't need
> better string interpolation. I just need a more-Swiss keyboard.
>
> --j
>
> On Mon, Mar 17, 2008 at 12:14 PM, martin odersky
> wrote:
>
>> Hi all,
>>
>> I agree with the formatting consensus, except for spaces around string
>> +. I am the one who proposed no spaces around + in strings. Let me
>> quickly explain my reasons (btw, I got this originally from Enno
>> Runne, several years ago).
>>
>> 1. When laying out strings, you want to be visually close to the
>> result you are getting. Compare:
>>
>> "test results: "+result1+", "+result2
>>
>> with
>>
>> "test results: " + result1 + ", " + result2
>>
>> Now, quickly: tell me where the spaces go: Is there a space before or
>> after the comma that gets printed? In the first version, this is
>> obvious, because the only spaces that are given are in the strings
>> themselves. And superfluous or missing spaces are one of
>> the most frequent source of errors in output.
>>
>> 2. With the new convention, the need for string substitution (often
>> put forward on Scala lists) all but disappears. Compare:
>>
>> "test results: ${result1}, ${result2}"
>>
>> with the first version above. You have saved one character per
>> substitution, hardly worth a new syntax convention. In other words,
>> Scala's string substitution syntax is written
>>
>> "+...+"
>>
>> instead of
>>
>> ${...}
>>
>> or some other similar proposal. On the other hand, if you insist on
>> spaces around the +, the story becomes much less convincing.
>>
>> 3. String + is not the same as numeric +, and this often leads to
>> errors. A classical trap is:
>>
>> println("the sum is "+ x + y)
>>
>> With the new convention, you'd tend to write:
>>
>> println("the sum is "+x + y)
>>
>> This gives you a visual clue that something is wrong. So you'd
>> normally correct to:
>>
>> println("the sum is "+(x + y))
>>
>> without having to run the program.
>>
>> For all three reasons, I think an exception to the rule: ``put spaces
>> around all operators'' is warranted. Or otherwise said: + is
>> problematic as an operator on strings. Let's try not to write it as
>> one.
>>
>> Cheers
>>
>> -- Martin
>>
>
>

dcsobral
Joined: 2009-04-23,
User offline. Last seen 38 weeks 5 days ago.
Re: Why Martin hates string interpolation (Was: Re: Formatting
And the most ridiculous thing is... there's interpolation for XML!
The visual thing bothers me too. Honestly, I'd prefer writing ${{{result}}}$ -- or whatever -- number of characters notwithstanding, just so that I could easily understand what's inside or outside the string.

On Fri, Jun 5, 2009 at 4:59 PM, Peter Niederwieser <pniederw [at] gmail [dot] com> wrote:

This reminds me of the (general) discussion whether optional semicolons are
really worth it. It's true that they only save one character per line, but
the result is much more readable. The same holds for string substitution:
"test results: ${result1}, ${result2}" is much easier to parse for the eye
than "test results: "+result1+", "+result2". One reason is that there is
only one pair of quotes involved, making it unnecessary for your brain to
judge if "+result1+" is inside or outside the string.

Cheers,
Peter


Jorge Ortiz-3 wrote:
>
> So, today on the #scala IRC channel, the perennial question of how to do
> string interpolation in Scala came up.
>
> The most recent student of Scala was informed that the feature as he
> expected it did not exist, but that "escaping from string and
> "+concatenating+" some "+variables+" had been declared just a character or
> two longer than the ${alternative}".
>
> Now, I have a lot of respect for Martin's decisions about language design.
> It's not a blind respect. Over time I've learned that when I disagree with
> him, it often turns out that I was wrong. However, on the issue of string
> interpolation I've always found Martin's stance to be rather puzzling. It
> just -looks- ugly. And it's so hard to -type-!
>
> And then it hit me. Maybe Swiss keyboards have much more convenient access
> to the "+ and +" key combinations needed to concatenate strings.
>
> I did a little research, and indeed, they do:
> http://en.wikipedia.org/wiki/Keyboard_layout#Swiss_German.2C_Swiss_French.2C_Swiss_Italian.2C_Liechtenstein.2C_Luxembourg
>
> Typing "+ and +" are just Shift+2+1 and Shift+1+2 on the Swiss keyboard.
> Either can be completed with a quick flick of the left wrist. It's hard to
> imagine something more natural.
>
> Compare to the situation on the standard US keyboard:
> http://en.wikipedia.org/wiki/Keyboard_layout#United_States
>
> Typing "+ and +" involves Shift+<comma (,)>+<equals (=)> and
> Shift+<equals>+<comma>. Not only does this require both hands to type
> naturally, but even then the last two keys involve a reaching pinky
> finger.
> (One the Swiss keyboard, the similarly-positioned keys would be
> Shift+<a-grave (à)>+<circumflex-diacritic (^)>.)
>
> I don't know how other keyboards fare, but I doubt most of them are as
> blessed as the Swiss keyboard.
>
> But there you go: once again, Martin was right. Scala really doesn't need
> better string interpolation. I just need a more-Swiss keyboard.
>
> --j
>
> On Mon, Mar 17, 2008 at 12:14 PM, martin odersky
> <martin [dot] odersky [at] epfl [dot] ch>wrote:
>
>> Hi all,
>>
>> I agree with the formatting consensus, except for spaces around string
>> +. I am the one who proposed no spaces around + in strings. Let me
>> quickly explain my reasons (btw, I got this originally from Enno
>> Runne, several years ago).
>>
>> 1. When laying out strings, you want to be visually close to the
>> result you are getting. Compare:
>>
>>    "test results: "+result1+", "+result2
>>
>> with
>>
>>    "test results: " + result1 + ", " + result2
>>
>> Now, quickly: tell me where the spaces go: Is there a space before or
>> after the comma that gets printed? In the first version, this is
>> obvious, because the only spaces that are given are in the strings
>> themselves. And superfluous or missing spaces are one of
>> the most frequent source of errors in output.
>>
>> 2. With the new convention, the need for string substitution (often
>> put forward on Scala lists) all but disappears. Compare:
>>
>>   "test results: ${result1}, ${result2}"
>>
>> with the first version above. You have saved one character per
>> substitution, hardly worth a new syntax convention. In other words,
>> Scala's string substitution syntax is written
>>
>>    "+...+"
>>
>> instead of
>>
>>   ${...}
>>
>> or some other similar proposal. On the other hand, if you insist on
>> spaces around the +, the story becomes much less convincing.
>>
>> 3. String + is not the same as numeric +, and this often leads to
>> errors. A classical trap is:
>>
>>   println("the sum is "+ x + y)
>>
>> With the new convention, you'd tend to write:
>>
>>  println("the sum is "+x + y)
>>
>> This gives you a visual clue that something is wrong. So you'd
>> normally correct to:
>>
>>  println("the sum is "+(x + y))
>>
>> without having to run the program.
>>
>> For all three reasons, I think an exception to the rule: ``put spaces
>> around all operators'' is warranted. Or otherwise said: + is
>> problematic as an operator on strings. Let's try not to write it as
>> one.
>>
>> Cheers
>>
>>  -- Martin
>>
>
>

--
View this message in context: http://www.nabble.com/Why-Martin-hates-string-interpolation-%28Was%3A-Re%3A-Formatting-Questions-Summary%29-tp23774178p23894606.html
Sent from the Scala - Debate mailing list archive at Nabble.com.




--
Daniel C. Sobral

Something I learned in academia: there are three kinds of academic reviews: review by name, review by reference and review by value.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland