<?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>Zen and the Art of Programming &#187; Scala</title>
	<atom:link href="http://programmingzen.com/category/scala/feed/" rel="self" type="application/rss+xml" />
	<link>http://programmingzen.com</link>
	<description>Meditations on programming, startups, and technology</description>
	<lastBuildDate>Mon, 16 Jan 2012 17:09:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>10 Ruby One Liners to Impress Your Friends</title>
		<link>http://programmingzen.com/2011/06/02/10-ruby-one-liners-to-impress-your-friends/</link>
		<comments>http://programmingzen.com/2011/06/02/10-ruby-one-liners-to-impress-your-friends/#comments</comments>
		<pubDate>Thu, 02 Jun 2011 20:53:08 +0000</pubDate>
		<dc:creator>Antonio Cangiano</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://programmingzen.com/?p=1383</guid>
		<description><![CDATA[Someone came up with a list of 10 one-liner examples that are meant to showcase Scala’s expressiveness. A CoffeeScript version quickly emerged, so I thought I’d publish a Ruby one. I find Ruby’s syntax to be a bit cleaner than Scala&#8217;s, but the substance (at least as far as these examples are concerned) is relatively [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Someone came up with <a href="http://solog.co/47/10-scala-one-liners-to-impress-your-friends/" target="_blank">a list of 10 one-liner examples</a> that are meant to showcase Scala’s expressiveness. <a href="http://ricardo.cc/2011/06/02/10-CoffeeScript-One-Liners-to-Impress-Your-Friends.html" target="_blank">A CoffeeScript version</a> quickly emerged, so I thought I’d publish a Ruby one. I find Ruby’s syntax to be a bit cleaner than Scala&#8217;s, but the substance (at least as far as these examples are concerned) is relatively similar.</p>
<h4>Multiply each item in a list by 2</h4>
<pre class="highlight">(1..10).map { |n| n * 2 }</pre>
<h4>Sum a list of numbers</h4>
<pre class="highlight">(1..1000).inject { |sum, n| sum + n }</pre>
<p>Or using the (built in) Symbol#to_proc syntax that&#8217;s been available since Ruby 1.8.7:</p>
<pre class="highlight">(1..1000).inject(&#038;:+)</pre>
<p>Or even just passing a symbol directly:</p>
<pre class="highlight">(1..1000).inject(:+)</pre>
<h4>Verify if tokens exist in a string</h4>
<pre class="highlight">words = ["scala", "akka", "play framework", "sbt", "typesafe"]
tweet = "This is an example tweet talking about scala and sbt."

words.any? { |word| tweet.include?(word) }</pre>
<h4>Reading a file</h4>
<pre class="highlight">file_text = File.read("data.txt")
file_lines = File.readlines("data.txt")</pre>
<p>The latter includes &#8220;\n&#8221; at the end of each element of the array, which can be trimmed by appending <code>.map { |str| str.chop }</code> or by using the alternative version:</p>
<pre class="highlight">File.read("data.txt").split(/\n/)</pre>
<h4>Happy Birthday</h4>
<pre class="highlight">4.times { |n| puts "Happy Birthday #{n==2 ? "dear Tony" : "to You"}" }</pre>
<h4>Filter a list of numbers</h4>
<pre class="highlight">[49, 58, 76, 82, 88, 90].partition { |n| n > 60 }</pre>
<h4>Fetch and parse an XML web service</h4>
<pre class="highlight">require 'open-uri'
require 'hpricot'

results = Hpricot(open("http://search.twitter.com/search.atom?&#038;q=scala"))</pre>
<p>This example requires open-uri and hpricot or equivalent libraries (you could use builtin ones if you wish). It&#8217;s not too much code, but Scala clearly wins here.</p>
<h4>Find minimum (or maximum) in a list</h4>
<pre class="highlight">[14, 35, -7, 46, 98].min
[14, 35, -7, 46, 98].max</pre>
<h4>Parallel Processing</h4>
<pre class="highlight">require 'parallel'

Parallel.map(lots_of_data) do |chunk|
  heavy_computation(chunk)
end</pre>
<p>Unlike Scala, multicore support is not built-in. It requires <a href="https://github.com/grosser/parallel">parallel</a> or a similar gem.</p>
<h4>Sieve of Eratosthenes</h4>
<p>The Scala one liner is very clever, but entirely unreadable. A simpler implementation that is no longer a one-liner in Ruby would be:</p>
<pre class="highlight">index = 0
while primes[index]**2 <= primes.last
      prime = primes[index]
      primes = primes.select { |x| x == prime || x % prime != 0 }
      index += 1
end
p primes
</pre>
<p>This last example is <a href="http://stackoverflow.com/questions/241691/sieve-of-eratosthenes-in-ruby" target="_blank">straight from StackOverflow</a>. Not the prettiest code ever, but you get the idea.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://programmingzen.com/2011/06/02/10-ruby-one-liners-to-impress-your-friends/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>On Scala&#8217;s future</title>
		<link>http://programmingzen.com/2009/08/07/on-scalas-future/</link>
		<comments>http://programmingzen.com/2009/08/07/on-scalas-future/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 19:45:34 +0000</pubDate>
		<dc:creator>Antonio Cangiano</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://antoniocangiano.com/?p=1021</guid>
		<description><![CDATA[Kenneth McDonald posted the following question about Scala&#8217;s future in the Scala mailing list: I thought it would be interesting to find out people&#8217;s predictions for how much of the Java market Scala will eventually penetrate. It&#8217;s nice to see Scala doing reasonably well so far, so now&#8217;s your chance to make a prediction on [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<p>Kenneth McDonald posted the following question about <a href="http://www.scala-lang.org/">Scala</a>&#8217;s future <a href="http://www.nabble.com/Question%3APredictions-on-penetration-of-Scala--to24869246.html">in the Scala mailing list</a>:</p>
<blockquote><p>I thought it would be interesting to find out people&#8217;s predictions for how much of the Java market Scala will eventually penetrate. It&#8217;s nice to see Scala doing reasonably well so far, so now&#8217;s your chance to make a prediction on the future of Scala:</p>
<p>a) Scala will remain a niche language, competing with Groovy, JRuby, etc.<br />
b) Scala will become the dominant &#8220;second&#8221; language for the <span class="caps">JVM</span>.<br />
c) Scala will actually become big enough to compete with Java in many respects.</p>
<p>If none of these fit your outlook, feel free to make up your own answer.</p></blockquote>
<p>In my opinion, the answer will be A (niche) or B (second language), depending on the community&#8217;s ability to:</p>
<ul>
<li>Promote Scala (and <a href="http://liftweb.net/">Liftweb</a>);</li>
<li>Simplify the process of switching from Java (e.g., by providing familiar tools) as much as possible;</li>
<li>Provide worthy reasons to switch (e.g., killer apps). People rarely go to the trouble of switching just because something is &#8220;nicer&#8221;, even if in reality it causes one to write more robust code that takes advantage of higher order abstractions and a &#8220;safe and coherent&#8221; type system. Liftweb and concurrency through the Actor model / Akka are definitely two examples of a step in the right direction, as they do a particularly good job of solving a specific problem and showcase the value of adopting Scala as a user, as well as a tool to implement libraries and reusable components.</li>
</ul>
<p>The software development community is embracing dynamically typed languages like Python and Ruby, as well as functional programming. Languages like Python and Ruby simplify the development process for a beginner. They are easy to read, learn and use. Their adoption is therefore growing quickly. They also offer practical solutions to web development needs through frameworks like Rails and Django.</p>
<p>The paradigm shift to functional programming is much slower however. Functional programming done a la Scala, is undoubtedly advantageous for the competent software engineer, but moving from Java to Scala requires significant commitment and a higher degree of understanding about how to program, in my opinion. Are Java developers up to this? Some of them are, but I doubt that a majority of them would be. It should be noted that Scala has the potential to also attract developers who don&#8217;t program in Java, but rather come from a different background, such as the aforementioned Python and Ruby. These people may look into Scala as a more functional-oriented, robust and faster alternative.</p>
<p>This, coupled with the current, limited popularity of Scala, leads me to believe that option C (let&#8217;s say ~50% marketshare) is not a realistic option for the foreseeable future. We are entering the long tail period of programming, where many lesser known languages will start gaining some traction. Achieving a &#8220;second language&#8221; status is still an ambitious and worthy goal. There are many formidable opponents aiming for that, including JRuby, Jython, Groovy, and Clojure, and the rewards for doing so would be substantial for everyone involved.</p>
<p>The real question is not how far Scala is capable of going in terms of adoption, but rather what can be done to ensure that it will achieve widespread acceptance, however that may be defined. Paying close attention to the success stories of Ruby and Python may give the community some insight as to what should be done. To a minor extent, fellow functional programming languages like Erlang and Haskell are doing a fine job marketing-wise and are gaining traction. As of 3.30 pm today, there are 147 members in the irc channel for Scala, and 576 for Haskell. This is not to say that one is better than the other, or even that Haskell is more popular than Scala in general, but rather that there may be something to learn from a &#8220;similar&#8221; language, that poses compatible challenges for those who intend to approach it.</p>
<p>Being based on the <span class="caps">JVM</span>, well integrated with Java, and to a certain extent being Java-like, are all major advantages that may help Scala&#8217;s ability to gain major popularity. And being ingrained in the Java world, will affect the way Scala&#8217;s image and the ways it can be promoted as well. Whereas Ruby has a somewhat anti-corporate spirit and image, and is tough to sell to the Enterprise world, Scala doesn&#8217;t face these challenges. As such it may appeal to a much larger category of developers and companies. However, a lot of work will be required to reach that tipping point. Scala is already an excellent language, as far as I can see, but it will be a combination of technical efforts and marketing to really decide Scala&#8217;s popularity.</p>
<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://programmingzen.com/2009/08/07/on-scalas-future/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

