<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.3.1" -->
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>
<channel>
	<title>Commenti a: Things I do not like in Scala</title>
	<link>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html</link>
	<description>Linguaggio Scala, Java, AS400 e...cose più serie</description>
	<pubDate>Fri, 30 Jul 2010 17:15:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
		<item>
		<title>Di: Franco Lombardo</title>
		<link>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-8047</link>
		<dc:creator>Franco Lombardo</dc:creator>
		<pubDate>Mon, 04 Jan 2010 22:07:43 +0000</pubDate>
		<guid>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-8047</guid>
		<description>Klauss,

thanks for your very good comment, that made me write my latest post: http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html</description>
		<content:encoded><![CDATA[<p>Klauss,</p>
<p>thanks for your very good comment, that made me write my latest post: <a href="http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html" rel="nofollow">http://www.francolombardo.net/fantom-vs-scala-semicolon-inference-and-something-more_post-98.html</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Klaus</title>
		<link>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-7939</link>
		<dc:creator>Klaus</dc:creator>
		<pubDate>Thu, 31 Dec 2009 19:08:10 +0000</pubDate>
		<guid>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-7939</guid>
		<description>Both issues seem somewhat problematic, agree.

Concerning the semicolon inference issue I have specifically seen it come up in the context
of definition of domain specific languages (DSLs). Several Scala features can be used to define
such DSLs, specifically "Automatic Type-Dependent Closure Construction", see :

   http://www.scala-lang.org/node/138

The idea is very! appealing. However, there seems to be three problems
with this approach in Scala, which I would like to see comments on.

 Problem 1 - "the eager semicolon":
 automated inference of semicolon causes DSL constructs to be only
 partially parsed leaving the rest unparsed as a DSL construct

 Problem 2 - "the satisfied semicolon":
 partially written (incomplete) DSL constructs are accepted

 Problem 3 - "the lazy semicolon":
 one has to write a semilon to end a call of a method that takes () as argument,
 otherwise the Scala parser will complain about subsequent text as supurfluous arguments

Let me illustrate the first two problems with (a slight modification
of) the example on the page: http://www.scala-lang.org/node/138.

&lt;pre&gt;
// Suppose we define a loop construct as follows:

object Loop {
 def loop(body: =&#62; Unit): LoopUnlessCond =
  new LoopUnlessCond(body)

 protected class LoopUnlessCond(body: =&#62; Unit) {
  def unless(cond: =&#62; Boolean) {
    body
    if (!cond) unless(cond)
  }
 }
}

// We can now use this as follows (use 1):

import Loop._

var i = 10
loop {
 println("i = " + i)
 i -= 1
} unless (i == 0)

// The above compiles and runs correctly. So far so good.

// Problem 1 : the eager semicolon.
// The following use (use 2) gives a compile time error:

i = 10
loop {
 println("i = " + i)
 i -= 1
}
unless (i == 0)

// This is because the unless method call is on a line for itself.
// Scala will at the '}' infer a semicolon too early. Hence the unless
// will no longer be a call of the method in class LoopUnlessCond.
// This is an example of Problem 1.

// Problem 2 : the satisfied semicolon.
// An example of Problem 2 is the following, which is missing the
// call of unless:

i = 10
loop {
 println("i = " + i)
 i -= 1
}

// this compiles correctly, but does not execute correctly. Nothing is printed.

// Problem 3 : the lazy semicolon.
// Suppose a constructs ends with a keyword, for example 'return' with
no arguments.
// Then one may want to write a class like:

class Return {
 def return() {...}
}
&lt;/pre&gt;

and have a construct like:

&lt;pre&gt;
... return
somethingelse
&lt;/pre&gt;

The compiler will look for an argument to return and will find
'somethingelse' and
will complain that return has too many arguments. So one has to insert
a semicolon to
make it work:

&lt;pre&gt;
... return; // inserted semicolon here
somethingelse
&lt;/pre&gt;

// which is a pitty

Any opinions about these observations?

Regards,

Klaus</description>
		<content:encoded><![CDATA[<p>Both issues seem somewhat problematic, agree.</p>
<p>Concerning the semicolon inference issue I have specifically seen it come up in the context<br />
of definition of domain specific languages (DSLs). Several Scala features can be used to define<br />
such DSLs, specifically &#8220;Automatic Type-Dependent Closure Construction&#8221;, see :</p>
<p>   <a href="http://www.scala-lang.org/node/138" rel="nofollow">http://www.scala-lang.org/node/138</a></p>
<p>The idea is very! appealing. However, there seems to be three problems<br />
with this approach in Scala, which I would like to see comments on.</p>
<p> Problem 1 - &#8220;the eager semicolon&#8221;:<br />
 automated inference of semicolon causes DSL constructs to be only<br />
 partially parsed leaving the rest unparsed as a DSL construct</p>
<p> Problem 2 - &#8220;the satisfied semicolon&#8221;:<br />
 partially written (incomplete) DSL constructs are accepted</p>
<p> Problem 3 - &#8220;the lazy semicolon&#8221;:<br />
 one has to write a semilon to end a call of a method that takes () as argument,<br />
 otherwise the Scala parser will complain about subsequent text as supurfluous arguments</p>
<p>Let me illustrate the first two problems with (a slight modification<br />
of) the example on the page: <a href="http://www.scala-lang.org/node/138." rel="nofollow">http://www.scala-lang.org/node/138.</a></p>
<pre>
// Suppose we define a loop construct as follows:

object Loop {
 def loop(body: =&gt; Unit): LoopUnlessCond =
  new LoopUnlessCond(body)

 protected class LoopUnlessCond(body: =&gt; Unit) {
  def unless(cond: =&gt; Boolean) {
    body
    if (!cond) unless(cond)
  }
 }
}

// We can now use this as follows (use 1):

import Loop._

var i = 10
loop {
 println("i = " + i)
 i -= 1
} unless (i == 0)

// The above compiles and runs correctly. So far so good.

// Problem 1 : the eager semicolon.
// The following use (use 2) gives a compile time error:

i = 10
loop {
 println("i = " + i)
 i -= 1
}
unless (i == 0)

// This is because the unless method call is on a line for itself.
// Scala will at the '}' infer a semicolon too early. Hence the unless
// will no longer be a call of the method in class LoopUnlessCond.
// This is an example of Problem 1.

// Problem 2 : the satisfied semicolon.
// An example of Problem 2 is the following, which is missing the
// call of unless:

i = 10
loop {
 println("i = " + i)
 i -= 1
}

// this compiles correctly, but does not execute correctly. Nothing is printed.

// Problem 3 : the lazy semicolon.
// Suppose a constructs ends with a keyword, for example 'return' with
no arguments.
// Then one may want to write a class like:

class Return {
 def return() {...}
}
</pre>
<p>and have a construct like:</p>
<pre>
... return
somethingelse
</pre>
<p>The compiler will look for an argument to return and will find<br />
&#8217;somethingelse&#8217; and<br />
will complain that return has too many arguments. So one has to insert<br />
a semicolon to<br />
make it work:</p>
<pre>
... return; // inserted semicolon here
somethingelse
</pre>
<p>// which is a pitty</p>
<p>Any opinions about these observations?</p>
<p>Regards,</p>
<p>Klaus</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Justin</title>
		<link>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-3985</link>
		<dc:creator>Justin</dc:creator>
		<pubDate>Fri, 08 May 2009 23:40:15 +0000</pubDate>
		<guid>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-3985</guid>
		<description>Thanks for your post.  I very much agree about the semicolon inference issue.  That's a showstopper for me.  

For example, when writing tens of thousands of lines with ActionScript I was bitten by the "optional semicolon" bug many times.  There are myriad ways that you can have a statement span two lines which results in bugs (sometimes very hard-to-find bugs).  Having to remember to format my lines so that the line terminator could be correctly inferred is, at best, irritating.  I got bit enough times that I swore i would never use a language that doesn't terminate its statements with a semicolon[1].

Sorry Scala, I like you and could probably learn to love you, except for the semicolon thing.

Justin

[1] I make an exception for Smalltalk.  It uses periods to end statements.  Besides, somehow ending lines with periods always seemed more natural to me than ending lines with semicolons, since that's how I usually write English anyway.  :)</description>
		<content:encoded><![CDATA[<p>Thanks for your post.  I very much agree about the semicolon inference issue.  That&#8217;s a showstopper for me.  </p>
<p>For example, when writing tens of thousands of lines with ActionScript I was bitten by the &#8220;optional semicolon&#8221; bug many times.  There are myriad ways that you can have a statement span two lines which results in bugs (sometimes very hard-to-find bugs).  Having to remember to format my lines so that the line terminator could be correctly inferred is, at best, irritating.  I got bit enough times that I swore i would never use a language that doesn&#8217;t terminate its statements with a semicolon[1].</p>
<p>Sorry Scala, I like you and could probably learn to love you, except for the semicolon thing.</p>
<p>Justin</p>
<p>[1] I make an exception for Smalltalk.  It uses periods to end statements.  Besides, somehow ending lines with periods always seemed more natural to me than ending lines with semicolons, since that&#8217;s how I usually write English anyway.  <img src='http://www.francolombardo.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /></p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: piggybox</title>
		<link>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-1812</link>
		<dc:creator>piggybox</dc:creator>
		<pubDate>Wed, 08 Apr 2009 21:18:12 +0000</pubDate>
		<guid>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-1812</guid>
		<description>For the 1st issue, Ruby has that one as well. Really, how can a compiler guess things like this:

a
-2

is this one statement 'a-2' or 2 statements where '-2' is the return value? We can't tell, not to mention the poor compiler. So, next time when you break a line, break it after an operator.</description>
		<content:encoded><![CDATA[<p>For the 1st issue, Ruby has that one as well. Really, how can a compiler guess things like this:</p>
<p>a<br />
-2</p>
<p>is this one statement &#8216;a-2&#8242; or 2 statements where &#8216;-2&#8242; is the return value? We can&#8217;t tell, not to mention the poor compiler. So, next time when you break a line, break it after an operator.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Di: Matt</title>
		<link>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-28</link>
		<dc:creator>Matt</dc:creator>
		<pubDate>Mon, 26 Jan 2009 08:02:39 +0000</pubDate>
		<guid>http://www.francolombardo.net/things-i-do-not-like-in-scala_post-69.html#comment-28</guid>
		<description>Interesting post, it's good to document the "standard traps" that every language end up with, even one as well-designed as Scala.

Overall, I'm a fan of semicolon inference. The blighters really are 99% redundant, and their absence contributes to Scala having some of the feel of a dynamic language like Python or Ruby. I agree that the "gotya" you outline is rather unpleasant, but I haven't been bitten by anything like it yet in practice. Maybe I've just been fortunate! 

I'm more ambivalent about Scala's "equals-sign-vs-without" syntax for method declarations, which I've found rather unintuitive to learn. Still, the gotya you mention above is likely not a huge issue in practice, as I suspect the majority of the time accidentally omitting the equals will result in a compile-time type error at a call site. It's also the sort of thing that could be readily flagged as a warning by the compiler or IDE.</description>
		<content:encoded><![CDATA[<p>Interesting post, it&#8217;s good to document the &#8220;standard traps&#8221; that every language end up with, even one as well-designed as Scala.</p>
<p>Overall, I&#8217;m a fan of semicolon inference. The blighters really are 99% redundant, and their absence contributes to Scala having some of the feel of a dynamic language like Python or Ruby. I agree that the &#8220;gotya&#8221; you outline is rather unpleasant, but I haven&#8217;t been bitten by anything like it yet in practice. Maybe I&#8217;ve just been fortunate! </p>
<p>I&#8217;m more ambivalent about Scala&#8217;s &#8220;equals-sign-vs-without&#8221; syntax for method declarations, which I&#8217;ve found rather unintuitive to learn. Still, the gotya you mention above is likely not a huge issue in practice, as I suspect the majority of the time accidentally omitting the equals will result in a compile-time type error at a call site. It&#8217;s also the sort of thing that could be readily flagged as a warning by the compiler or IDE.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
