Quantcast

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

classic Classic list List threaded Threaded
19 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Jorge Ortiz
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 <[hidden email]> 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

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

L Jantzen
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.

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Miles Sabin
In reply to this post by Jorge Ortiz
On Fri, May 29, 2009 at 6:47 AM, Jorge Ortiz <[hidden email]> 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

--
Miles Sabin
tel: +44 (0)7813 944 528
skype:  milessabin
http://twitter.com/milessabin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

csar
In reply to this post by L Jantzen
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 <[hidden email]> 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.


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Martin Odersky
In reply to this post by L Jantzen
On Fri, May 29, 2009 at 8:59 AM, L Jantzen <[hidden email]> 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

 -- Martin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Martin Odersky
On Fri, May 29, 2009 at 10:03 AM, martin odersky <[hidden email]> wrote:
> On Fri, May 29, 2009 at 8:59 AM, L Jantzen <[hidden email]> 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

 -- Martin
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

James Iry-2
In reply to this post by Martin Odersky
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 <[hidden email]> wrote:
I did not know about the difference, I am using a US keyboard as well :-)

Cheers

 -- Martin

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Randall R Schulz-2
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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Robert Fischer
In reply to this post by Miles Sabin
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 <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Bill Venners-3
Hi All,

On Fri, May 29, 2009 at 1:33 PM, Robert Fischer
<[hidden email]> 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 <[hidden email]>
>> 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
>



--
Bill Venners
Artima, Inc.
http://www.artima.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Derek Chen-Becker-2
Bill Venners wrote:

> Hi All,
>
> On Fri, May 29, 2009 at 1:33 PM, Robert Fischer
> <[hidden email]> 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 <AB08>  { [     comma,     less,  leftarrow,   leftarrow ] };
   key <AB09>  { [    period,  greater, rightarrow,   rightarrow ] };
   // Double right arrow
   key <AE12>  { [     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 </variant> tag for olpc2:

        <variant>
          <configItem>
            <name>scala</name>
            <description>Scala Layout</description>
          </configItem>
        </variant>


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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Derek Chen-Becker-2
In reply to this post by Bill Venners-3
Sorry, I should mention the mappings:

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

Derek
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Min Huang-2
In reply to this post by Randall R Schulz-2
Math pedantry says 1 is not a prime either.

On Fri, May 29, 2009 at 6:05 AM, Randall R Schulz <[hidden email]> 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
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Seth Tisue
In reply to this post by Robert Fischer
>>>>> "Robert" == Robert Fischer <[hidden email]> writes:

 Robert> Someone could make a fine little side-business on selling
 Robert> "Scala" keyboards!  ~~ Robert.

with big .asInstanceOf[ and .isInstanceOf[ keys for people who
haven't unlearned their Java and Ruby habits yet :-)

--
Seth Tisue / http://tisue.net
lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Ray Racine
I'd like to introduce the concept of an "editor" into this thread.  They fall in the category of useful software tools designed to wrangle code.  I highly recommend them.

For example, Emacs' yasnippit mode for Scala has many predefined handy abbreviations and their expansions.  Customize to suit, it takes literally 10 seconds to add or modify an abbreviation to something else.

One of these prefined snippits allows one to type the word "cast", hit the tab key and (it's quite magical really) it expands to "asInstanceOf[Type]".  The cursor is helpfully positioned over the letter 'T' in the color coded word Type.  As soon as you type the first letter of the desired class name  the word "Type" disappears.  Of course I rarely type the full class name, only the first few letters and then alt-/ auto-complete it.

Those unfamiliar with editors, suffused with a sense of deep accomplishment, may stop at backspace key mastery, however, editors are capable of additional and equally amazing things such as allowing one to redefine keys '"' key positions or shortcut expansion.  Even horribly difficult ones like Scandinavian key positions, which due to their well thought out positioning, do not allow for proper exercising of the fingers. 

As a result they (the fingers) adopt the appearance of breakfast sausages.  You may doubt,  but I defer to the scientific method for validation.  During Martin's visit to the West Coast observe if as he points to a slide you find yourself strangely and rather suddenly craving a good breakfast.


On Sat, May 30, 2009 at 11:26 AM, Seth Tisue <[hidden email]> wrote:
>>>>> "Robert" == Robert Fischer <[hidden email]> writes:

 Robert> Someone could make a fine little side-business on selling
 Robert> "Scala" keyboards!  ~~ Robert.

with big .asInstanceOf[ and .isInstanceOf[ keys for people who
haven't unlearned their Java and Ruby habits yet :-)

--
Seth Tisue / http://tisue.net
lead developer, NetLogo: http://ccl.northwestern.edu/netlogo/


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Florian Hars-3
In reply to this post by Seth Tisue
Seth Tisue wrote:
> with big .asInstanceOf[ and .isInstanceOf[ keys for people who
> haven't unlearned their Java and Ruby habits yet :-)

We could reuse that one:

http://www.seanmichaelragan.com/html/[2008-10-27]_CAPS_LOCK_TRAINER_KEY.shtml

- Florian
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Ricky Clarkson
Perhaps my lisp ( and ) foot pedals have a new use.

2009/5/31 Florian Hars <[hidden email]>:

> Seth Tisue wrote:
>>
>> with big .asInstanceOf[ and .isInstanceOf[ keys for people who
>> haven't unlearned their Java and Ruby habits yet :-)
>
> We could reuse that one:
>
> http://www.seanmichaelragan.com/html/[2008-10-27]_CAPS_LOCK_TRAINER_KEY.shtml
>
> - Florian
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Peter Niederwieser
In reply to this post by Jorge Ortiz
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.odersky@epfl.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
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

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

Daniel Sobral
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 <[hidden email]> 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
> <[hidden email]>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.
Loading...