<?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:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	>

<channel>
	<title>thomasknierim.com</title>
	<link>http://www.thomasknierim.com</link>
	<description>Software development with Java, Scala, and PHP</description>
	<pubDate>Tue, 25 Nov 2008 07:44:23 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.3.1</generator>
	<language>en</language>
			<item>
		<title>Make WAR with Eclipse</title>
		<link>http://www.thomasknierim.com/81/web-development/make-war-with-eclipse/</link>
		<comments>http://www.thomasknierim.com/81/web-development/make-war-with-eclipse/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 06:31:40 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Web Development]]></category>

		<category><![CDATA[create]]></category>

		<category><![CDATA[Eclipse]]></category>

		<category><![CDATA[export]]></category>

		<category><![CDATA[WAR]]></category>

		<category><![CDATA[web application archive]]></category>

		<category><![CDATA[Web archive]]></category>

		<category><![CDATA[WTP]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/81/web-development/make-war-with-eclipse/</guid>
		<description><![CDATA[No, it has nothing to do with armed conflict. Making WAR files is the Java way of packaging, distributing, and deploying web applications. While JAR stands for “Java archive”, WAR stands for “Web application archive”, or simply “Web archive”. In fact, the JAR and WAR formats are both gzipped directories that include a manifest. While [...]]]></description>
			<content:encoded><![CDATA[<p>No, it has nothing to do with armed conflict. Making WAR files is the Java way of packaging, distributing, and deploying web applications. While JAR stands for “Java archive”, WAR stands for “Web application archive”, or simply “Web archive”. In fact, the JAR and WAR formats are both gzipped directories that include a manifest. While a JAR file typically contains a collection of class files, a WAR file contains the entire content that goes into a Java Web application. More precisely, a WAR file contains all the static content, directories, JSPs, beans and classes, libraries, as well as the web.xml deployment descriptor. If you unpack a WAR file, you get a directory structure that mirrors the document root of a deployed application in a web container, such as Tomcat. I recently had to create a Web application in Eclipse. I realised that despite having worked with Eclipse for five years, this is something I never did before, because in the past I used Netbeans for creating web applications. But it&#8217;s just as easy in Eclipse. Here are is how:</p>
<p>To create a Java web project, you need to have the following software installed: a Java JDK, a recent version of Eclipse that contains the WTP <em>Web Tools Platform</em> module for Eclipse, and a web container or an application server, such as Tomcat, JBoss, WebSphere, etc.</p>
<p>1&#8230;Select <em>File/New/Project</em> from the menu. The following dialogue appears:</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img01.png" alt="webapp-img01.png" style="clear: both; margin: 16px 0px" /></p>
<p>2&#8230;Select <em>Dynamic Web Project</em> from the list and click on the <em>Next</em> button.<br />
<img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img02.png" alt="webapp-img02.png" style="clear: both; margin: 16px 0px" /></p>
<p>3&#8230;Type a name for the new project and select a file system location for it. In the <em>Target Runtime</em> option, specify the web container or application server you using. This server is used to build and deploy your web application. If the drop-down box does not contain the desired server, click New&#8230; and select one of the predefined configurations (see Step 4). If you have already defined a <em>Target Runtime</em>, you can skip ahead to Step 6. The <em>Dynamic Web Module version</em> option specifies the architecture you are going to use in the web project. Select the latest version for a new project. Unfortunately, this cannot be changed later. By clicking the <em>Modify&#8230;</em> button in the Configuration section, you can select “facets” for your web application. What Eclipse calls “facets” are various building blocks and APIs, such as Java Server Faces, Java Persistence API, etc., that add functionality to your application.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img03.png" alt="webapp-img03.png" style="clear: both; margin: 16px 0px" /></p>
<p>4&#8230;The <em>New&#8230;</em> button in the Target Runtime section opens a dialogue that lets you select the server on which the application is developed and deployed, which is probably the most important aspect of your configuration. Eclipse offers a number of common configurations for popular servers. If you cannot find your server in this list, click on the <em>Download additional server adapters</em> link and chances are that your server is listed. Make sure that the <em>Create a new local server</em> option is checked, so that you can find the server in the Eclipse server view later on.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img04.png" alt="webapp-img04.png" style="clear: both; margin: 16px 0px" /></p>
<p>5&#8230;Once you specified the server type, you need to provide some details about it, such as the installation directory of the server, or the server root, and the JRE you want the server to run on. Click <em>Finish </em>when done.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img05.png" alt="webapp-img05.png" style="clear: both; margin: 16px 0px" /></p>
<p>6&#8230;Finally, the dynamic web project wizard prompts you for some basic configuration data. The <em>Context Root</em> is the name that the web container matches with the  location where the application is deployed and simultaneously constitutes the root URL for the web application. The <em>Content Directory</em> specifies the name of the directory that contains the web application files. The <em>Java Source Directory</em> specifies the name of the directory that contains Java source code files. These settings are only relevant to the development machine. Make sure that the <em>Generate deployment descriptor</em> option is checked in order to automatically create the web.xml file. In most cases, you can probably accept the default settings and click <em>Finish</em>.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img06.png" alt="webapp-img06.png" style="clear: both; margin: 16px 0px" /></p>
<p>7&#8230;Voilá. You have created a web application, or rather the framework for its development in Eclipse. The new project should now be visible in the <em>Navigator</em> view. There aren&#8217;t any files yet, except the ones which were generated automatically by Eclipse. The next step would be to write your web application, and possibly incorporating the application framework of your choice. Piece of cake.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img07.png" alt="webapp-img07.png" style="clear: both; margin: 16px 0px" /></p>
<p>8&#8230;The <em>Server</em> view should display the server you have chosen for your project. If everything went OK, you can start and stop the server from this view. The server can be started in normal mode, debug mode, or profiling mode. Debug mode needs to be selected if you want to define breakpoints in your Java code. While you edit sources, such as JSP files, servlets, bean classes, static content, etc., Eclipse automatically redeploys these resources to the running server as soon as you save them. You can view your web application in a separate browser window and receive debug output in Eclipse&#8217;s <em>Console </em>view.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img08.png" alt="webapp-img08.png" style="clear: both; margin: 16px 0px" /></p>
<p>9&#8230;After you have written your formidable web application, it&#8217;s time to share it with the world, or in more technical terms, to distribute and deploy it. The process of creating a distributable WAR file is extremely simple. Select <em>File/Export</em> from the Eclipse menu and click on the <em>WAR file</em> option in the <em>Web</em> category.</p>
<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/11/webapp-img09.png" alt="webapp-img09.png" style="clear: both; margin: 16px 0px" /></p>
<p>10&#8230;After clicking the <em>Next </em>button, specify the web project to be packaged, the file destination, and the target server. Although the latter is not a mandatory option, it is probably an important one. The selected server is likely to be the same as the one chosen in Step 3. Click <em>Finish </em>and there you have your masterpiece in a handy WAR format.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/81/web-development/make-war-with-eclipse/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pocket PCs Suck!</title>
		<link>http://www.thomasknierim.com/80/tech-trends/pocket-pcs-suck/</link>
		<comments>http://www.thomasknierim.com/80/tech-trends/pocket-pcs-suck/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 10:39:20 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Tech Trends]]></category>

		<category><![CDATA[business device]]></category>

		<category><![CDATA[maintenance]]></category>

		<category><![CDATA[Pocket PC]]></category>

		<category><![CDATA[suck]]></category>

		<category><![CDATA[toy]]></category>

		<category><![CDATA[usability]]></category>

		<category><![CDATA[Windows Mobile]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/80/tech-trends/pocket-pcs-suck/</guid>
		<description><![CDATA[Pocket PCs suck! Well, they do at least suck sometimes, namely when they don&#8217;t function. To be fair, I have to say that Pocket PCs are great as long as they work. Since a Pocket PC is like a miniature computer, it offers a functional range and programmability that surpasses almost any other mobile device. [...]]]></description>
			<content:encoded><![CDATA[<p>Pocket PCs suck! Well, they do at least suck sometimes, namely when they don&#8217;t function. To be fair, I have to say that Pocket PCs are great as long as they work. Since a Pocket PC is like a miniature computer, it offers a functional range and programmability that surpasses almost any other mobile device. Unfortunately, this leads to complexity, and complexity leads to bugs which in turn leads to malfunctioning devices. I&#8217;ve been using Pocket PCs for two years now and have developed sort of a love-hate relationship. Probably the culprit is the Windows Mobile operating system. Windows Mobile, although already in version 6, evokes bad memories of the buggy Microsoft operating systems of the nineties. Only that this isn&#8217;t the nineties. After ten or fifteen years of consumer mobile phones, we have come to expect mobile devices to work flawlessly. In fact, I am relying on my Pocket PC for many day-today tasks. I use it as a phone, alarm clock, notepad, camera, phone book, and mp3 player and more. My HP iPaq Business Navigator also has an assisted GPS, but I came to see the latter as a toy function. Due to usability issues I hardly bother to fiddle with it.</p>
<p>However, the question I am asking myself now is – isn&#8217;t this device just an expensive toy? Where is the robustness that should come with a &#8220;business&#8221; device . I have put in a good deal of time just to keep my pocket PC working. My HP PPC has seen the service shop twice, once because of a faulty memory chip, and another time because it didn&#8217;t boot anymore until the shop installed a firmware upgrade. In addition to that, I have spent a fair number of hours with configuration and trouble-shooting because one or another function was broken. Once I get a working configuration with all the software installed, I use Spb Backup to create a complete backup of the system. Spb Backup is a real life-saver. It backs up all configuration data, user data, applications and system data. Should the device give up its ghost or display odd behaviour (believe me, every Pocket PC will do that at some point), I can perform a factory reset and restore the backup to recreate the former status of the device easily. But even with this tool, the amount of maintenance required seems a little excessive. A gadget that carries the name “Business Navigator” should be expected to work like a business device, namely reliably. Unfortunately, I can&#8217;t say that for the HP iPaq and neither for the other Pocket PCs I&#8217;ve owned and used. As previously mentioned, I am not blaming the hardware manufacturers. The OS seems to be the crux.</p>
<p>Real business users would probably be better off with a smartphone that requires less messing around. A Pocket PC is more suited to -shall I put it this way- the technically inclined person.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/80/tech-trends/pocket-pcs-suck/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Emusic Blues</title>
		<link>http://www.thomasknierim.com/79/internet/emusic-blues/</link>
		<comments>http://www.thomasknierim.com/79/internet/emusic-blues/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 16:20:47 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Tech Trends]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/79/internet/emusic-blues/</guid>
		<description><![CDATA[Until earlier this month I was a short-time subscriber to emusic.com. Extremely short-time. Nine days to be precise. For those of you who don&#8217;t know emusic.com - it&#8217;s an online music store where you can (legally!) buy music in MP3 format on a monthly subscription basis. Emusic.com specialises in independent labels. It offers a total [...]]]></description>
			<content:encoded><![CDATA[<p>Until earlier this month I was a short-time subscriber to emusic.com. Extremely short-time. Nine days to be precise. For those of you who don&#8217;t know emusic.com - it&#8217;s an online music store where you can (legally!) buy music in MP3 format on a monthly subscription basis. Emusic.com specialises in independent labels. It offers a total of 4.5 million tracks for download with a fairly good selection of Jazz music, which was the reason I subscribed. So, I get DRM-free MP3 tracks at roughly 25 cents per track. Sounds perfect. What went wrong? Well, on the ninth day I looked at the emusic.com site and it said: “We&#8217;re sorry but eMusic is not currently available in your area.” Bummer. I was neither able to log into my account anymore, nor could I download any music. I contacted the their customer service to ask what had happened. No response. I contacted them again. No response. Only after threatening to initiate a chargeback procedure with my credit card company did I get a reply. It repeated the message, namely that eMusic wasn&#8217;t available anymore in my country. It also promised a refund. Oh well. - As for the reason why eMusic suddenly unplugged Thailand (and possibly other countries as well) I can only guess. It must have to do something with contracts, record labels, and anti-piracy policies. Clearly, the music industry is shooting into its own foot by taking such steps. Now emusic.com has become one of several online music stores that is not available in Thailand. Another one is Amazon, which also offers MP3 music. Consumers in Thailand and other countries are thus left with two options. Either buy music in DRM-crippled format for the same price as a physical CD, or turn to other more doubtful sources. You can probably guess what most people would do in this situation. Since I am a hobby musician, I would very much prefer to pay artists for their work. However, given the current situation in Thailand it has almost become impossible to acquire music legally in MP3 format.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/79/internet/emusic-blues/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Scala Tutorial (2)</title>
		<link>http://www.thomasknierim.com/77/scala/scala-tutorial-2/</link>
		<comments>http://www.thomasknierim.com/77/scala/scala-tutorial-2/#comments</comments>
		<pubDate>Tue, 07 Oct 2008 06:10:56 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/77/scala/scala-tutorial-2/</guid>
		<description><![CDATA[Scala is a purely object-oriented language in the sense that all language constructs are objects. This includes all primitive type values, such as Char, Int, Long, Float etc. For example, it is perfectly legal in Scala to append a method call to a literal primitive value, as in 3.1415.round or 88.max(99). Scala defines the following [...]]]></description>
			<content:encoded><![CDATA[<p>Scala is a purely object-oriented language in the sense that all language constructs are objects. This includes all primitive type values, such as Char, Int, Long, Float etc. For example, it is perfectly legal in Scala to append a method call to a literal primitive value, as in <code>3.1415.round</code> or <code>88.max(99)</code>. Scala defines the following basic types:</p>

<div class="wp_syntax"><div class="code"><pre class="java java" style="font-family:monospace;"><span style="color: #003399;">Byte</span>     <span style="color: #cc66cc;">8</span><span style="color: #339933;">-</span>bit <span style="color: #003399;">Integer</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">7</span> to <span style="color: #cc66cc;">2</span> <span style="color: #339933;">^</span><span style="color: #cc66cc;">7</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">Short</span>    <span style="color: #cc66cc;">16</span><span style="color: #339933;">-</span>bit <span style="color: #003399;">Integer</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">15</span> to <span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">15</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
Int      <span style="color: #cc66cc;">32</span><span style="color: #339933;">-</span>bit <span style="color: #003399;">Integer</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">31</span> to <span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">31</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">Long</span>     <span style="color: #cc66cc;">64</span><span style="color: #339933;">-</span>bit <span style="color: #003399;">Integer</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">64</span> to <span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">64</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
Char     <span style="color: #cc66cc;">16</span><span style="color: #339933;">-</span>bit Unicode character <span style="color: #009900;">&#40;</span>0 to <span style="color: #cc66cc;">2</span><span style="color: #339933;">^</span><span style="color: #cc66cc;">16</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span>
<span style="color: #003399;">String</span>   A sequence of Chars
<span style="color: #003399;">Float</span>    <span style="color: #cc66cc;">32</span><span style="color: #339933;">-</span>bit IEEE <span style="color: #cc66cc;">754</span> single<span style="color: #339933;">-</span>precision floating point number
<span style="color: #003399;">Double</span>   <span style="color: #cc66cc;">64</span><span style="color: #339933;">-</span>bit IEEE <span style="color: #cc66cc;">754</span> double<span style="color: #339933;">-</span>precision floating point number
<span style="color: #003399;">Boolean</span>  Logical value <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span> or <span style="color: #000066; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span></pre></div></div>

<p>These data types are defined in the package <code>scala</code>, which is imported automatically along with <code>scala.lang</code> by the compiler. Extended functionality for these types (such as the cited max() function) is available via the <code>scala.runtime</code> API. Each type has an associated &#8220;rich wrapper class&#8221;, e.g for <code>String</code> there is a <code>RichString</code> class, for <code>Int</code> there is a <code>RichInt</code> class, and so on. Unlike Java, Scala does not distinguish between objects and primitive types. This implies that there are no boxing and unboxing functions and thus less to worry about the semantic details of these operations. Everything is simply an object. Behind the scenes the compiler performs optimisations that amount to auto-unboxing when arithmetic expressions are evaluated. Hence, the expression <code>a + b * c</code> which is equivalent to method calls <code>b.*(c).+(a)</code> is actually resolved to a primitive type arithmetic, just like in Java.</p>
<p>Scala is not only object-oriented in the sense that all variables are objects, irrespective of type, but that all functions including methods are also objects. Since functions and methods are objects, they are treated just like regular variables, which means that functions can be assigned to variables. They can also be used as parameters in function calls or as return values of functions and methods. A function value in the position of a function parameter creates a so-called higher-order function. In addition, Scala has a construct called a function literal which is basically a nameless function used in place of a function value, a bit like an anonymous method in Java, although the former are a lot more versatile. Furthermore, operators in Scala are methods. This makes some sort of operator overloading possible. Since <code>+,-,*,/</code> etc. are just methods with funny names, you can define operators for your own data types. It is therefore possible to extend the language by adding APIs that contain class definitions for new data types along with their operators. This is illustrated by the following class definition for rational numbers. Rational numbers can be expressed as a fraction of two integer numbers. The following class defines the data type Rational as well as the four basic arithmetic operations for rational numbers:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="scala scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">class</span> Rational<span style="color: #F78811;">&#40;</span>numerator<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span>, denominator<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span><span style="color: #F78811;">&#41;</span> <span style="color: #F78811;">&#123;</span>
&nbsp;
  require<span style="color: #F78811;">&#40;</span>denominator <span style="color: #000080;">!=</span> 0<span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">val</span> gcd <span style="color: #000080;">=</span> greatestCommonDivisor<span style="color: #F78811;">&#40;</span>numerator.<span style="color: #000000;">abs</span>,
    denominator.<span style="color: #000000;">abs</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #0000ff; font-weight: bold;">val</span> n <span style="color: #000080;">=</span> numerator / gcd
  <span style="color: #0000ff; font-weight: bold;">val</span> d <span style="color: #000080;">=</span> denominator / gcd
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> <span style="color: #0000ff; font-weight: bold;">this</span><span style="color: #F78811;">&#40;</span>n<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span><span style="color: #F78811;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000ff; font-weight: bold;">this</span><span style="color: #F78811;">&#40;</span>n, <span style="color: #F78811;">1</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">private</span> <span style="color: #0000ff; font-weight: bold;">def</span> greatestCommonDivisor<span style="color: #F78811;">&#40;</span>a<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span>, b<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span><span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span> <span style="color: #000080;">=</span>
  <span style="color: #0000ff; font-weight: bold;">if</span> <span style="color: #F78811;">&#40;</span>b <span style="color: #000080;">==</span> 0<span style="color: #F78811;">&#41;</span> a <span style="color: #0000ff; font-weight: bold;">else</span> greatestCommonDivisor<span style="color: #F78811;">&#40;</span>b, a <span style="color: #000080;">%</span> b<span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> + <span style="color: #F78811;">&#40;</span>that<span style="color: #000080;">:</span> Rational<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Rational <span style="color: #000080;">=</span>
  <span style="color: #0000ff; font-weight: bold;">new</span> Rational<span style="color: #F78811;">&#40;</span>n <span style="color: #000080;">*</span> that.<span style="color: #000000;">d</span> + d <span style="color: #000080;">*</span> that.<span style="color: #000000;">n</span>, d <span style="color: #000080;">*</span> that.<span style="color: #000000;">d</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> - <span style="color: #F78811;">&#40;</span>that<span style="color: #000080;">:</span> Rational<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Rational <span style="color: #000080;">=</span>
  <span style="color: #0000ff; font-weight: bold;">new</span> Rational<span style="color: #F78811;">&#40;</span>n <span style="color: #000080;">*</span> that.<span style="color: #000000;">d</span> - d <span style="color: #000080;">*</span> that.<span style="color: #000000;">n</span>, d <span style="color: #000080;">*</span> that.<span style="color: #000000;">d</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> <span style="color: #000080;">*</span> <span style="color: #F78811;">&#40;</span>that<span style="color: #000080;">:</span> Rational<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Rational <span style="color: #000080;">=</span>
  <span style="color: #0000ff; font-weight: bold;">new</span> Rational<span style="color: #F78811;">&#40;</span>n <span style="color: #000080;">*</span> that.<span style="color: #000000;">n</span>, d <span style="color: #000080;">*</span> that.<span style="color: #000000;">d</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">def</span> / <span style="color: #F78811;">&#40;</span>that<span style="color: #000080;">:</span> Rational<span style="color: #F78811;">&#41;</span><span style="color: #000080;">:</span> Rational <span style="color: #000080;">=</span>
  <span style="color: #0000ff; font-weight: bold;">new</span> Rational<span style="color: #F78811;">&#40;</span>n <span style="color: #000080;">*</span> that.<span style="color: #000000;">d</span>, d <span style="color: #000080;">*</span> that.<span style="color: #000000;">n</span><span style="color: #F78811;">&#41;</span>
&nbsp;
  <span style="color: #0000ff; font-weight: bold;">override</span> <span style="color: #0000ff; font-weight: bold;">def</span> toString <span style="color: #000080;">=</span> n + <span style="color: #6666FF;">&quot;/&quot;</span> + d
<span style="color: #F78811;">&#125;</span></pre></td></tr></table></div>

<p>The first line contains the head of the class with the so-called primary constructor, which is part of the class declaration in Scala. The expression in parentheses accepts two integer numbers that constitute the numerator and the denominator of the fraction. The next line that starts with <code>require</code> tests the denominator for zero and throws an exception if <code>denominator = 0</code>. As you can see, exceptions don&#8217;t need to be declared in the head of the class definition in Scala. The following three lines reduce the fraction by calculating the greatest common divisor and subsequently dividing the numerator and denominator by the result. These first four lines are not enclosed by a function definition block or any other block and thus constitute the body of the primary constructor. Next follows what&#8217;s called a auxiliary constructor in Scala. Auxiliary constructors are easy to spot, because they always start with <code>this()</code>. The expression <code>def this(n: Int) = this(n, 1)</code> provides a constructor that accepts a single integer number as an argument. This makes it easy to represent integer numbers as fractions where needed simply by setting the denominator implicitly to 1. For example, the expression <code>new Rational(2,3)</code> results in 2/3 and the expression <code>new Rational(2)</code> results in 2/1.</p>
<p>The method definition that follows the constructor code computes the greatest common integer divisor of two numbers using recursion. Since the recursive invocation stands in tail-call position in this instance, the Scala compiler optimises the generated byte code  internally and creates a loop instead of a recursive function call. The four methods after the <code>greatestCommonDivisor()</code> method define the four basic arithmetic operations for fractions. In case of addition and subtraction, the numerators and denominators of both operands are multiplied with each other before the sum of the numerators is calculated. In doing so, Scala makes use of built-in operator precedence (* and / before + and -), which is determined lexically if the function or method name begins with a special operator characters. The expression  <code>n * that.d + d * that.n</code>, is thus executed as <code>n.*(that.d).+.(d.*(that.n))</code>. Multiplication and division are even easier to implement as the two fractions are simply multiplied by each other, or respectively multiplied by the reciprocal value. The results are then returned as new <code>Rational</code> objects. Since the constructor finds the GCD of the two integer numbers, the resulting fraction is automatically reduced. Finally, the last method <code>toString</code> outputs the fraction in a readable form. Overridden methods must be marked with the <code>override</code> keyword in Scala. Functions that don&#8217;t take arguments are written without parentheses, hence <code>toString()<code> becomes <code>toString</code>.</code></code></p>
<p>Class Hierarchy</p>
<p><a href="http://www.thomasknierim.com/wp-content/uploads/2008/10/scala-hierarchy.png" title="Scala Hierarchy"><img src="http://www.thomasknierim.com/wp-content/uploads/2008/10/scala-hierarchy.thumbnail.png" alt="Scala Hierarchy" /></a>Similar to Smalltalk, every class inherits from a single common superclass. The universal superclass is named <code>Any</code> in Scala. This is to say that any datum in Scala is of the type <code>Any</code>. The subclasses of <code>Any</code> fall into two categories: <code>AnyVal</code> (value) and <code>AnyRef</code> (object reference). The above listed basic data types, as well as the primitive types in Java, such as <code>byte, int, float,</code> etc., are direct descendants of <code>AnyVal</code>, while all other types are descendants of <code>AnyRef</code>. The Scala type <code>AnyRef</code> is therefore conceptually identical with <code>java.lang.Object</code> and it comes with analogous methods, e.g. <code>equals(), hashCode, clone, wait,</code> etc. Some of these are actually defined further up in the hierarchy, namely in <code>Any</code>. In addition, Scala defines the type <code>scala.scalaObject</code> which provides the common superclass for all objects in the Scala APIs. This works because Scala allows multiple inheritance via so-called traits. This will be explained later in more detail.</p>
<p>The nesting of this type hierarchy allows interoperability wit Java. For example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="scala scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">var</span> a<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">int</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">2</span>    <span style="color: #008000; font-style: italic;">// Java Integer</span>
<span style="color: #0000ff; font-weight: bold;">var</span> b<span style="color: #000080;">:</span> <span style="color: #9999cc; font-weight: bold;">Int</span> <span style="color: #000080;">=</span> <span style="color: #F78811;">3</span>    <span style="color: #008000; font-style: italic;">// Scala Integer</span>
println<span style="color: #F78811;">&#40;</span>a + b<span style="color: #F78811;">&#41;</span>    <span style="color: #008000; font-style: italic;">// 5</span></pre></td></tr></table></div>

<p>In addition, it is possible to use Java collections for storing Scala data types, or Scala collections for storing Java data types. Furthermore, Scala has several special data types. For example, <code>scala.Null</code> is defined as subtype of any class that derives from an object reference <code>scala.AnyRef</code>. It is analogous to the <code>null</code> literal in Java and can thus be assigned to object references. The type <code>scala.Nothing</code> is defined as a subtype of all types; it is employed in exceptions where an expression does not return a type. This happens situations where an exception is thrown in a place where a value is expected. Finally, there is the type <code>scala.Unit</code> that is used for functions that don&#8217;t return a value. This is Scala&#8217;s concession to imperative programming. It is analogous to the <code>void</code> keyword in Java.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/77/scala/scala-tutorial-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>HTML 5 Preview</title>
		<link>http://www.thomasknierim.com/76/web-development/html-5-preview/</link>
		<comments>http://www.thomasknierim.com/76/web-development/html-5-preview/#comments</comments>
		<pubDate>Fri, 26 Sep 2008 15:29:53 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Internet]]></category>

		<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/76/web-development/html-5-preview/</guid>
		<description><![CDATA[Because HTML is at the very core of the World Wide Web, you would expect it to be a mature and refined technology. You would also expect it to provide a flexible platform for Web application development and deployment. As most web developers know, the reality is a bit different. HTML started out as a [...]]]></description>
			<content:encoded><![CDATA[<p>Because HTML is at the very core of the World Wide Web, you would expect it to be a mature and refined technology. You would also expect it to provide a flexible platform for Web application development and deployment. As most web developers know, the reality is a bit different. HTML started out as a rather simple SGML application for creating hyperlinked documents. It originally provided a basic set of elements for data viewing, data input, and formatting, whereas it did a little bit of all, yet nothing quite right. While this was practical for whipping up quick-and-dirty websites, it proved to be inadequate for more demanding presentation tasks and fine-tuned user interaction. Thus a whole bunch of supplemental technologies came into being, including CSS, JavaScript, Flash and finally AJAX. You know the story. All of this was quite a messy affair and unfortunately it still is.</p>
<p>While the HTML 4.01 specification has ruled the Web since 1999, the fifth incarnation of HTML was released by the W3C as a working draft earlier this year and is constantly updated since then. The HTML 5 specification is supposed to pave the way for future Web standards. It contains an older draft of W3C dubbed “Web Forms 2.0”, which is W3C&#8217;s answer to Web 2.0 and the World Wide Web becoming a platform for distributed applications. Don&#8217;t expect anything too radical, though. It neither delivers the hailed “rich GUI” for the Internet, nor will it replace current technologies like AJAX. It is rather designed as a natural extension of the former. It provides good backward compatibility while smoothing some of the rough edges of HTML. No more no less. Let&#8217;s have a look at the new features in more detail.</p>
<p>HTML 5 mends the split between the preceding HTML 4 and XHTML 1.0 specifications. Rather than being defined in terms of syntactical rules, it makes the DOM tree its conceptual basis. Thus HTML 5 can be expressed in two similar syntaxes, the “traditional” one and the XML syntax, which both result in the same DOM tree. It goes far beyond the scope of previous specifications, for example by spelling out how markup errors are handled, rather than leaving it to browser vendors, and by specifying APIs for new and old elements. These APIs describe how scripting languages interact with HTML. So, what&#8217;s new? The following elements have been dropped from the specification:</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em">
<li> &lt;acronym&gt;</li>
<li> &lt;applet&gt;</li>
<li> &lt;basefont&gt;</li>
<li> &lt;center&gt;</li>
<li> &lt;dir&gt;</li>
<li> &lt;font&gt;</li>
<li> &lt;frame&gt;</li>
<li> &lt;frameset&gt;</li>
<li> &lt;isindex&gt;</li>
<li> &lt;noframes&gt;</li>
<li> &lt;s&gt;</li>
<li> &lt;small&gt;</li>
<li> &lt;strike&gt;</li>
<li> &lt;tt&gt;</li>
<li> &lt;u&gt;</li>
<li> &lt;xmp&gt;</li>
</ul>
<p>The following <em>attributes</em> are also goners:</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em"> abbr, accesskey, align, alink, axis, background, bgcolor, border, cellpadding and cellspacing, char, charoff, charset, classid, clear, compact, codebase, codetype, coords, declare, frame, frameborder, headers, height, hspace, language, link, marginheight and marginwidth, name, nohref, noshade, nowrap, profile, rules, rev, scope, scrolling, shape, scheme, size, standby, summary, target, text, type, valuetype, valign, version, vlink, width.</ul>
<p>Some of these <em>elements</em> and <em>attributes</em> are quite obscure, so perhaps they won&#8217;t be missed. Others like &lt;center&gt;, align, background, and &lt;u&gt; were heavily used in the past, although most of these were already deprecated in HTML 4. The message here is clear: get rid of presentational markup and use CSS instead. The &lt;b&gt;, &lt;i&gt;, &lt;em&gt; and &lt;strong&gt; tags have miraculously survived, however. Although primarily used for text formatting in the past, these tags have been assigned new (non-presentational) semantics to make them respectable. Another conspicuous omission are frames. Yes, frames are gone! But you might breath a sigh of relief to know that &lt;iframe&gt; is still there. Speaking presentational versus semantic HTML, there are quite a few additions to HTML 5 in the latter category. The new semantic tags are designed to aid HTML authors in structuring text and to make it easier for search engine crawlers to parse information in web pages. Here they are (explanations provided by W3C):</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em">
<li> &lt;section&gt; represents a 	generic document or application section. It can be used together 	with h1-h6 to indicate the document structure.</li>
<li> &lt;article&gt; represents an 	independent piece of content of a document, such as a blog entry or 	newspaper article.</li>
<li> &lt;aside&gt; represents a piece 	of content that is only slightly related to the rest of the page.</li>
<li> &lt;header&gt; represents the 	header of a section.</li>
<li> &lt;footer&gt; represents a footer 	for a section and can contain information about the author, 	copyright information, et cetera.</li>
<li> &lt;nav&gt; represents a section 	of the document intended for navigation.</li>
<li> &lt;dialog&gt; can be used to mark 	up a conversation in conjunction with the &lt;dt&gt; and &lt;dd&gt; 	elements.</li>
<li> &lt;figure&gt; can be used to 	associate a caption together with some embedded content, such as a 	graphic or video.</li>
<li> &lt;details&gt; represents 	additional information or controls which the user can obtain on 	demand.</li>
</ul>
<p>Most of these, except the last two, behave like the &lt;div&gt; element, which means their primary use is to identify a block of content that belongs together. Unlike &lt;div&gt; special semantics are associated with each of these elements. Not very exciting? HTML 5 also introduces the following new elements (explanations again from the W3C document):</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em">
<li> &lt;audio&gt; and &lt;video&gt; 	for multimedia content. Both provide an API so application authors 	can script their own user interface, but there is also a way to 	trigger a user interface provided by the user agent. Source elements 	are used together with these elements if there are multiple streams 	available of different types.</li>
<li> &lt;embed&gt; is used for plugin 	content.</li>
<li> &lt;mark&gt; represents a run of 	marked (highlighted) text.</li>
<li> &lt;meter&gt; represents a 	measurement, such as disk usage.</li>
<li> &lt;time&gt; represents a date 	and/or time.</li>
<li> &lt;canvas&gt; is used for 	rendering dynamic bitmap graphics on the fly, such as graphs, games, 	et cetera.</li>
</ul>
<p>The &lt;embed&gt; tag supersedes the &lt;applet&gt; and &lt;object&gt; tags. It defines some sort of embedded content that doesn&#8217;t expose its internal structure to the DOM tree. The content is typically rendered by a browser plugin. The &lt;audio&gt; and &lt;video&gt; tags are perhaps more interesting, because they make it possible to include multimedia files or streams directly into the HTML document without having to specify a vendor-specific plugin for playing the content. Granted, this could previously be done with the &lt;embed&gt; tag, but the &lt;embed&gt; tag was never a W3C standard and it isn&#8217;t supported by all browsers. Obviously, W3C has decided not to follow the mainstream browser implementations and added the &lt;audio&gt; and &lt;video&gt; tags instead, while reserving the &lt;embed&gt; tag for the above named purpose.</p>
<p>Arguably the most exciting additions to HTML 5 -at least from the perspective of a web developer- are the extensions to form processing and data rendering, and the related APIs, such as the editing API or the drag-and-drop API. These additions have previously evolved as a separate standard under the term <em>Web Forms 2.0</em> and are now incorporated into HTML 5. The &lt;input&gt; element has been enhanced to support several new data types. New elements for user interface components have been defined, similar to those that can be found in GUI applications. For example, HTML 5 finally features the long awaited combo box, a combination of text input and drop-down list, which is a standard component in GUIs for decades. A new &lt;datagrid&gt; element for the interactive/editable representation of data in tabular, list, or tree form, is also present. Here are the new &lt;input&gt; types:</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em">
<li> type=&#8221;datetime&#8221;- a date 	and time (year, month, day, hour, minute, second, fraction of a 	second) with the time zone set to UTC.</li>
<li> type=&#8221;datetime-local&#8221;- a 	date and time (year, month, day, hour, minute, second, fraction of a 	second) with no time zone.</li>
<li> type=&#8221;date&#8221; - a date 	(year, month, day) with no time zone.</li>
<li> type=&#8221;month&#8221; - a date 	consisting of a year and a month with no time zone.</li>
<li> type=&#8221;week&#8221; - a date 	consisting of a year and a week number with no time zone.</li>
<li> type=&#8221;time&#8221;- a time 	(hour, minute, seconds, fractional seconds) with no time zone.</li>
<li> type=&#8221;number&#8221; - a 	numerical value.</li>
<li> type=&#8221;range&#8221; - a 	numerical value, with the extra semantic that the exact value is not 	important.</li>
<li> type=&#8221;email&#8221;- an e-mail 	address.</li>
<li> type=&#8221;url&#8221; - an 	internationalised resource identifier.</li>
</ul>
<p>The input element also has several new attributes in HTML 5 that enhance its functionality (many of these also apply to other form controls such as &lt;select&gt;, &lt;textarea&gt;, etc.):</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em">
<li value="1"> list=&#8221;listname&#8221; 	- used in conjunction with the &lt;datalist&gt; element to create a 	combobox.</li>
<li> required - indicates that the user 	must provide an input value.</li>
<li> autofocus -  automatically focuses 	the control upon page load.</li>
<li> form - allows a single control to 	be associated with multiple forms.</li>
<li> inputmode - gives a hint to the 	user interface as to what kind of input is expected.</li>
<li> autocomplete - tells the browser 	to remember the value when the user returns to the page.</li>
<li> min - minimum value constraint.</li>
<li> max - maximum value constraint.</li>
<li> pattern - specifies pattern 	constraint.</li>
<li> step - specifies step constraint.</li>
</ul>
<p>The following new elements provide additional user interface components for web applications. The last three are actually not themselves UI components, but components used for scripting the UI through a server side language:</p>
<ul style="list-style-image: url('none'); font-weight: bold; line-height: 1.3em">
<li> &lt;command&gt; represents a 	command the user can invoke (e.g. toolbar button or icon).</li>
<li> &lt;datalist&gt; together with the 	a new list  attribute for input is used to create comboboxes.</li>
<li> &lt;output&gt; represents some 	type of output, such as from a calculation done through scripting.</li>
<li> &lt;progress&gt; represents a 	completion of a task, such as downloading or when performing a 	series of expensive operations.</li>
<li> &lt;menu&gt; represents a menu. 	The element has three new attributes: type, label and autosubmit. 	They allow the element to transform into a menu as found in typical 	user interfaces as well as providing for context menus in 	conjunction with the global contextmenu attribute.</li>
<li> &lt;datagrid&gt; represents an 	interactive representation of a tree list or tabular data.</li>
<li> &lt;ruby&gt;, &lt;rt&gt; and &lt;rb&gt; 	allow for marking up Ruby annotations.</li>
<li> &lt;eventsource&gt; represents a 	target that &#8220;catches&#8221; remote server events.</li>
<li> &lt;datatemplate&gt;, &lt;rule&gt; 	and &lt;nest&gt; provide a templating mechanism for HTML.</li>
</ul>
<p>Let&#8217;s briefly look at the new &lt;datagrid&gt; element. &lt;datagrid&gt; usually has a &lt;table&gt; child element, although &lt;select&gt; and &lt;datalist&gt; are also possible to create a tree control. The columns in the datagrid can have clickable captions for sorting. Columns, rows, and cells can each have specific flags, known as classes, which affect the functionality of the datagrid element. Rows are selectable and single cells (or all cells) can be made editable. A cell can contain a checkbox or values that can be cycled. Rows can also be separator rows. Datagrids have a DOM API for updating, inserting, and deleting rows or columns. They also have a data provider API that controls grid data content and editing.</p>
<p>I hope you found this brief overview useful. Please note that the features mentioned here don&#8217;t cover everything that is new in HTML 5, but hopefully they catch the essence. The HTML 5 specification is a work in progress; it is still changing and evolving. You can find the latest editor&#8217;s draft at <a href="http://www.w3.org/html/wg/html5/">http://www.w3.org/html/wg/html5/</a>. An overview of the changes from HTML 4 is available at <a href="http://www.w3.org/TR/html5-diff/">http://www.w3.org/TR/html5-diff/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/76/web-development/html-5-preview/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Scala Tutorial (1)</title>
		<link>http://www.thomasknierim.com/75/scala/scala-tutorial-1/</link>
		<comments>http://www.thomasknierim.com/75/scala/scala-tutorial-1/#comments</comments>
		<pubDate>Sat, 13 Sep 2008 04:06:21 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Scala]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/75/scala/scala-tutorial-1/</guid>
		<description><![CDATA[One sign of the success of the Java platform is the profusion of new languages for the Java Virtual Machine (JVM), which appeared during the past few years. Some examples are Jython, Groovy, and JRuby. These languages serve niches in domain specific development where they typically offer better productivity and time-to-market than traditional Java development. [...]]]></description>
			<content:encoded><![CDATA[<p>One sign of the success of the Java platform is the profusion of new languages for the Java Virtual Machine (JVM), which appeared during the past few years. Some examples are Jython, Groovy, and JRuby. These languages serve niches in domain specific development where they typically offer better productivity and time-to-market than traditional Java development. One language stands out, however – the Scala language. Unlike many others, Scala is not an adaptation of an existing language to the Java platform, but it has been designed for the JVM from the beginning and it is fully interoperable with the existing Java APIs.</p>
<p>What is more, Scala is a rich statically typed language that provides the ease of use of a scripting language. Scala&#8217;s object-oriented features are at least as powerful as those of Java. Scala also offers a full set of functional programming features. It is the felicitous combination of object-oriented and functional properties that makes this language interesting. As of today, Scala already has closures, support for properties, an Erlang-like concurrency API (excellent for multi-core parallel programming) as well as other advanced features that Java will only have in future releases, or possibly never. For this reason, I would like to introduce this language to interested readers in a brief tutorial. Once you get to know Scala, you might agree that it&#8217;s a fascinating language. So let&#8217;s get started. The obvious starting point is the (in-)famous “Hello World” program, or rather a slightly more involved version of it:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="scala scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">object</span> Hello <span style="color: #F78811;">&#123;</span>
  <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>args<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>
    <span style="color: #0000ff; font-weight: bold;">for</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">val</span> arg<span style="color: #000080;">:</span> String <span style="color: #000080;">&lt;</span>- args<span style="color: #F78811;">&#41;</span>
      System.<span style="color: #000000;">out</span>.<span style="color: #000000;">println</span><span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Hello, &quot;</span> + arg + <span style="color: #6666FF;">&quot;!&quot;</span><span style="color: #F78811;">&#41;</span>;
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></td></tr></table></div>

<p>Any Java programmer should be able to understand what these six lines of code do, despite it being written in a “foreign” language. The program prints a greeting for each of the arguments passed to it. The invocation “scala Hello World” prints the inspiring yet slightly trite line “Hello Word!”. For more fun, you could pass the names of all 190 and odd countries and the program would greet each nation individually. There are some obvious differences to Java. For example, there are no <code>static</code> or <code>void</code> declarations. Another obvious difference is that the program starts with an <code>object</code> definition rather than a <code>class</code> definition. In Scala, the keyword <code>object</code> creates a singleton object, which is akin to a class that contains only static members, except that the Scala <code>object</code> is able to make use of inheritance and polymorphic invocation.</p>
<p>Method definitions start with the keyword <code>def</code> in Scala. The single argument to the main method is <code>args</code> which is of type <code>Array[String],</code> meaning “array of string”. The method contains a for-loop that looks similar to the Java-5 foreach loop construct. It iterates over the elements in the string array <code>args</code>. The expression <code>val arg: String</code> is equivalent to the Java expression <code>final String arg</code>. The keyword <code>val</code> declares an immutable variable, which means that its value cannot be changed after it has been assigned a value. Scala also has mutable variables which are declared with <code>var</code> instead of <code>val</code>. The variable <code>arg</code> is of type String and it takes the value of the iterator variable. It is possible to simplify the  program a little:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="scala scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">object</span> Hello <span style="color: #F78811;">&#123;</span>  
  <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>args<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>
    <span style="color: #0000ff; font-weight: bold;">for</span><span style="color: #F78811;">&#40;</span><span style="color: #0000ff; font-weight: bold;">val</span> arg <span style="color: #000080;">&lt;</span>- args<span style="color: #F78811;">&#41;</span>
      println <span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Hello, &quot;</span> + arg + <span style="color: #6666FF;">&quot;!&quot;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></td></tr></table></div>

<p>In this version, the following items have been omitted:</p>
<p>The type declaration <code>: String</code> after <code>arg</code> was eliminated. Although Scala is a statically typed language, which means that every variable has a fixed type, it can infer type declarations automatically. In this case, it infers that the <code>arg</code> variable is of type <code>String</code> because the <code>args</code> variable is of type <code>array of String</code>. This feature is known as type inference and it contributes to making Scala source code more concise by eliminating redundant type declarations. Other examples for type inference are:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="scala scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">val</span> a <span style="color: #000080;">=</span> <span style="color: #6666FF;">&quot;Abacadabra&quot;</span>
<span style="color: #0000ff; font-weight: bold;">val</span> b <span style="color: #000080;">=</span> <span style="color: #F78811;">3.141592</span>
<span style="color: #0000ff; font-weight: bold;">val</span> c <span style="color: #000080;">=</span> Map<span style="color: #F78811;">&#40;</span><span style="color: #F78811;">1</span> -<span style="color: #000080;">&gt;</span> <span style="color: #6666FF;">&quot;alpha&quot;</span>, <span style="color: #F78811;">2</span> -<span style="color: #000080;">&gt;</span> <span style="color: #6666FF;">&quot;beta&quot;</span>, <span style="color: #F78811;">3</span> -<span style="color: #000080;">&gt;</span> <span style="color: #6666FF;">&quot;gamma&quot;</span><span style="color: #F78811;">&#41;</span></pre></td></tr></table></div>

<p>The types of the variables <code>a, b, c</code> are derived from the literal values. Variable <code>a</code> is a <code>String</code>, <code>b</code> is a <code>Double</code>, and c is a <code>Map </code>that maps <code>Integer</code> values to <code>String</code> values. The above listing also does without the <code>System.out</code> in <code>System.out.println()</code> which results in just <code>println()</code>. Since <code>println()</code> is a frequently used statement, the method context is predefined by Scala. Java programmers may think of this as an automatic static import. Another thing that is absent from the simplified version of the program is the semicolon after the <code>println()</code> call. Semicolons are mostly optional in Scala, except in situations where multiple expressions are stringed together in one line. The code already looks simple, but with Scala we can make it even more concise by replacing the for loop with a <code>foreach()</code> invocation:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="scala scala" style="font-family:monospace;"><span style="color: #0000ff; font-weight: bold;">object</span> Hello <span style="color: #F78811;">&#123;</span> 
  <span style="color: #0000ff; font-weight: bold;">def</span> main<span style="color: #F78811;">&#40;</span>args<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>
    args.<span style="color: #000000;">foreach</span><span style="color: #F78811;">&#40;</span>arg <span style="color: #000080;">=&gt;</span> println<span style="color: #F78811;">&#40;</span><span style="color: #6666FF;">&quot;Hello&quot;</span> + arg + <span style="color: #6666FF;">&quot;!&quot;</span><span style="color: #F78811;">&#41;</span><span style="color: #F78811;">&#41;</span>
  <span style="color: #F78811;">&#125;</span>
<span style="color: #F78811;">&#125;</span></pre></td></tr></table></div>

<p>The foreach construct iterates over <code>args</code>, creating a String variable <code>arg</code> variable each time and calls <code>println()</code> on every iteration. The expression with the arrow (an equals sign followed by a greater than sign) <code>this =&gt; that</code> can be read “with a given argument <code>this</code> do <code>that</code>”. It is called a function literal in Scala. Granted, in this case it doesn&#8217;t save us much typing, but if we wanted to print just the <code>arg</code> variable and if we didn&#8217;t refer to it in the expression following the arrow <code>=&gt;</code>, we could just write it as: <code>args.foreach(println), </code>which is the short form for <code>args.foreach(arg =&gt; println(arg))</code>.</p>
<p>I hope that this first glance at Scala has whetted your appetite for more. The cited examples are fairly unsophisticated. The next section, which discusses Scala&#8217;s types and object hierarchy, will introduce some more involved concepts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/75/scala/scala-tutorial-1/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Effective Java</title>
		<link>http://www.thomasknierim.com/71/java/effective-java/</link>
		<comments>http://www.thomasknierim.com/71/java/effective-java/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 09:11:07 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[books]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/71/uncategorised/effective-java/</guid>
		<description><![CDATA[Book Review: Effective Java
2nd Edition, June 2008
by Joshua Bloch
Addison Wesley, 346 pages
ISBN: 978-0-321-35668-0

This book seems to be one of the most critically acclaimed Java titles. What could I possibly add to what has been said? The acclaim is fully deserved. I had the feeling that I already learned something new and important as soon as [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.thomasknierim.com/wp-content/uploads/2008/09/effective-java.jpg" alt="Effective Java, Joshua Bloch, 2008" /><strong>Book Review: Effective Java<br />
2nd Edition, June 2008<br />
by Joshua Bloch<br />
Addison Wesley, 346 pages<br />
ISBN: 978-0-321-35668-0</strong><br />
<br clear="all" /><br />
This book seems to be one of the most critically acclaimed Java titles. What could I possibly add to what has been said? The acclaim is fully deserved. I had the feeling that I already learned something new and important as soon as I reached page twenty. This is something that I cannot say of very many books. <em>Effective Java</em> manages to be extremely useful and simultaneously extremely easy to read. However, “easy” doesn&#8217;t mean simple in this case, since many of the discussed problems are subtly complex. Some are so complex, in fact, that Java beginners might not fully understand or appreciate them. So, it&#8217;s probably not a book for beginners. On the other hand, the book is neither esoteric. The 78 items are general Java programming issues which one is likely to encounter in everyday work at some point, regardless of any specific domain. The book is written in a clear and concise language and each problem is exceptionally well reasoned. The author has a very deep understanding of the Java language, which is rather apparent and no surprise, since Joshua Bloch is one of the architects of the Java platform. Incidentally, this also means that the problems are discussed from the perspective of an API designer rather than from the perspective of an application programmer. This is useful, because it is primarily concerned with creating robust and high quality interfaces. Architects, designers, and application programmers benefit likewise from this. The items discussed in this book can probably be described as design and implementation level rationales. They are grouped by Java categories, such as generics, enums, annotations, exceptions, serialisation, as well as by more general concepts, such as  object creation, classes and interfaces, methods and concurrency. Many of the individual topics are related; therefore the author makes ample use of cross references, which is helpful for reference use. The included code examples are a joy to read; they are clear, concise, and always illustrative. While discussing the intricacies of the above named topics, Joshua Bloch casually introduces the reader to a good number of commonly used design patterns, many of which are illustrated with code examples. However, design patterns are not themselves formally discussed. The book equips Java programmers with an arsenal of relevant best practices, from comparatively simple things such as creating objects, implementing “equals()” and “hashCode()” methods to more advanced topics, such as concurrency, mutability, and thread safety. In doing so, Joshua Bloch points out quite a few quirks and peculiarities of the Java language, and he does not only point them out, but explains their practical consequences in detail. Thus, the book has great didactic value, as the reader will end up with a higher level of familiarity with the language. Reading this book is time well invested for any Java programmer.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/71/java/effective-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>The Problem With Cup Typing</title>
		<link>http://www.thomasknierim.com/70/software-engineering/cup-typing/</link>
		<comments>http://www.thomasknierim.com/70/software-engineering/cup-typing/#comments</comments>
		<pubDate>Fri, 22 Aug 2008 02:09:58 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[software]]></category>

		<category><![CDATA[typing]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/70/uncategorised/the-problem-with-coffee-typing/</guid>
		<description><![CDATA[First I should explain what I mean with cup typing. When you buy a cup of coffee, you have the choice of short, tall, or grande sized cup. Sometimes you can also choose  decaf or regular. When you declare an integer variable in Java, you have the choice of  byte, short, int, and long. Sometimes [...]]]></description>
			<content:encoded><![CDATA[<p>First I should explain what I mean with cup typing. When you buy a cup of coffee, you have the choice of short, tall, or grande sized cup. Sometimes you can also choose  decaf or regular. When you declare an integer variable in Java, you have the choice of  byte, short, int, and long. Sometimes (in languages like C++) you can also choose between signed and unsigned. The similarity is obvious. And it doesn&#8217;t end with integers. Floating point numbers come in two different flavours, namely as regular “float” values (32-bit) and as “double” values (64-bit). Characters come in the form of 7-bit, 8-bit and 16-bit encodings. In statically typed programming languages, multiplicity is the rule rather than the exception. While Fortran and Pascal offer a moderate choice of two different integers, Java offers four plus a BigInteger implementation (“extra grande”) for really large numbers. However, it&#8217;s C# that takes the biscuit in cup typing with 9 different integer types and 3 different real  types. Database systems are keeping up with this trend. For example, the popular MySQL RDBMS offers 5 different integer types and 3 different real types. Seeing the evolution from Fortran to C#, it almost appears as if type plurality has increased over time. We must ask two things: How did this come about and is it useful? We appreciate the fact that we can buy coffee in different cup sizes to match our appetite, but does the same advantage apply to data types?</p>
<p>The first question is easy to answer. Graduated types result from the fact that computer architectures have evolved in powers of two. Over several decades, the register width of the CPU of an average PC has expanded from 8 to 16 to 32 to  64 bits. Each step facilitated the use of larger types and numeric types in particular were closely matched to register width. Expressing data types in a machine-oriented way appears to be a C legacy and quite a few newer programming languages have been strongly influenced by C. - It is my contention that while curly braces and ternary operators are an acceptable C-language tradition, graduated types are definitely not. Why not? Because they counter abstraction. They hinder rather than serve the natural expression of mathematical constructs. Have you ever wondered whether you should index an array with byte- or short-sized integers? Whether you should calculate an offset using int or long values? Whether method calls comply with type widening rules? Whether an arithmetic operation might overflow? Whether a type cast may lose significant bits or not? All of this is a complete waste of time in my view. Wouldn&#8217;t it be better to let the virtual machine worry about such low-level questions, or the library if a VM is not present? Cup typing gets positively annoying when you have to write an API that is flexible enough to deal with parameters of different widths. If there&#8217;s no type hierarchy, you inevitably end up with multiple overloaded constructors and methods (one for each type) which add unnecessary bulk. The Java APIs are full of such examples and the valueOf() method is a case in point - it&#8217;s really ugly.</p>
<p>However, graduated types are beyond ugly; they are outright evil. They cause an enormous number of bugs and the small numeric types are the prime offenders. I wonder how many times a signed or unsigned byte has caused erratic program behaviour by silently overflowing. Such bugs can be hard to find and worse – they often don&#8217;t show until certain border conditions are reached. Casts that shorten types also belong to the usual suspects. I shall not even mention the insidious floating point operations that regularly unsettle newbie programmers with funny looking computation results. What numeric types does one really need? - Integer numbers and real numbers. One of each and not more. - If you want to be generous as a language designer, you can throw in an optimised implementation of a complex number type and a rational number type. However, in an object-oriented language with operator overloading, it&#8217;s fairly easy to express these in a library. The fixed comma type (sometimes called decimal type) is the subset of the rational type where the denominator is always a power of ten. So, that&#8217;s really all you need – a clean representation of the basic mathematical number systems.</p>
<p>At this point, you might object: “but the CPU register is only x bits wide,” or “how do I allocate an array of fifty thousand short values?”, or “can I still have 8-bit chars?” Unfortunately, there is no simple answer to these questions. The natural way to represent integers is to always use the machine&#8217;s native word width, but unfortunately that doesn&#8217;t solve the problem. First of all, the word width is architecture dependent. Second, it might be wasteful for large arrays that hold small numbers and on the other hand it would still be too small for applications that need big integers. The solution is of course a variable size type, i.e. an integer representation that can grow from byte size to multiple word lengths. We have variable length strings, so why shouldn&#8217;t we have variable length numbers? It seems perfectly natural. There is certainly some overhead involved, because variable length types need special encoding. The overhead will be most likely due to loading a descriptor value and/or to bit shifting operations. After all, variable length numbers don&#8217;t come for free, but they do offer tremendous advantages. They relieve the programmer from making type width decisions, as well as documenting these decisions - and worse - changing the type width later if the decision turned out to be inadequate. Furthermore, they eliminate the above mentioned bugs resulting from silent overflows and type cast errors, not to mention API proliferation due to type plurality. Thus variable length numbers are generally preferable to common fixed width types.</p>
<p>Of course, there are situations where you know that you will never need more than a byte. There are also situations where performance is paramount. In addition, APIs and libraries based on multiple fixed types are not going to disappear overnight. To provide backward compatibility and to offer optimisation pathways to the programmer, a language could present these as subsets of the mathematical type. For example, if a language defines the keyword “int” for variable length integer numbers, then “int(8)” could mean a traditional byte, “int(16)” could mean a short word, and so on. Now, this is a bit like reintroducing cup typing through the back door. Therefore the use of subtypes for general purpose computations should be discouraged. However, it&#8217;s always better to have a choice of fixed and variable types than having no variable types at all.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/70/software-engineering/cup-typing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Too much Java</title>
		<link>http://www.thomasknierim.com/69/java/too-much-java/</link>
		<comments>http://www.thomasknierim.com/69/java/too-much-java/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 06:53:05 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/69/java/too-much-java/</guid>
		<description><![CDATA[You know you had too much Java&#8230;
&#8230;when you type a company memo and begin with the heading “public static final”.
&#8230;when you drop your used paper cups on the floor stating that the garbage collector will take care of it.
&#8230;when most of your email attachments are jar files.
&#8230;when you feel lost without an application server.
&#8230;when you [...]]]></description>
			<content:encoded><![CDATA[<p>You know you had too much Java&#8230;</p>
<p>&#8230;when you type a company memo and begin with the heading “public static final”.<br />
&#8230;when you drop your used paper cups on the floor stating that the garbage collector will take care of it.<br />
&#8230;when most of your email attachments are jar files.<br />
&#8230;when you feel lost without an application server.<br />
&#8230;when you refer to your wife as domestic domain expert.<br />
&#8230;when you say “use case actor” instead of “user”.<br />
&#8230;when you attempt to subclass meeting agendas.<br />
&#8230;when you write down your shopping list in string array notation.<br />
&#8230;when you think that the “Java community process” has nothing to do with Indonesian politics.<br />
&#8230;when you begin all your annotations with an “@” sign.<br />
&#8230;when you can type “System.out.println” in less than 2 seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/69/java/too-much-java/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Parallel Programming</title>
		<link>http://www.thomasknierim.com/68/software-engineering/parallel-programming/</link>
		<comments>http://www.thomasknierim.com/68/software-engineering/parallel-programming/#comments</comments>
		<pubDate>Tue, 29 Jul 2008 11:42:56 +0000</pubDate>
		<dc:creator>thomas</dc:creator>
		
		<category><![CDATA[Software Engineering]]></category>

		<category><![CDATA[parallel]]></category>

		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.thomasknierim.com/68/software-engineering/parallel-programming/</guid>
		<description><![CDATA[During the last few years, we have seen a trend change in CPU design. Until about 2003, CPUs  became more powerful through frequency scaling. The number of operations per second increased exponentially over a period of 20 years. Clock speeds went from 4.77 MHz in the first IBM PC (1981) to 3.3 GHz in a [...]]]></description>
			<content:encoded><![CDATA[<p>During the last few years, we have seen a trend change in CPU design. Until about 2003, CPUs  became more powerful through frequency scaling. The number of operations per second increased exponentially over a period of 20 years. Clock speeds went from 4.77 MHz in the first IBM PC (1981) to 3.3 GHz in a high-end PC of the year 2003. Thus, Moore&#8217;s law was supported chiefly by increasing clock speed. Then something &#8220;strange&#8221; happened: clock speeds plateaued. For a brief moment, it appeared that Moore&#8217;s law was nearing its end. Not because of the physical limits of miniaturisation, or because higher clock speeds were impossible, but because of thermal problems associated with such high clock frequencies. Water cooled systems were already introduced at the top-end of the market, but obviously the energy efficiency of these systems presents a serious economic problem. Then in 2004, the first PC dual core processor was introduced. Dual cores became widely available in 2005 and by now we have become used to quadcore processors, while eight-core systems are around the corner. The trend is obvious: in the forseeable future we will move from multi-core to many-core CPUs with dozens and perhaps even more cores.</p>
<p>Increasing the clock speed of a CPU has the effect, that program execution speed increases proportionally with clock speed. The increase is independent of software and hardware architectures. A sequential algorithm simply runs twice as fast on a machine where CPU operations take half the time. Unfortunately, this is not the case for a machine with twice as many CPUs. A sequential algorithm runs just as fast on a 3 GHz single core CPU than on a 3 GHz dual core CPU, because it uses only one of the CPU cores. Increased overall execution speed is therefore only achieved when multiple tasks run concurrently, because they can be executed simultaneously on different CPUs. This problem of parallelism is not new in computer science. Unfortunately though, today&#8217;s programming languages aren&#8217;t very well equipped to deal with parallel scaling. The computer language idiom that typifies multi-core concurrency is the thread model. Threads are lightweight processes that are typically used for self-contained subtasks. Several languages, notably Java, offer APIs and native support for their implementation. Threads are well suited to asynchronous processing, for example in communication and networking. They can also be used for simple parallelisation, where a computing problem is parallel by nature (for example serving multiple web documents at the same time). However, threads are relatively cumbersome and thus not really suitable for fine-grained parallel programming, such as traversing data structures or executing nested loops in parallel. Edward A. Lee describes the problems with threads <a href="http://www.computer.org/portal/site/computer/index.jsp?pageID=computer_level1_article&amp;TheCat=1005&amp;path=computer/homepage/0506&amp;file=cover.xml&amp;xsl=article.xsl" title="The Problem With Threads">in this excellent article</a>.</p>
<p>The fundamental problem that software engineers face is described by Amdahl&#8217;s law. Amdahl&#8217;s formula expresses the speed gain of an algorithm achieved by parallelisation: speedup = N / ( (B*N) + (1-B) ), where B is the non-parallelizable (sequential) percentage of the problem and N is the number of worker threads, or processor cores. There are two notable things about Amdahl&#8217;s law: (1) the speedup is highly dependent on B, and (2) the curve flattens logarithmically with increasing N. It&#8217;s also important to know that Amdahl&#8217;s law assumes a constant problem size, which is unrealistic given that parallelisation  requires a certain amount of control overhead. Nevertheless, we can draw several conclusions from Amdahl&#8217;s law. First, the performance gain from parallel scaling is lower than that of frequency scaling. Second, it is not proportional to the number of cores. Third, it is highly dependent on software architecture, since the latter chiefly determines the size of B. From the perspective of a software engineer, the last conclusion is probably the most interesting one. It leads to the question what can be done to maximise parallelisation at the level of the algorithm exploiting data and task parallelisms. The present thread model is too coarse-grained to provide solutions at the algorithm-level. Hence, what is called for are new programming idioms that make this task easier.</p>
<p>Ideally, parallelisation is fully automatic, implemented by the compiler and the underlying hardware architecture. In this case, the application programmer could simply continue to formulate sequential algorithms without having to worry about parallelism. Unfortunately, automatic parallelisation has turned out to be extremely complex and difficult to realise. Despite many years of research in compiler architecture, there are no satisfactory results. Parallelisation at the algorithm level involves several abstraction steps, such as decomposition, mapping, scheduling, synchronisation, and result merging. The hardest among these tasks is very likely decomposition, which means breaking down a sequential task into parts that can be solved in parallel. The preferred method for doing this is divide and conquer. A problem is divided into identical smaller pieces, whereas the division can be expressed recursively or iteratively. The problem chunks can then be solved in parallel and the subtask results are joined into one final result. Prime examples for this strategy are merge sort and sequential search algorithms. These are easily parallelisable. Likewise many operations on arrays and collections can be parallelised fairly easily. But certain tasks are not obviously parallelisable, for example the computation of the Fibonacci series: f (n) = f (n-1) + f (n-2). Since every step in the computation depends on the previous step, the Fibonacci algorithm is sequential <em>by nature</em>. In theoretical informatics, the question whether algorithms of the complexity classes P and NP are in principle parallelisable is still unsolved. For practical purposes, some problems are simply non-parallelisable.</p>
<p>Given that automatic parallelisation is currently out of reach, the need for the facilitation of algorithm parallelisation in computer languages boils down to (1) the need for expressive constructs that allow programmers to express parallelisms intuitively, and (2) the need for freeing programmers from writing boilerplate code for the drudge work of parallel execution, such as scheduling, controlling, and synchronisation. There are already a number of computer languages that provide built-in idioms for parallel programming, such as Erlang, Parallel Haskell, MPD, Fortress, Linda, Charm++ and others. However, these are fringe languages with a small number of users. It is questionable whether the   parallel scaling trend in hardware will lead to a wide adoption of any of these languages. Perhaps mainstream languages will evolve to acquire new APIs, libraries, and idioms to support parallel programming. For example, there are Compositional C++, MPI, Unified Parallel C, Co-Array Fortran and other existing extensions that make widely used languages more suitable for parallel programming, although there aren&#8217;t any established standards yet. It also remains to be seen whether the functional programming paradigm will catch on in view of parallel programming. Java is promising, because the JDK 7 (Dolphin) will contain a  new API for fine-grained parallel processing. In <a href="http://www.ibm.com/developerworks/java/library/j-jtp11137.html" title="Parallelism in Java SE 7">this very informative article</a> by Brian Goetz, the author of <em>Java Concurrency in Practice</em>, introduces the new java.util.concurrency API features of Java SE 7. It will include a fork-join framework that simplifies the expression of parallel processing, for example in loops or in recursive method invocation. It will also provide new data structures, such as ParallelArray, that make parallel iteration easier to express. To learn more about parallel computing, read the free <em><a href="https://computing.llnl.gov/tutorials/parallel_comp/">Introduction To Parallel Computing</a></em> by Blaise Barney or search the free <a href="http://books.google.co.th/books?q=parallel+programming&amp;source=citation">parallel programming books at Google Books</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.thomasknierim.com/68/software-engineering/parallel-programming/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
