<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Scala for Java Refugees Part 3: Methods and Statics</title>
	<atom:link href="http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/feed" rel="self" type="application/rss+xml" />
	<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3</link>
	<description>(permanently in beta)</description>
	<lastBuildDate>Mon, 09 Jan 2012 20:21:24 -0800</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Ari</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-5137</link>
		<dc:creator>Ari</dc:creator>
		<pubDate>Sun, 19 Sep 2010 22:42:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-5137</guid>
		<description>Does it strike anyone else as especially perverse/strange that object-level methods go in &quot;class&quot; while class-level methods (in Java terms) go in &quot;object&quot;?  It seems 100% backward to me.

I like some of the ideas behind Scala but so far have found its syntax to be, shall we say, less than elegant.</description>
		<content:encoded><![CDATA[<p>Does it strike anyone else as especially perverse/strange that object-level methods go in &#8220;class&#8221; while class-level methods (in Java terms) go in &#8220;object&#8221;?  It seems 100% backward to me.</p>
<p>I like some of the ideas behind Scala but so far have found its syntax to be, shall we say, less than elegant.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Gomes</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-5109</link>
		<dc:creator>Richard Gomes</dc:creator>
		<pubDate>Wed, 21 Jul 2010 07:36:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-5109</guid>
		<description>Imagine you&#039;d like to &#039;port&#039; a your Java class onto OSGi environment.
In a nutshell, what you have to do is:
(1) extract the interface of your class
(2) expose the interface so that clients will be able to call services you are providing
(3) make the concrete implementation of your class (actually, your original class), implement the interface you&#039;ve just exposed.

If your Java class has &#039;statics&#039;, you will be obliged to split your class in two: 
(a) one part which is similar to a Factory pattern, which contain non-static methods which were static methods in your original class and
(b) another part which contains all non-static methods of your original class.

In other words, you have to create the concepts of Scala class and the companion Scala object by hand, in Java. You have to do that when you are about to implement your application on top of OSGi, possibly breaking source compatibility with another platforms.

So, we can see that Scala is very well suited to OSGi because it &#039;forces&#039; developers to adopt a recommended strategy which is &quot;get rid of statics&quot; from day one.

In particular, statics are ugly because they do not scale well and they jeopardize concurrent threads. If statics do not &#039;scale&#039; well, they cannot be part of Scala :)

Scalability problems are certainly irrelevant with small applications but they are critical in the real world, when big and complex applications are needed in order to perform useful work, attending thousands or millions of requests a day.

Scala was designed trying to address needs not only of professional developers but also addressing needs of huge, complex applications, running on enterprise grade environments.

Thanks

Richard Gomes</description>
		<content:encoded><![CDATA[<p>Imagine you&#8217;d like to &#8216;port&#8217; a your Java class onto OSGi environment.<br />
In a nutshell, what you have to do is:<br />
(1) extract the interface of your class<br />
(2) expose the interface so that clients will be able to call services you are providing<br />
(3) make the concrete implementation of your class (actually, your original class), implement the interface you&#8217;ve just exposed.</p>
<p>If your Java class has &#8217;statics&#8217;, you will be obliged to split your class in two:<br />
(a) one part which is similar to a Factory pattern, which contain non-static methods which were static methods in your original class and<br />
(b) another part which contains all non-static methods of your original class.</p>
<p>In other words, you have to create the concepts of Scala class and the companion Scala object by hand, in Java. You have to do that when you are about to implement your application on top of OSGi, possibly breaking source compatibility with another platforms.</p>
<p>So, we can see that Scala is very well suited to OSGi because it &#8216;forces&#8217; developers to adopt a recommended strategy which is &#8220;get rid of statics&#8221; from day one.</p>
<p>In particular, statics are ugly because they do not scale well and they jeopardize concurrent threads. If statics do not &#8217;scale&#8217; well, they cannot be part of Scala <img src='http://www.codecommit.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Scalability problems are certainly irrelevant with small applications but they are critical in the real world, when big and complex applications are needed in order to perform useful work, attending thousands or millions of requests a day.</p>
<p>Scala was designed trying to address needs not only of professional developers but also addressing needs of huge, complex applications, running on enterprise grade environments.</p>
<p>Thanks</p>
<p>Richard Gomes</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Niall O'Higgins</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-4952</link>
		<dc:creator>Niall O'Higgins</dc:creator>
		<pubDate>Wed, 24 Mar 2010 00:47:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-4952</guid>
		<description>Hello,

I have found your articles on Scala helpful.  Thank you for writing them.  However I have noticed an error in this post.  You state that closures and anonymous methods are the same thing.  The following sentence confused me:

This “returnless” form becomes extremely important when dealing with anonymous methods (closures).

In fact they are not the same.  From Wikipedia:

&quot;The term closure is often mistakenly used to mean anonymous function. This is probably because most languages implementing anonymous functions allow them to form closures and programmers are usually introduced to both concepts at the same time. These are, however, distinct concepts.&quot;

See http://en.wikipedia.org/wiki/Closure_%28computer_science%29 for more.</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I have found your articles on Scala helpful.  Thank you for writing them.  However I have noticed an error in this post.  You state that closures and anonymous methods are the same thing.  The following sentence confused me:</p>
<p>This “returnless” form becomes extremely important when dealing with anonymous methods (closures).</p>
<p>In fact they are not the same.  From Wikipedia:</p>
<p>&#8220;The term closure is often mistakenly used to mean anonymous function. This is probably because most languages implementing anonymous functions allow them to form closures and programmers are usually introduced to both concepts at the same time. These are, however, distinct concepts.&#8221;</p>
<p>See <a href="http://en.wikipedia.org/wiki/Closure_%28computer_science%29" rel="nofollow">http://en.wikipedia.org/wiki/Closure_%28computer_science%29</a> for more.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Bygrave</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-4807</link>
		<dc:creator>Rob Bygrave</dc:creator>
		<pubDate>Fri, 27 Mar 2009 02:15:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-4807</guid>
		<description>Yes, I see that is an option - thanks... the downside that I see is that &quot;object DataBean&quot; generates a singleton class.

... it just seems like overkill to me ( to require a singleton class for this ).  Hmmm ...</description>
		<content:encoded><![CDATA[<p>Yes, I see that is an option &#8211; thanks&#8230; the downside that I see is that &#8220;object DataBean&#8221; generates a singleton class.</p>
<p>&#8230; it just seems like overkill to me ( to require a singleton class for this ).  Hmmm &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-4806</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 27 Mar 2009 01:20:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-4806</guid>
		<description>I would do something like this:

&lt;pre&gt;abstract class CanLog(name: String) {
  val logger = Logger getLogger name
}&lt;/pre&gt;

Then, for each class for which you want to allow logging, declare the companion object as a subclass of CanLog.  Thus, for some class DataBean, declare the class normally and then define the following additional snibblet:

&lt;pre&gt;object DataBean extends CanLog(&quot;mypackage.DataBean&quot;)&lt;/pre&gt;

With this in place, you can safely get the static logger using &quot;DataBean.logger&quot; (without the quotes).  That logger will indeed be static across the entire JVM just like a true Java static.</description>
		<content:encoded><![CDATA[<p>I would do something like this:</p>
<pre>abstract class CanLog(name: String) {
  val logger = Logger getLogger name
}</pre>
<p>Then, for each class for which you want to allow logging, declare the companion object as a subclass of CanLog.  Thus, for some class DataBean, declare the class normally and then define the following additional snibblet:</p>
<pre>object DataBean extends CanLog("mypackage.DataBean")</pre>
<p>With this in place, you can safely get the static logger using &#8220;DataBean.logger&#8221; (without the quotes).  That logger will indeed be static across the entire JVM just like a true Java static.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rob Bygrave</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-4805</link>
		<dc:creator>Rob Bygrave</dc:creator>
		<pubDate>Fri, 27 Mar 2009 00:43:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-4805</guid>
		<description>In Java you often have a static logger .... 

private static final Logger logger = Logger.getLogger(....the class .getName()... ); 

Do you have any suggestions on how do you do this in Scala?  

Note:  I&#039;ve googled/heard (could be wrong) that static final &#039;values&#039; ... can become static fields ... but Logger is not a value type.


Cheers, Rob.

PS: Nice work with your Scala articles - thanks for your efforts !!</description>
		<content:encoded><![CDATA[<p>In Java you often have a static logger &#8230;. </p>
<p>private static final Logger logger = Logger.getLogger(&#8230;.the class .getName()&#8230; ); </p>
<p>Do you have any suggestions on how do you do this in Scala?  </p>
<p>Note:  I&#8217;ve googled/heard (could be wrong) that static final &#8216;values&#8217; &#8230; can become static fields &#8230; but Logger is not a value type.</p>
<p>Cheers, Rob.</p>
<p>PS: Nice work with your Scala articles &#8211; thanks for your efforts !!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zack</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-4108</link>
		<dc:creator>Zack</dc:creator>
		<pubDate>Tue, 07 Oct 2008 22:20:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-4108</guid>
		<description>This series is, by far, the best intro to Scala I&#039;ve come across.  The content is great, but I think that I&#039;ve gotten at least as much out of the comments.  

Thanks for putting in the time to respond, Daniel.</description>
		<content:encoded><![CDATA[<p>This series is, by far, the best intro to Scala I&#8217;ve come across.  The content is great, but I think that I&#8217;ve gotten at least as much out of the comments.  </p>
<p>Thanks for putting in the time to respond, Daniel.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sarah A</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-3398</link>
		<dc:creator>Sarah A</dc:creator>
		<pubDate>Thu, 03 Apr 2008 23:58:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-3398</guid>
		<description>FYI, Haskell does have a convention (in do blocks) where the last value is returned. However, this is *not* a shortcut: there is no way to return anything but the last value. Do blocks are monadic command sequences, so nothing but the last value makes sense anyway. There is a return function, but it&#039;s not really comparable to the return of an imperative language.</description>
		<content:encoded><![CDATA[<p>FYI, Haskell does have a convention (in do blocks) where the last value is returned. However, this is *not* a shortcut: there is no way to return anything but the last value. Do blocks are monadic command sequences, so nothing but the last value makes sense anyway. There is a return function, but it&#8217;s not really comparable to the return of an imperative language.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-3227</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Sat, 08 Mar 2008 17:17:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-3227</guid>
		<description>Good catch!  I was a little foggy on the syntax when I wrote the article, but I hadn&#039;t remembered my error in the &quot;package private&quot; bit.  Fixed!</description>
		<content:encoded><![CDATA[<p>Good catch!  I was a little foggy on the syntax when I wrote the article, but I hadn&#8217;t remembered my error in the &#8220;package private&#8221; bit.  Fixed!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: David Linsin</title>
		<link>http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3/comment-page-1#comment-3226</link>
		<dc:creator>David Linsin</dc:creator>
		<pubDate>Sat, 08 Mar 2008 17:11:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.codecommit.com/blog/scala/scala-for-java-refugees-part-3-methods-and-statics#comment-3226</guid>
		<description>Hey Daniel,

your example 

package com.codecommit.mypackage
 
class MyClass {
  private[com.codecommit.mypackage] def myMethod = &quot;test&quot;
}

is not working for me...The compiler complains about the first dot after &quot;com&quot;. However, if I only put &quot;mypackage&quot; for AccessQualifier, it works like charm.</description>
		<content:encoded><![CDATA[<p>Hey Daniel,</p>
<p>your example </p>
<p>package com.codecommit.mypackage</p>
<p>class MyClass {<br />
  private[com.codecommit.mypackage] def myMethod = &#8220;test&#8221;<br />
}</p>
<p>is not working for me&#8230;The compiler complains about the first dot after &#8220;com&#8221;. However, if I only put &#8220;mypackage&#8221; for AccessQualifier, it works like charm.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

