<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ctrl-C &#187; scala</title>
	<atom:link href="http://ctrl-c.us/blog/archives/tag/scala/feed" rel="self" type="application/rss+xml" />
	<link>http://ctrl-c.us/blog</link>
	<description>a friendly interruption</description>
	<lastBuildDate>Fri, 28 May 2010 11:49:37 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>First Thoughts on Scala</title>
		<link>http://ctrl-c.us/blog/archives/589</link>
		<comments>http://ctrl-c.us/blog/archives/589#comments</comments>
		<pubDate>Tue, 14 Jul 2009 19:31:36 +0000</pubDate>
		<dc:creator>Caleb Spare</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[scala]]></category>

		<guid isPermaLink="false">http://ctrl-c.us/blog/?p=589</guid>
		<description><![CDATA[Over the past week or so I&#8217;ve been looking into the Scala programming language. If you aren&#8217;t familiar with it, Scala is one of a group of new-ish languages including Groovy, Clojure, and Nice (as well as new implementations of preexisting languages like Jython, JRuby, and Rhino) that run on the JVM (either interpreted or [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past week or so I&#8217;ve been looking into the <a href="http://www.scala-lang.org/">Scala</a> programming language. If you aren&#8217;t familiar with it, Scala is one of a group of new-ish languages including <a href="http://groovy.codehaus.org/">Groovy</a>, <a href="http://clojure.org/">Clojure</a>, and <a href="http://nice.sourceforge.net/">Nice</a> (as well as new implementations of preexisting languages like <a href="http://www.jython.org/">Jython</a>, <a href="http://jruby.codehaus.org/">JRuby</a>, and <a href="http://www.mozilla.org/rhino/">Rhino</a>) that run on the JVM (either interpreted or compiled to Java bytecode). Over perhaps the past decade the JVM has been increasingly seen as an attractive target platform for language development for several reasons:</p>
<ul>
<li> Implementation in Java instead of C</li>
<li> Features like garbage collection, portability, and a huge standard library come for free</li>
<li> Languages benefit from advances and optimizations in the JVM</li>
</ul>
<p>(This is part of a trend pointed out as Prediction #4 in <a href="http://steve.yegge.googlepages.com/ten-predictions">a list of 10 predictions</a> about software Steve Yegge made about 5 years ago.) In fact, targeting a virtual machine has almost become the <em>only</em> way to implement new, fancy languages with reasonable performance, portability, and implementation time.</p>
<p><span id="more-589"></span></p>
<p>Scala has an interesting mix of features. Some are taken from functional programming such as higher-order and anonymous functions, closures, partial function applications, and algebraic data types. It has pure OO (everything is an object, even functions) with mixins to compose functionality. Probably the most distinguishing feature of Scala is that it is statically typed (with some pretty nice type inference). For all this, it has a fairly small syntax (significantly smaller than Java, for instance).</p>
<p>As implied by the name, Scala tries to be as scalable as possible. Here are a couple of ways this is done (and I&#8217;m sure there are many others that I haven&#8217;t seen). Scala programs can be interpreted like scripts: if <code>hello.scala</code> contains</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;">println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;OHAI&quot;</span><span style="color: #F78811;">&#41;</span></pre></div></div>

<p>then this can be run by</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ scala hello.scala
OHAI</pre></div></div>

<p>They can also be compiled to class files. If <code>hello.scala</code> instead contains</p>

<div class="wp_syntax"><div class="code"><pre class="scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">object</span> HelloApp <span style="color: #F78811;">&#123;</span>
    <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>arg<span style="color: #000080;">:</span> Array<span style="color: #F78811;">&#91;</span>String<span style="color: #F78811;">&#93;</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
        println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;OHAI&quot;</span><span style="color: #F78811;">&#41;</span>
    <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></div></div>

<p>then we can do</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ scalac hello.scala
$ scala HelloApp
OHAI</pre></div></div>

<p>What really makes Scala scalable, though, is how its small but powerful syntax allows creation of new constructs that almost look like new syntax itself. In <a href="http://ftp.heanet.ie/mirrors/fosdem-video/2009/maintracks/scala.xvid.avi">a great talk</a> by Martin Odersky, the creator of Scala, he presents three nice examples of features that can be concisely added to Scala due to its extensibility: the <code>using</code> keyword, <code>break</code> and <code>continue</code>, and Erlang-style actors (the latter two are included in the Scala library).</p>
<p>I&#8217;m just getting started with Scala, but I&#8217;ve been very happy with its thorough documentation and the large collection of documents available to help learn the language. For instance, I have found Martin Odersky&#8217;s <a href="http://www.scala-lang.org/docu/files/ScalaByExample.pdf">Scala By Example</a> to be a great introduction. It&#8217;s nice to see a language that makes it so easy for beginners to figure out what&#8217;s going on (I&#8217;m looking at you, <a href="http://cobra-language.com/">Cobra</a>). I&#8217;m also having a good time reading <a href="http://www.amazon.com/Programming-Scala-Comprehensive-Step-step/dp/0981531601/ref=sr_1_1?ie=UTF8&amp;s=books&amp;qid=1247598681&amp;sr=8-1">&#8220;Programming in Scala&#8221;</a>, the comprehensive and extremely well-written language guide. Not only does it explain Scala very well, it is easy to read and includes tidbits such as this (<code>var</code>s are mutable variables; <code>val</code>s are immutable):</p>
<blockquote><p>If you’re coming from an imperative background, such as Java, C++, or C#, you may think of <code>var</code> as a regular variable and <code>val</code> as a special kind of variable. On the other hand, if you’re coming from a functional background, such as Haskell, OCaml, or Erlang, you might think of <code>val</code> as a regular variable and <code>var</code> as akin to blasphemy.</p></blockquote>
<p>Scala has some traction in the software community. The most well-known example, of course, is Twitter; last year they switched their message queuing from Rails to Scala, in their continuing quest to turn millions of dollars of venture capital into the hippest code possible. (Also there was a bit of a case of their backend exploding when things started heating up; it seems a bit telling that they switched to from Ruby to a language that has the first two syllables of &#8217;scalable&#8217; in its name.) There is also a Rails-like web framework for Scala, <a href="http://liftweb.net/">Lift</a>.</p>
<p>Given my great initial impression, I can only hope that Scala becomes more widespread. I might post more thoughts on Scala quirks and features (as well as my improved vim indent file) later on.</p>
]]></content:encoded>
			<wfw:commentRss>http://ctrl-c.us/blog/archives/589/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://ftp.heanet.ie/mirrors/fosdem-video/2009/maintracks/scala.xvid.avi" length="185676474" type="video/x-msvideo" />
		</item>
	</channel>
</rss>
