<?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>Gridshore &#187; Ben</title>
	<atom:link href="http://www.gridshore.nl/author/ben/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Tue, 13 Dec 2011 15:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Documents the Pull Way</title>
		<link>http://www.gridshore.nl/2011/09/01/documents-the-pull-way/</link>
		<comments>http://www.gridshore.nl/2011/09/01/documents-the-pull-way/#comments</comments>
		<pubDate>Thu, 01 Sep 2011 19:48:15 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2011/09/01/documents-the-pull-way/</guid>
		<description><![CDATA[<p>Today I came across a column posted (in Dutch) on Webwereld entitled &#34;It&#8217;s a trap!&#34;. This column is responding to the recent decision at a LibreOffice/OpenOffice Workshop to put more effort into support for Microsoft&#8216;s proprietary OOXML format.</p> <p>Perhaps it is because I have been reading Pull. Perhaps it is because I have been [...]]]></description>
			<content:encoded><![CDATA[<p>Today I came across a column posted (in Dutch) on <a href="http://webwereld.nl/" title="Webwereld" target="_blank">Webwereld</a> entitled &quot;<a href="http://webwereld.nl/column/107786/its-a-trap---column-.html" title="It's a trap! (column)" target="_blank">It&#8217;s a trap!</a>&quot;. This column is responding to the <a href="http://www.osor.eu/news/support-for-proprietary-ooxml-format-spurs-open-source-suites-adoption" target="_blank">recent decision</a> at a LibreOffice/OpenOffice Workshop to put more effort into support for <a href="http://www.microsoft.com" title="Microsoft" target="_blank">Microsoft</a>&#8216;s proprietary <a href="http://en.wikipedia.org/wiki/Office_Open_XML" title="Office Open XML" target="_blank">OOXML</a> format.</p>
<p>Perhaps it is because I have been reading <a href="http://www.amazon.com/Pull-Power-Semantic-Transform-Business/dp/B00403NG2C/" title="Pull: The Power of the Semantic Web to Transform Your Business" target="_blank">Pull</a>. Perhaps it is because I have been working at a new company over the past year who are trying to address some related issues. But this column got me thinking about what the essence is of what we call documents nowadays and how this might change in the coming years.</p>
<p><span id="more-1188"></span><br />
<h1>It&#8217;s a trap! in short&#8230;</h1>
<p>For those of you who do not read Dutch, the point of the original column &quot;It&#8217;s a trap&quot; is that word processors as they are nowadays are simply a continuation of the evolution of the paper document, from clay tablet to an electronic view on preparing documents for printing on static paper. However, the author states, documents are moving more and more to being electronic entities living primarily on computers, independent of the static form of the paper document. In light of this he is surprised that the LibreOffice community wants to concentrate on adopting the &quot;enemy&quot; document format and try to challenge Microsoft on its own homeground, when that is just playing to Microsoft&#8217;s strength rather than trying to pull ahead of them in the area of the location- and medium independent document that just lives in the cloud.</p>
<h1>Semantic web</h1>
<p>Like I mentioned earlier, I&#8217;ve been working for a new company for the past year. This <a href="http://www.qiy.com" target="_blank">company</a> is trying to embrace part of the vision of the <a href="http://en.wikipedia.org/wiki/Semantic_Web" target="_blank">semantic web</a> as put forth in books like <a href="http://thepowerofpull.com/siegel/thoughts/who-is-the-worlds-first-blogger" target="_blank">David Siegel</a>&#8216;s Pull. As part of this new job I&#8217;ve been able to spend time thinking about the vision of Pull and how reversing the current model of interaction between companies and consumers will affect the way we think about personal data and data sharing.</p>
<p>The basic idea behind the semantic web is that it must be possible to interpret the meaning of (textual) resources and the relationships to other resources automatically and unambiguously. To that end these relationships are described formally in a (the?) semantic web, enabling software to reason about these relationships according to preset rules in order to deliver value to human users of the software.</p>
<p>Once you start thinking about it, the consequence of building and using a semantic web is that data is not the only thing that is important any more. In addition to data (which exists for human interpretation and consumption), formally formed data <em>about</em> data is very important: the <strong><em><u>metadata</u></em></strong>. This metadata, like a formal description of relationships, describes what data is about in a way that can be understood by machines. Metadata is what enables automated processing of data and as the amount and richness of metadata increases and is linked together in a semantic web, the more it will enable smart(er) software to process data in new and unusual ways. It will enable software to discover data in the cloud and even generate new data by combining existing data through actual understanding of that data.</p>
<h1>It&#8217;s a document, but not as we know it</h1>
<p>So when is a datum data and when is it metadata? That&#8217;s a good question. The answer is that it depends. Data is intended for humans and metadata for computers&#8230; but why shouldn&#8217;t humans know who the sender of an email is, just because that information is metadata? Or the other way around, why shouldn&#8217;t a computer try to make some sense of data, or try to perform some processing of data, just because the primary audience is human? Search engines do exactly that&#8230;</p>
<p>The upshot of it is that data can be data and can be metadata interchangeably, depending on the context. In other words, the role of data is not fixed but depends on how you happen to be treating it. Nothing new there, of course. Which is when I came across that column.</p>
<p>The column raises the question of whether LibreOffice should try to follow the OOXML format when the very nature of document storage and presentation is changing. That&#8217;s a good point, but in the light of the semantic web it&#8217;s not going far enough. Since data can be both data and metadata and metadata enables processing (such as presentation), I say the real question is: what is a document?</p>
<p>The point of a file format like the .DOC or the .DOCX formats is that they contain document data (i.e. contents), what users consider metadata (i.e. properties like the author), and application-specific metadata pertaining to the way applications are supposed to present data. All very nice and useful. But one of those three categories is only useful to applications that want to present the content exactly the way Word does. An application that wants to apply different formatting, or wants to read the contents out loud, or wants to do something completely different than presenting the contents on-screen or on paper is not interested in the Word instructions at all.</p>
<p>So here&#8217;s a question: what is really a document? Is it a file on a storage medium? Or is it just the contents and the application-independent metadata? Is it in any way interesting to include presentation hints in a document? After all, if you follow the visions of data pull and the semantic web, real value comes from making data application-agnostic and allowing each application to overlay any presentation that fits its purposes.</p>
<p>And that is the direction I think documents will start following more and more. Even in the original Web 1.0 the intention already existed that data only be described and display be left to the user agent. After having veered off the path in HTML 3 and 4, the web is now morphing into the transport medium for a worldwide system of applications forming (partially) dynamic SOA networks, whose entire possibility of existence is based on being able to process raw data without having to wade through superfluous bytes that are specific to one particular application. Application networks like that are based on location-agnostic data with plenty of application-independent metadata to allow for all sorts of processing without binding to a specific application.</p>
<p>So I think that in the future our notion of a document will change completely. I think that we will move to a separation of content and semantic data from anything else, meaning that we will be divorcing documents from the applications that process them. We will even divorce documents from presentation forms and formats, so that the distinction between a Word document, a PDF, a spreadsheet, a (NoSQL) database of facts and relations, an MP3 recording of the contents and a steganographic encoding of some piece of abstract art will vanish and the informational content of the document will depend only on the application doing the processing (note that &quot;informational content&quot; is not the same as &quot;semantics&quot;).</p>
<h1>Oh, by the way&#8230;</h1>
<p>The column that inspired this blog was wondering whether or not the LibreOffice community should invest effort in becoming (more) compatible with the OOXML format and so emulate MS Office. Contrary to what you might be thinking, I feel that the answer given by that column is wrong. Not that I think that the goal should be to become fully OOXML-compatible, because I do feel the very notion of &quot;document&quot; and &quot;document format&quot; should change. But in the world that I think we are moving towards, the value of an application will not be in its compatibility with one data format but in how much value it creates for a user in the way it interprets and (re)processes the basic data and metadata.</p>
<p>So how does this relate to LibreOffice and their OOXML compatibility? Well, LibreOffice could stand to start offering more value as an office suite. Simply put, LibreOffice sucks as an office suite. It wasn&#8217;t so bad when Microsoft Office was still in the pre-2007 releases and documents from MS Office sucked in the same way as those from OpenOffice. But with Office 2007, Microsoft took a huge leap ahead of all the alternatives out there. And the difference isn&#8217;t in any technical improvement they made either; Microsoft didn&#8217;t add any great new technical functionalities, any huge new editing or DTP facilities or anything to do with the document <em>content</em>. But they did invest a lot in a number of document looks and feels (designed by graphics designers) that make it possible to create good-looking documents very simply (i.e. to present the content in an attractive way with little effort). A vast improvement over documents from other Office suites (including earlier versions of MS Office), which produced documents whose appearance sucked unless you put in A LOT of effort. In other words, Microsoft put a lot of effort into how they processed and presented the basic content of each file and so added a lot of value for the end user rather than adding useless functionality that nobody needs like they did in earlier releases. Their concentration on adding this value means MS Office is now a far better document processor than LibreOffice. And in that sense, yes, the LibreOffice community should definitely try to emulate Microsoft Office far more than it is doing now. Not for the document format, but for the value the office suite adds as a document interpreter.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2011%2F09%2F01%2Fdocuments-the-pull-way%2F&amp;title=Documents%20the%20Pull%20Way&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2011/09/01/documents-the-pull-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Public Transportation pass woes&#8230;.</title>
		<link>http://www.gridshore.nl/2010/08/19/public-transportation-pass-woes/</link>
		<comments>http://www.gridshore.nl/2010/08/19/public-transportation-pass-woes/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 19:21:13 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2010/08/19/public-transportation-pass-woes/</guid>
		<description><![CDATA[<p>The Netherlands is currently in the middle of a large project to change the way we pay for public transportation. We are moving from paying with a cardboard strip (called the &#34;Nationale Strippenkaart&#34;, which must be stamped by the driver of the public transportation vehicle you get on) to a new system (the OV-chipkaart) [...]]]></description>
			<content:encoded><![CDATA[<p>The Netherlands is currently in the middle of a large project to change the way we pay for public transportation. We are moving from paying with a cardboard strip (called the &quot;<a href="http://nl.wikipedia.org/wiki/Nationale_Strippenkaart">Nationale Strippenkaart</a>&quot;, which must be stamped by the driver of the public transportation vehicle you get on) to a new system (the <a href="http://en.wikipedia.org/wiki/OV-chipkaart">OV-chipkaart</a>) involving an RFID chip on which you can preload money or one or more subscriptions. The idea is not new (the Greater London <a href="http://en.wikipedia.org/wiki/Oyster_card">Oyster Card</a> is a well-know example) but this is the first time I know of that it has been done on a nationwide scale.</p>
<p>Needless to say there have been problems along the way. <a href="http://michelvaneeten.nl/">Michel van Eeten</a>, professor of Governance of Infrastructures at the <a href="http://www.tudelft.nl">Delft University of Technology</a>, recently gave an interview to the Dutch engineering magazine <a href="http://www.deingenieur.nl">De Ingenieur</a> in which he explained how the project is suffering from an implicit choice of offloading all of the project risks (security, privacy, and so on) onto the customer. A few days ago I had a similar experience with problem offloading onto the public by this project&#8230;</p>
<p><span id="more-1074"></span><br />
<h3>Some background</h3>
<p>Before I get into the problem itself, let me give you some background on the setup that <a href="http://www.translink.nl/content.asp?languageID=UK&amp;pageID=1">Trans Link Systems</a> (the executive organization behind the new system) has come up with. The idea behind the new OV-chipkaart is to replace the old Nationale Strippenkaart as a single method of payment for all public transportation services. This means that you must be able to wave your card in front of a machine at any train station, bus stop, tram stop, metro station and so on and be able to check in for travel or check out for payment (you then get charged based on distance traveled). Privacy laws in The Netherlands being what they are, each company must keep track of its own interactions with the passenger/customer, so a shared administrative database is out (meaning also that if you want to transfer from one company to another you must check out and check in again at a different sign-in point at the same station).</p>
<p>At the same time the government doesn&#8217;t want a monopoly on any part of the equipment, so the check-in/check-out hardware cannot be standardized to one offering by one company. Instead there is a general communications standard between the RFID chip (which is a MiFare chip supplied by <a href="http://www.nxp.com">NXP Semiconductors</a> &#8212; the government agreed to a monopoly on that part) and the devices and between the devices and the public transportation operators. Trans Link Systems ties the machines together through a shared network infrastructure and also maintains a database of all transportation data (separate from the data kept by the individual companies) in order to deal with system difficulties, fraud and so on. In other words, Trans Link Systems is running a huge <a href="http://en.wikipedia.org/wiki/Enterprise_service_bus">ESB</a> with a monitoring system.</p>
<p>To reiterate, the idea behind all of this is to replace the existing Nationale Strippenkaart with the same level of service or better.</p>
<h3>Where things started going wrong</h3>
<p>As is often the case with huge projects that are forced on a large entity from above (a company by management or a country by the government), the problem with the OV-chipkaart project is not in the technology itself but in the interaction with the potential user base. There has been a lot to do in The Netherlands over the past few months about privacy and security involving this system. I won&#8217;t get into all of that, save to say (as mentioned before) that professor van Eeten has given a nice interview to the Ingenieur in which he points out that most of the problems are the result of some stupid choices by Trans Link Systems which boil down to dropping problems in the lap of the passengers rather than dealing with them themselves. These choices serve to lower trust in the system and the people behind it and increase the height of the hurdle to be taken in convincing people to switch.</p>
<p>Case in point is what happened to my mother a few days ago. My mother has had an OV-chipkaart for several months, which she ordered through the bus company (my mother travels by bus mostly, so that&#8217;s where she chose to order her card; all the cards use the same MiFare chip, but the cards themselves are supplied by many different companies and can either be anonymous or personalized). She doesn&#8217;t use it often because she is entitled to ride for free on the inner city buses, but she needs one for regional buses and the once-in-a-blue-moon train ride.</p>
<p>Last Monday was one of those blue-moon occasions. We took the bus to the station together and then she tried to check in for the train — and was promptly refused. Several attempts, no success. Finally I bought her an old-fashioned return ticket (say what you want about that paper stuff, it definitely <em>works</em>). On the way back we stopped in at the bus company to complain, who told us they couldn&#8217;t see what was up with railway payments on their machines and told us to go to the railway company (who, luckily, had an office in the same station). So we trudged over there and the railway <s>bitch</s> not-very-nice-person at the desk snippily informed us that my mother&#8217;s card was not equipped for the train. In order to use the train she first had to go online to order a special train subscription for not-railway-issued OV-chip cards (which was needed for the sole purpose of determining which class she wanted to travel in), which would then have to be loaded onto her card using one of the machines back at the station. And processing an order for such a subscription takes an hour, so even if you have a smartphone with Internet access and can order the thing right there it does you no good unless you want to hang around the station for an hour, thank you very much.</p>
<h3>QoS or JPS?</h3>
<p>Now, I&#8217;m not quite sure what I&#8217;m complaining about in this blog but it&#8217;s either a lack of QoS (Quality of Service) or an excess of JPS (Just Plain Stupid). Either way, it&#8217;s a case of what Van Eeten was talking about in his interview: offloading responsibility from the service provider onto the customer making the system difficult to use and lowering acceptance.</p>
<p>Sure, it doesn&#8217;t sound so bad to have to get a special subscription for the train (it&#8217;s free, you just pay for using the train) and having to wait an hour. And the reasoning even sounds reasonable (after all, the railways must know what class you will be traveling in in order to know what to charge you). But here&#8217;s the point: the public transportation providers and the government decided to change the payment system without consulting the traveling public and must therefore convince the public to switch <em>and they&#8217;re offering a lower level of service than the old system while doing this</em>.</p>
<p>Really, they are. I said it earlier and I&#8217;ll repeat it here: say what you want about that paper stuff, but it definitely works. And that&#8217;s what people are used to. You buy a single ticket and then you&#8217;re good to go. And that&#8217;s the level of service that the new system must meet at the very least. Without that the hurdle is too high for the public and acceptance will be low and grudging. After all, you must realize (which Trans Link doesn&#8217;t seem to) that the public to convince is <u>the general public</u>. And that general public is being asked to make changes in what it is used to. For starters, the public is being asked to move from the following process:</p>
<ol>
<li>Go to stop/station.</li>
<li>Get on board.</li>
<li>Present ticket for stamping.</li>
<li>Travel.</li>
</ol>
<p>to this one:</p>
<ol>
<li>Go to stop/station.</li>
<li>Get on board.</li>
<li>Present ticket for check in.</li>
<li>Travel.</li>
<li>Present ticket for check out.</li>
</ol>
<p>That&#8217;s only a single extra step, but for most of the general public that&#8217;s already pushing the limit of what you can ask of a person. If the card itself is difficult to handle on top of that, that&#8217;s a risk to the success of the system.</p>
<h3>So what to do?</h3>
<p>Compare the situation sketched above to that of the mobile phone (which I&#8217;m intimately aware of just now, having just switched <img src='http://www.gridshore.nl/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ). For that you need some sort of subscription from a telecom provider and a phone (call it a card with a MiFare chip). Many providers provide some network services in addition to voice communication (like voicemail, SMS, MMS). For those you usually get pushed configurations the first time you sign in on the network. In addition most phones offer additional services (like email) which you must configure. But whether they do or not: your basic network services work the moment you put your SIM-card in the phone. Easy-peasy, Japaneasy. </p>
<p>The phone situation is so normal that you might have missed the point: <em>the basic network services work immediately.</em> No extra work or configuration required. Extra stuff like email needs configuration, but the basics are plug-and-play.</p>
<p>So why doesn&#8217;t the OV-chipkaart work like that? Why didn&#8217;t they make it so that you can use all public transportation in the lowest class the moment you have the card? Sure, if you want to travel in a higher class you would have to do something extra, but at least travel would be possible immediately. Why was it necessary to push the problem of getting basic service working off onto the passengers? That&#8217;s Just Plain Stupid, all the way. Not to mention <a href="http://www.gridshore.nl/2008/03/29/how-wtfs-improve-code-quality-awareness/">WTF</a>&#8230;</p>
<h3>Are you kidding me?</h3>
<p>Just as an aside, here&#8217;s an interesting question for you: how do you think tourists are supposed to get around using the new system? Tourists have to rely on the anonymous, prepaid, disposable cards that you buy at station bookstores and magazine stands. Available all over the place and no privacy concerns, for the ease of use of the hapless visitor to our country. And just to add insult to injury, <em>those</em> cards allow you to check in to any mode of transportation in the lowest class available automatically.</p>
<p><em>Update (05-09-2010): Since writing this blog, I have purchased an anonymous pass from the Railway Service and it has turned out that I have completely maligned them in the area of not being consistent in the treatment of personal and anonymous passes. As it turns out, you must also get a special train subscription as explained above for an anonymous pass, even if you purchase it directly from the Railway Service. So it&#8217;s equally inconvenient for everybody and tourists are just as screwed as everybody else. My apologies to the Railway Service for misrepresenting the situation.</em></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F08%2F19%2Fpublic-transportation-pass-woes%2F&amp;title=Public%20Transportation%20pass%20woes....&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/08/19/public-transportation-pass-woes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Yes! REST really is not the same as HTTP!!</title>
		<link>http://www.gridshore.nl/2010/08/16/yes-rest-really-is-not-the-same-as-http/</link>
		<comments>http://www.gridshore.nl/2010/08/16/yes-rest-really-is-not-the-same-as-http/#comments</comments>
		<pubDate>Mon, 16 Aug 2010 18:04:38 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Architecture]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=1072</guid>
		<description><![CDATA[<p>By now I&#8217;m sure everybody has at least heard of REpresentational State Transfer (REST). REST is an architectural style that was first properly described by Roy Fielding in his doctoral thesis. Since Fielding published his thesis in 2000 the term REST has become very popular among web developers. Mostly for the wrong reasons of [...]]]></description>
			<content:encoded><![CDATA[<p>By now I&#8217;m sure everybody has at least <em>heard</em> of <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REpresentational State Transfer (REST)</a>. REST is an architectural style that was first properly described by <a href="http://roy.gbiv.com/">Roy Fielding</a> in his <a href="http://www.ics.uci.edu/~fielding/pubs/dissertation/top.htm">doctoral thesis</a>. Since Fielding published his thesis in 2000 the term REST has become very popular among web developers. Mostly for the wrong reasons of course — REST and the derived term RESTful have morphed into marketing jargon for people who really mean &quot;building a web site&quot; when they say &quot;implementing a RESTful architecture&quot;.</p>
<p>One of the things that has gone wrong in the area of REST-the-popular-interpretation is that people think that &quot;doing REST&quot; is the same thing as &quot;using HTTP&quot; (another thing is that they think that REST is something you can <em>do</em>). The reason of course is simple: most people use the term REST to mean building a web site. And you use HTTP for that. And in fact I thought it was not a wholly unreasonable position because one of the constraints of the REST architectural style is such that you really would not want to use anything but HTTP as a rule. </p>
<p>However, today, all of a sudden, I stumbled on ultimate proof that REST really is as independent from HTTP as Fielding claims: a piece of software that uses the REST architectural style but not HTTP.</p>
<p><span id="more-1072"></span><br />
<h3>REST: the short, <em>short</em> version&#8230;</h3>
<p>Before we get to this marvelous, mythical piece of software let&#8217;s have a short recap of what REST entails. Real REST that is, not the bullshit about URI mappings, JSON and all the other nonsense that REST-the-marketing-buzzword has come to mean.</p>
<p>REST is not a codeword for building a web site. REST is also not something that you <em>do</em>. REST is an <em>architectural style</em>, which means that it is a general idea about what your application architecture should look like with some architectural choices already made for you. In particular the REST style is a general description of application architectures that make the following choices:</p>
<ul>
<li><strong><u>client-server:</u></strong> The entire application uses a client-server architecture. This principally covers the interaction between the end user and the core application, but if the application consists of multiple components they use client-server communication as well.</li>
<li><strong><u>stateless:</u></strong> All inter-component communication (including the end-user client to the application service layer) uses stateless communication. This does not mean that a component cannot have state at all (like a database), but it does mean there is no concept like a running session or a session context. It also means that all external information needed to complete a request must be in the request.</li>
<li><strong><u>cache-able:</u></strong> At the discretion of a component in the system, a response to a request may be marked as cache-able. This means that the requesting component <em>may</em> cache the answer for later reuse.</li>
<li><strong><u>uniform interface:</u></strong> All components in the system use the same interface, no matter what their specific functionality. This interface therefore also becomes the communication protocol of the entire system, which simplifies building communication clients. System functionality is achieved by adding a distinct, addressable resource that offers the functionality and that is controlled using the shared communication protocol.</li>
<li><strong><u>layered:</u></strong> This constraint means that you cannot see through a component that you send a request to. As long as the client doesn&#8217;t control the processing of the server, the system remains scalable.</li>
<li><strong><u>code-on-demand:</u></strong> As an optional extra a server might send code to the client for local execution.</li>
</ul>
<p>The architectural constraints above, in the sense of a preselected set of choices, are what makes REST. Anybody see any mention of JSON? No, neither do I&#8230;</p>
<h3>So where does HTTP come in?</h3>
<p>If you look at the architectural constraints again, you&#8217;ll see something else that isn&#8217;t mentioned (other than JSON): HTTP. REST does not imply HTTP. So why does everybody think it does? Just because Roy Fielding helped define HTTP? Because marketing guys want to sell web site work? No, it&#8217;s because of the uniform interface constraint. That constraint specifies that each component in the system is communicated with <em>and controlled</em> using a single protocol. Which means a single command set. In other words, no matter what the functionality of the component, it always answers to the same command set with the same possible parameters.</p>
<p>The uniform interface constraint is a very horrible idea. It is a complete contradiction of the principles of <a href="http://domaindrivendesign.org/">domain-driven design</a>: having a uniform interface for all your components which is also your communication protocol means that you must encode domain concepts and operations in terms of the uniform interface instead of making them explicit in a domain language. It means your attention is diverted away from the application domain and domain model and even at the level of the most basic lesson we all learned in programming (&quot;use explicit names for your identifiers&quot;) the uniform interface is a bad idea. Nobody in his right mind would ever use a uniform interface in a multi-component application they were designing.</p>
<p>In point of fact, there is only one situation in which you would want to employ a uniform interface in your application: in order to allow your application to become part of a larger, generally accessible system where participation brings you more users. Think plug-in architectures like the Eclipse platform&#8230; Or the World Wide Web, which runs on HTTP. So that&#8217;s why REST has become inextricably linked with HTTP: HTTP is the protocol for a network that is an ideal use case for the REST architectural style&#8230; and it&#8217;s practically the only example of a popular network that you would want to join in order to reach a large audience.</p>
<h3>And yet&#8230;</h3>
<p>So it looks (for good reason) like REST and HTTP are congruent. Everybody who &quot;does REST&quot; uses HTTP and the HTTP-based WWW is practically the only interesting vehicle for real REST-style applications. And yet, and yet, today, in the wild, out of the blue, I came across a perfect example of that mythical beast: a REST-style application that doesn&#8217;t use HTTP as a uniform interface. So what was this application? The <a href="http://www.ezmlm.org/">EZMLM</a> mailing list manager.</p>
<p>EZMLM is, as said, a mailing list manager. That is, it manages a list of email addresses which are subscribed to a list (i.e. get a mail forwarded that is sent to a certain email address). In order to perform this management the EZMLM offers a number of command resources, each of which is triggered by the delivery of a message to that resource. Each command resource is individually addressable (using an email address as a universal resource identifier). My claim is that this program uses the REST architectural style. In order to prove this I must show that the architecture of EZMLM meets the constraints as explained above:</p>
<ul>
<li><strong><u>client-server:</u></strong> EZMLM uses two components: a mail client (officially an SMTP user agent) and the EZMLM mail server. Like any SMTP-based email setup, this is a client-server application by definition.</li>
<li><strong><u>stateless:</u></strong> EZMLM has no concept of a session at all. Each request is somehow a mailing list management command which is atomic and no session is needed at all. The situation is somewhat deceptive because you might think that the mailing list itself is session state. However, this is not the case: EZMLM manages this list, that is true, but the list does not tie individual requests together into a session. Also, the list is not needed to make any request function correctly; all the information needed is in the mail message (usually that information consists of the contents of the FROM: header). This is true even for a command to the unsubscribe resource: the command still functions if the FROM: address is not on the list, it just cannot mutate the list (an error case is still correct processing).<br />Of course the mailing list does serve as server state, especially in case of a forward command (i.e. sending a mail to the list which is distributed to all list subscribers). However, the statelessness requirement doesn&#8217;t forbid server state. The important thing to realize is that the purpose of EZMLM is to manage the mailing list and that the mailing list does not function as session state information.</li>
<li><strong><u>cache-able:</u></strong> This requirement entails that the system might decide that some server responses may be cached. The client may then use its cache instead of talking to the server. This could be done using EZMLM, especially with the EZMLM response to the &quot;help&quot; command (the response is a list of command email addresses recognized by the EZMLM server). In practice EZMLM won&#8217;t do this, but the requirement is not that the system MUST have responses which it considers cacheable. Also, most user agents wouldn&#8217;t be able to handle caching of mails. But again, this is not a requirement.</li>
<li><strong><u>uniform interface:</u></strong> All one server components in the system use the SMTP protocol as uniform interface.</li>
<li><strong><u>layered:</u></strong> There is only one component in the system, so this requirement is trivially met. Still, if there were more components it is hard to see how their details would not be hidden behind the SMTP interface.</li>
<li><strong><u>code-on-demand:</u></strong> EZMLM does not use this optional constraint.</li>
</ul>
<p>Again, the essential point here is to understand that there is a difference between <em>managing</em> a mailing list as function of the application and using that list as session state. Another point is the definition of a component. EZMLM uses other software (particularly qmail and its shell hooks) to deliver its functionality. However, EZMLM is buildable and deployable as a single package with all functionality and must be administered and maintained as a single package. Perhaps somewhat tentatively I will consider this enough to consider EZMLM a single component.</p>
<h3>Conclusion</h3>
<p>Simply put: miracle of miracles, there really is software that uses a REST style architecture but doesn&#8217;t use HTTP. So yes, against all expectation it is true and REST really is independent of HTTP!</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F08%2F16%2Fyes-rest-really-is-not-the-same-as-http%2F&amp;title=Yes%21%20REST%20really%20is%20not%20the%20same%20as%20HTTP%21%21&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/08/16/yes-rest-really-is-not-the-same-as-http/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>An evening on the Go</title>
		<link>http://www.gridshore.nl/2010/07/28/an-evening-on-the-go/</link>
		<comments>http://www.gridshore.nl/2010/07/28/an-evening-on-the-go/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 23:47:44 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2010/07/28/an-evening-on-the-go/</guid>
		<description><![CDATA[<p>Last Thursday (July 22nd, 2010) Rob Pike, a Principal Engineer at Google, gave a talk at the O&#8217;Reilly Open Source conference. In this talk he stated that established languages such as C++ and Java are too complex and not adequately suited for today&#8217;s computing environments. He then proceeded with some criticism of dynamically typed [...]]]></description>
			<content:encoded><![CDATA[<p>Last Thursday (July 22nd, 2010) <a title="Rob Pike" href="http://research.google.com/people/r/index.html">Rob Pike</a>, a Principal Engineer at Google, gave a talk at the O&#8217;Reilly Open Source conference. In this talk he stated that established languages such as <a title="C++" href="http://en.wikipedia.org/w/index.php?title=C%2B%2B&amp;oldid=374538072">C++</a> and <a title="Java" href="http://en.wikipedia.org/w/index.php?title=Java_(programming_language)&amp;oldid=374887455">Java</a> are too complex and not adequately suited for today&#8217;s computing environments. He then proceeded with some criticism of dynamically typed languages (that I share) and finally ended up plugging the <a href="http://golang.org">Go language</a> (which he co-developed) as a solution to the problem.</p>
<p>Now, Rob Pike is not nobody (in addition to being a Google principle engineer he has C and Unix credentials), plus the Go language has the Google brand name on it, so I thought it would be a good idea to check it out&#8230;. </p>
<p><span id="more-1067"></span>
<p>&nbsp;</p>
<h3>Evaluating Go</h3>
<p>The <a href="http://golang.org">Go programming language</a> is described on the website as a language geared towards system programming. That is to say, it is a new(ish), general purpose programming language developed internally at Google to scratch an itch some of their developers had and they then decided to open source it.</p>
<p>Evidently, judging from Rob Pike&#8217;s talk at O&#8217;Reilly, it is also intended to be a simpler alternative to C++ and Java and a more robust alternative to dynamically typed languages such as Ruby, Python and such. It is this claim that I felt was particularly intriguing, so I took a look at the language this evening by reading through the <a href="http://golang.org/doc/go_spec.html">language spec</a> and briefly glancing at the <a href="http://golang.org/doc/go_tutorial.html">tutorials</a>.</p>
<p>&nbsp;</p>
<h3>Creak, creak&#8230;</h3>
<p>Well, let&#8217;s address the great big elephant in the room immediately: it would seem that &#8220;simpler alternative&#8221; is Google-speak (or Pike-speak) for &#8220;forty five years old&#8221;. It&#8217;s had a spit-polish plus language features and libraries added, but there&#8217;s no way around it — Go is a rehash of the C programming language with some Pascal thrown in for good measure. Not surprising of course, given Rob&#8217;s background, but perhaps not the great linguistic revolution you would have expected.</p>
<p>Just to reassure you all, I&#8217;m not exaggerating: Go is essentially C, including structs, pointers and reams of different (un)signed int types. It even includes everyone&#8217;s favorite cross-platform language feature: numeric types whose size is architecture-dependent.</p>
<p>&nbsp;</p>
<h4>Spit-shine</h4>
<p>That&#8217;s not to say that some improvements have not been made to cover up some of the glaring problems that made C and C++ hard to handle: extern is gone as a concept, as is pointer arithmetic. Plus Go has a type definition feature, so you don&#8217;t need macro&#8217;s anymore. Also, Go has some more built-in types (such as complex numbers), support for Unicode and it can insert semicolons where needed and has both escaped and unescaped strings (both borrowed from Bourne Shell). And it places the type behind the identifier instead of in front and uses := as an assignment to distinguish from equality (borrowing from Pascal).</p>
<p>&nbsp;</p>
<h4>Back from the dead</h4>
<p>&nbsp;</p>
<p>Nevertheless, not all is well with the world. Like it&#8217;s ancestors Go still relies on an ability to export named entities (including variables), meaning you can get into the global variable mess. And guess what&#8217;s back from the dead: the goto statement, in its <a href="http://userweb.cs.utexas.edu/users/EWD/transcriptions/EWD02xx/EWD215.html">full and glorious horror</a>.</p>
<p>&nbsp;</p>
<h3>So what else is new?</h3>
<p>At the core of it, Go is a component-based language. It&#8217;s main architectural feature for this is the <em>package</em>, which isn&#8217;t much like Java but rather borrows from the Unit found in Turbo Pascal: a collection of exported types and identifiers, with hidden implementations. Packages serve as libraries in the language and are the main strength and source of language functionality.</p>
<p>In the spirit of &#8220;this is your grandfather&#8217;s technology&#8221;, Go is not an object-oriented language. Instead it is fully procedural and uses the <a href="http://en.wikipedia.org/wiki/Abstract_data_type">abstract data type</a> as its main means of abstraction. Admittedly, this is a good combination with the Unit-like library. The ADT concept has been bolstered with real language support to keep ADT functions and data structures together though. Even though the main data structures are C-style structs, the language includes the concept of a method (which is a function that is sort of legoed into a data type, creating the effect of putting a function pointer into a struct in C). Methods directly associate a callable code block with a data structure, so it&#8217;s sort of like adding real behavior to your basic data type. That&#8217;s a pretty good concession to OO thinking sure enough, but encapsulation beyond the package level and inheritance are still out.</p>
<p>The other major feature of the language is built-in concurrency modeled on <a href="http://en.wikipedia.org/wiki/C._A._R._Hoare">Tony Hoare&#8217;s</a> <a href="http://en.wikipedia.org/wiki/Communicating_sequential_processes">Communicating Sequential Processes</a>. This is a brand of concurrency that is not based around the classic &#8220;multi-process, shared single memory&#8221; model but around a &#8220;multi-process, multi-memory&#8221; model whereby processes are linked together by channels. Each process can &#8220;toss&#8221; values to another process over a channel (or &#8220;catch&#8221; values coming in across a channel). These operations block until succeeded, which allows for synchronization. The mechanism has been proven equally powerful as <a href="http://en.wikipedia.org/wiki/Edsger_W._Dijkstra">Dijkstra&#8217;s</a> standard <a href="http://en.wikipedia.org/wiki/Semaphore_(programming)">semaphore</a> mechanism. This is once again a typical choice for someone with Rob Pike&#8217;s background as this mechanism is also included in the Bourne Shell in the form of <a href="http://en.wikipedia.org/wiki/Named_pipe">named pipes</a>. Of course in such a language it must also be easy to start threads or fork subprocesses and indeed this can be accomplished with the use of a single statement.</p>
<p>&nbsp;</p>
<h3>So what are we to make of this&#8230;</h3>
<p>The Go programming language is an interesting combination of proven language features and program architectures. Rooted firmly in the Pascal/C/Bourne Shell era, it seems a bit of a museum of 1960&#8242;s language design ideas geared towards the hardware systems environment of that era&#8217;s dreams (and possibly today&#8217;s reality): heavily multiprocessed with the distinction between local and distributed processing disappeared into the background, using ADT and component-based modularity to achieve separation of concerns.</p>
<p>&nbsp;</p>
<h3>&#8230; except perhaps a bonfire?</h3>
<p>&nbsp;</p>
<p>And yet, I can&#8217;t say that I&#8217;m overly impressed with Go. Mostly I don&#8217;t see the point. Sure, its well-suited to the multiprocessing environment that we have nowadays. But its support for domain modeling and domain driven design is poor, based as it is on the ADT concept — a serious failing in a modern language if you ask me. And a language that isn&#8217;t architecture independent in a Cloud-based platform era? Come on&#8230; But most of all I don&#8217;t see the new language idea that is supposed to make this language better than all others. I don&#8217;t see a refreshing combination of functional and OO paradigms like Scala, or an &#8220;easily-typed shell over a large Java class library&#8221; like Groovy. I don&#8217;t really see what Google thinks it has accomplished with Go.</p>
<p>In addition to that, I don&#8217;t see proof for the claim of simplicity. Sure, it covers up the worst pointer-related problems in C/C++. Sure, multithreading is less verbose than it is in Java. But on the whole the language is no simpler than Java, as far as I&#8217;m concerned. I don&#8217;t like the lacking encapsulation, the poor man&#8217;s OSGi modularity, the way methods are tacked on to external data types rather than syntactically part of data structures. And I don&#8217;t think first-class lambda functions (popularly called closures) are all that special and I don&#8217;t think that having channels as a built-in language element is a great advantage over having them in a separate library (like C++ or Java do).</p>
<p>So what do I think of Go&#8217;s future? Well, it certainly has one major weapon in its arsenal: the Google logo, which still makes everything cool that it touches. So Go might get somewhere based on that. But on its own merits I can&#8217;t think of any reason to prefer it over another language.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F07%2F28%2Fan-evening-on-the-go%2F&amp;title=An%20evening%20on%20the%20Go&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/07/28/an-evening-on-the-go/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Some notes on discovering your type parameter using the Reflection API</title>
		<link>http://www.gridshore.nl/2009/10/27/some-notes-on-discovering-your-type-parameter-using-the-reflection-api/</link>
		<comments>http://www.gridshore.nl/2009/10/27/some-notes-on-discovering-your-type-parameter-using-the-reflection-api/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 11:54:04 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2009/10/27/some-notes-on-discovering-your-type-parameter-using-the-reflection-api/</guid>
		<description><![CDATA[<p>Starting with release 5.0, the Java language comes equipped with parametric polymorphism. Also known as generics, this language feature allows for a type (a class, interface, enum or other) to be parameterized with a type variable: a variable that represents some other type. This allows for the creation of Java code that is generic [...]]]></description>
			<content:encoded><![CDATA[<p>Starting with release 5.0, the Java language comes equipped with parametric polymorphism. Also known as generics, this language feature allows for a type (a class, interface, enum or other) to be <em>parameterized</em> with a <em>type variable</em>: a variable that represents some other type. This allows for the creation of Java code that is generic with respect to the type system (like when using java.lang.Object as the type of a method parameter) yet type safe at runtime (once you&#8217;ve chosen a specific type to use, the compiler can enforce that choice).</p>
<p>Even though parameterized polymorphism allows you to write code that is generic with respect to the type system, sometimes you want to write code that knows which actual type(s) it has been parameterized with. This article will examine how to discover that information, as well as the discoverability limits of the Java generic type system.</p>
<p><span id="more-916"></span><br />
<h3>Java 5.0: Generics</h3>
<p>When Java 1.0 was introduced in 1995, it didn&#8217;t include any concept of parametric polymorphism; it was a difficult concept and considered too complicated for inclusion in the original language. So for years we as Java developers were forced to write code that relied on the supertype of the entire language (<code>java.lang.Object</code>) whenever we didn&#8217;t want to be specific about which type(s) our code would work with at runtime. Of course there was a major downside to this: when you formally declare that your code needs a <code>java.lang.Object</code>, you immediately lose the ability of the compiler to check for correct usage if you are actually going to use a more specific type. I.e. if you want to use a <code>java.util.List</code> to include Strings, the compiler cannot check that everybody only puts Strings into that list and not objects of a different type.</p>
<p>So with the advent of Java 5.0, finally parametric polymorphism was added to the language: Java was outfitted with so-called <em>type parameters</em>, the type equivalent of method parameters. Like a method declares formal parameters which a program can reason over in a generic way and which are only given an actual value at runtime, a class, method or interface can now take a type parameter that makes the types the code works with just as indefinite as the values of method parameters. That is, the exact type a piece of generic code will act over may not be known at programming time, but it becomes known and verifiable at compile time and therefore a safe situation at runtime. For example, consider this code:</p>
<pre>
<pre class="brush: java; title: ; notranslate">public class Example&lt;T&gt;
{
     public void report(T parameter)
     {
         /* Really interesting, generic code here */
     }
}

...

Example&lt;String&gt; stringExample = new Example&lt;String&gt;();
stringExample.report(&quot;Hello World!&quot;);
</pre>
</pre>
<p>Within the declaration of class Example, you as a programmer don&#8217;t know the exact type that Example will use (although you can set limits). But once a specific Example instance has been created, the compiler can check that that instance is always used with the correct type.</p>
<p>But now suppose that you want to know within the generic code what runtime type you&#8217;re dealing with? For example, if we modify the example above a bit like so:</p>
<pre>
<pre class="brush: java; title: ; notranslate">public class Example&lt;T&gt;
{
     public void reportType()
     {
         System.out.println(&quot;This example is using type &quot; + [what goes here?] + &quot; for parameter T&quot;);
     }
}
</pre>
</pre>
<p>Is it possible to implement the example above?</p>
<h3>Java 5.0 and the new, generic type system</h3>
<p>In order to answer that question, we have to delve a bit into Java 5.0&#8242;s new, generic type system &#8212; and into the representation of the type system in the <a href="http://java.sun.com/j2se/1.5.0/docs/guide/reflection/index.html">Reflection API</a>.</p>
<p>In previous versions of Java, the type system was rather simple: you had classes and interfaces and everything was represented in the Reflection API by instances of the <code>java.lang.Class</code> class. Which was arranged very conveniently, since you got all the reflective functionality for free with your regular programming work; whenever you declared a class, the Java Virtual Machine would magically arrange at runtime for a <code>java.lang.Class</code> instance to appear to represent the new class you had just written. And everything (even primitive types) was represented by a <code>java.lang.Class</code> instance, whether it was really a class, or an interface or anything else. Simple.</p>
<p>With the introduction of generics, the simplicity is unfortunately gone. Parametric polymorphism forces a language to have a far more extensive type system, capable of making distinctions between all sorts of different <em>kinds</em> of types. Before we could get away with calling everything a class; now, we have classes (like before), but we also have parameterized classes and type variables (and annotations and varargs, but let&#8217;s not care about those for now). This is because we have to be able to distinguish between a regular old class (or interface), a class that has type parameters and the type parameters themselves (which, after all, are <em>also</em> a kind of type in the language).</p>
<p>To deal with all this, Java changed its type system and the way it is represented in the Reflection API. For starters, every type in Java is now a form of type &#8212; which is represented by the new interface <code>java.lang.reflect.Type</code>. Since classes and interfaces are types, <code>java.lang.Class</code> is now a subtype of <code>java.lang.reflect.Type</code>. But there are more subtypes of this new interface, including <code>java.lang.reflect.TypeVariable</code> (which represents a type variable in a generic declaration) and <code>java.lang.reflect.WildcardType</code> (which represents generic wildcards used when you cannot be definite about a type). And in addition to the new <code>java.lang.reflect.Type</code> type, there is also <code>java.lang.reflect.GenericDeclaration</code> interface, which represents the declaration of a generic type (in our example above, the declaration of the Example class is a generic declaration). Since generic declarations usually declare classes and interfaces, the main implementation of the GenericDeclaration interface is also <code>java.lang.Class</code>.</p>
<p>Confused already? Good, because now it gets worse. How many types do you think you introduce to the Java language every type you declare a generic class? The correct answer is <em><strong>infinitely many</strong></em>. Of course there&#8217;s the obvious one, the generically declared class you just typed in by hand. But also every potential use with a specific type is a new type in Java. In the case of our Example class, for instance, we&#8217;ve introduced Example&lt;T&gt; but also (potentially) Example&lt;String&gt;, Example&lt;Integer&gt;, Example&lt;Number&gt; and so on. Every time you come up with an Example in which the generic parameter T has been substituted for a real type, that&#8217;s a new type in the Java language. And the JVM represents these by automagically introducing an instance of a special subtype of <code>java.lang.reflect.Type</code> called <code>java.lang.reflect.ParameterizedType</code> (which is not the parameterized type declaration that it sounds like, but rather an instance of the generic declaration with all the type varables filled in with a real value).</p>
<h3>Type erasures and reifiable types</h3>
<p>If the discussion above already made your mind boggle, you&#8217;re going to love what comes next. You see, when the powers that be were working on Java generics, they decided that the most important thing would be to remain backwards compatible. That is, the Example class introduced earlier should still work with Java 1.4 code once compiled. That means that all the generics stuff in Java is purely administrative data to be used by the compiler, but at runtime it all gets thrown out (you can still discover it using the Reflection API in an administrative sense, but it doesn&#8217;t affect the interaction with other classes). So, in effect, at runtime the Example class is still a class that declares a method using <code>java.lang.Object</code> as a formal parameter. It&#8217;s just that the compiler has done extra verification so we do not need runtime type checking.</p>
<p>This choice by the language designers has some consequences. For starters, it means that at compile time all generic code goes through a process called <em>type erasure</em>, which really means that all generic data is removed. So we forget that it is Example&lt;T&gt; (this becomes just Example, like in Java 1.4) and we forget that stringExample is an Example&lt;String&gt; (at runtime it will just be an Example).</p>
<p>This same choice also means that we have a distinction between what is called <em>reifiable types</em> and <em>non-reifiable types</em>. Essentially this means that in the case of some types we can completely discover at runtime what their full generic declaration was (this is called <em>reifiable</em>) and in other cases this is not possible.</p>
<h3>Discovering type parameter values at runtime</h3>
<p>So the question of discovering the type parameter values at runtime is going to center around whether we are using a reifiable type or not. And let me get right down to it: very often this is going to mean that the answer is &#8220;no, you cannot discover at runtime&#8221;. In the case of our Example class for instance, the compiler throws away all the generic information during compilation so stringExample will never know that it is working with Strings.</p>
<p>So when <em>can</em> you discover type parameter values at runtime? Well, if you have explicitly introduced a ParameterizedType (i.e. a fully defined, fully resolved form of a generic class with all the type parameters filled in). ParameterizedType information is definite, you see, and not generic. So it doesn&#8217;t get erased by the compiler. An example to clarify:</p>
<ul>
<li>The generic class Example&lt;T&gt; gets erased into Example by the compiler</li>
<li>The parameterized type Example&lt;String&gt; stays, because it is definite at compile time</li>
</ul>
<p>So how do you explicitly introduce a ParameterizedType? Through subtyping. If you create a definite subclass of a generic type, that means the type hierarchy at runtime <strong>must</strong> include the ParameterizedType (otherwise there is a hole in the type hierarchy). And a ParameterizedType (being a fully resolved, reifiable type) allows you to discover every detail of its being. Let&#8217;s look at this in the case of our Example. First, we introduce a subclass of Example for Strings:</p>
<pre>
<pre class="brush: java; title: ; notranslate">public class Example&lt;T&gt;
{
     public void reportType()
     {
         System.out.println(&quot;This example is using type &quot; + [what goes here?] + &quot; for parameter T&quot;);
     }
}

public class StringExample extends Example&amp;lt;String&amp;gt; {}
</pre>
</pre>
<p>This code will introduce three <em>types</em> to the language at runtime: Example (the erased version of Example&lt;T&gt;), StringExample and Example&lt;String&gt; (the String-specific, non-generic, fully reifiable supertype of StringExample). Why is Example&lt;String&gt; not lost as a type? Because otherwise StringExample wouldn&#8217;t have a supertype anymore. After all, Example cannot be the supertype of StringExample &#8212; it doesn&#8217;t know about Strings, only about Objects. And StringExample cannot inherit directly from Object because it has to inherit the report method from somewhere. So there has to be an intermediate type that introduced a String-specific version of the report method (and any other inherited methods). So there is this mysterious Example&lt;String&gt; supertype. By the way, don&#8217;t expect this type to show up as a <code>java.lang.Class</code> instance: it&#8217;s not a class that you can instantiate or an interface that you can cast to. But it&#8217;s there nevertheless.</p>
<p>So now how do we do discovery and implement the report method? As with all uses of the Reflection API, we start out by getting the <code>java.lang.Class</code> instance that represents StringExample. Starting in Java 5.0, Class has a new method called <code>getGenericSuperclass()</code>, which returns the <code>java.lang.reflect.Type</code> that represents the (possibly generic) supertype of the class. In the case of StringExample that is a <code>java.lang.reflect.ParameterizedType</code> representing Example&lt;String&gt;. ParameterizedTypes have an array of actual type arguments, Types representing the actual types the ParameterizedType was instantiated with. And if any of those types is a Class, that is the definite, reifiable type we are looking for. So the report method will look like this:</p>
<pre>
<pre class="brush: java; title: ; notranslate">public class Example&lt;T&gt;
{
     public void reportType()
     {
         Class thisClass = getClass();
         // Since we KNOW this must be a ParameterizedType, we can cast
         ParameterizedType pType = (ParameterizedType)thisClass.getGenericSuperclass();
         Type firstType = pType.getActualTypeArguments()[0];
         Class whatWeWant = (Class)firstType;
         System.out.println(&quot;This example is using type &quot; + whatWeWant.getName() + &quot; for parameter T&quot;);
     }
}

public class StringExample extends Example&lt;String&gt; {}
</pre>
</pre>
<p>Of course, normally you would have to check whether firstType is really a <code>java.lang.Class</code>.</p>
<h3>Conclusion</h3>
<p>In this article we have discussed the changes to the Java 5.0 type system with respect to genericity and with an eye towards runtime discovery of type parameter values. This has lead us to review the new concept of Type in the type system and the many subtypes thereof. It has also lead us to examine the differences and causes of differences between reifiable and non-reifiable types. Finally, we have distinguished when type variable values are discoverable and when they are not, as well as how their values can be discovered.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F10%2F27%2Fsome-notes-on-discovering-your-type-parameter-using-the-reflection-api%2F&amp;title=Some%20notes%20on%20discovering%20your%20type%20parameter%20using%20the%20Reflection%20API&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/10/27/some-notes-on-discovering-your-type-parameter-using-the-reflection-api/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>The Long and Winding Road: a tale of grouping my mails using a user-defined field in Outlook</title>
		<link>http://www.gridshore.nl/2009/10/10/the-long-and-winding-road-a-tale-of-grouping-my-mails-using-a-user-defined-field-in-outlook/</link>
		<comments>http://www.gridshore.nl/2009/10/10/the-long-and-winding-road-a-tale-of-grouping-my-mails-using-a-user-defined-field-in-outlook/#comments</comments>
		<pubDate>Sat, 10 Oct 2009 01:33:38 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Microsoft Outlook 2007]]></category>
		<category><![CDATA[Outlook]]></category>
		<category><![CDATA[User-Defined Fields]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2009/10/10/the-long-and-winding-road-a-tale-of-grouping-my-mails-using-a-user-defined-field-in-outlook/</guid>
		<description><![CDATA[<p>First and foremost an apology to all regular readers: I fully realize GridShore is not intended to deal with Microsoft technology (or whatever detritus is collected under that name). However, this one is such a beauty of having to go the long way to get things done that I don&#8217;t want to hold back.</p> [...]]]></description>
			<content:encoded><![CDATA[<p>First and foremost an apology to all regular readers: I fully realize GridShore is not intended to deal with Microsoft technology (or whatever detritus is collected under that name). However, this one is such a beauty of having to go the long way to get things done that I don&#8217;t want to hold back.</p>
<p>As with many a long and winding trail, this one started this morning with what seemed like a short hike across a small and uncomplicated footpath. You see, of late I have found myself making more and more use of the different features of Outlook (something to do with becoming more senior in my company&#8230;). Among others, I&#8217;ve found that I&#8217;ve started using the little flags to mark mails that I have to get back to. But I receive so many mails nowadays that even in a single day the flags get snowed under and pushed off the list. Of course I could just sort by flag status, but I prefer to have today&#8217;s mails at the top (rather than the flags and ticks from two weeks ago). So I had myself a bright idea this morning: I&#8217;ll just change the grouping of my mails to group by received date and then flag status within the date groups. Walk in the park, right?</p>
<p>Oh mother&#8230;.</p>
<p><span id="more-912"></span>
<p>&nbsp;</p>
<h3>First strike: the very simple idea</h3>
<p>Okay, to recap, I wanted to end up with the mails in my inbox grouped first by date of receipt, then by flag status. Now, as it happens, if you do nothing to your Inbox (or any mail folder), Outlook 2007 sorts mails by date by default. You can even see this: just right-click the column headers in Outlook and select Group Box. You&#8217;ll see a tree display of grouping fields.</p>
<p>So, simple idea: just drag the Flag Status column into this Group Box to add it as a grouping to the Date. Unfortunately though, Date is an implicit rather than real property that Outlook groups by if there is nothing else and you cannot add any sub grouping to it. You can <strong>replace</strong> Date with anything, but you cannot add to it. Scratch that idea.</p>
<h3>Second strike: a slightly less simple idea</h3>
<p>So, the implicit Date as main grouping is out. No biggie, because the Receipt time is included in each mail as a property by Outlook. You even see it as a column in the default layout of every mailbox. Quick job to select that instead of the Date, then subgroup by Flag Status.</p>
<p>The result is, unfortunately, unusable. You see, the Receipt column includes the <strong>time</strong> as well as the date, even if you format the column to include only the date (the column format is really just for display). Almost no two mails arrive within the same minute. Group on Receipt time and you&#8217;ll end up with a million groups consisting of just one mail (maybe two every now and then). So that was that idea up the spout as well.</p>
<h3>Third strike: some formula magic</h3>
<p>Okay, so we cannot sort on Receipt time because it is too detailed. And there is no date-only column. But Outlook has a neat little party trick: user-defined fields (UDFs). You can define mail items to have custom properties <em>and you can even associate a VB formula with those properties</em>. So here&#8217;s our solution: create a custom property which will contain the Receipt time with the time part stripped off. Then use that as the main group selector.</p>
<p>Creating a UDF in Outlook 2007 is easy: right-click the column headers and select Field Chooser. From the drop-down, select &#8220;User-defined fields in Inbox&#8221;. Then hit the New button and select Formula as type. Fill in a name for the field and in the Formula box fill in</p>
<p>
<pre class="brush: vb; title: ; notranslate">DateValue( [Received] )</pre>
</p>
<p>Now right-click the column headers again and select &#8220;Customize current view&#8221;. Hit the &#8220;Group by&#8221; button. Uncheck the checkbox and select &#8220;User-defined fields in Inbox&#8221; from the drop-down at the bottom. Now, in the first drop-down for grouping field, select your new field and&#8230;. snag. You cannot select the field.</p>
<p>You see, you cannot group by formula UDFs in Outlook. Probably because VB is typeless in principle, so Outlook cannot predict the type of your field and so cannot compare the values reliably. So that idea is out as well.</p>
<h3>The long way around</h3>
<p>So that means there&#8217;s only one way to do this: add a custom property to each mail in the Inbox with the date part of the receipt time. And since it has to be <em>typed</em> field, it has to be added <strong>programmatically</strong>. So the long road means delving into the guts of VBA for Outlook 2007.</p>
<p>Since we&#8217;re going into programming mode here, it is necessary to think a little about what must be done. We want to add a custom date property to each mail in the inbox. But there are two kinds of mails in the inbox:</p>
<ol start="0">
<li>Mails that are already there, which require a one-time loop to add the property.</li>
<li>Mails which will come in later and must have the property added as they arrive; this will require event handling.</li>
</ol>
<p>In both cases we will have to perform the following, general steps:</p>
<ol start="0">
<li>Get hold of the mail M to be augmented.</li>
<li>Get M&#8217;s receipt time R.</li>
<li>Figure out the date part D<sub>R</sub> of R.</li>
<li>Create a custom property EmailDate for M, with value D<sub>R</sub>.</li>
<li>Save M with its new property EmailDate.</li>
</ol>
<h4>Visual Basic for Applications in Outlook</h4>
<p>Let&#8217;s start with some basics about Outlook Basic (ha, ha, I make a funny). Outlook VBA all lives in one large VBA project file called <strong>VBAProject.OTM</strong>, which contains one project called Project1. Everything has to be added there. Project1 itself consists of a sort of main module called ThisOutlookSession. This is the place to put simple macro&#8217;s and the entry points to larger programs.</p>
<p>VBA for Outlook is essentially the same VBA you find in any Microsoft application: a VBA editor (hit Alt+F11 in Outlook) which supports a subset of Visual Basic with some built-in functions and an application-specific object model. In the case of VBA for Outlook this model models things like Folders, MailItems, CalendarItems and so on.</p>
<p>Like all VBA languages, VBA for Outlook allows you to create special variables which can hold object instances that are aware of application events. For example, if you declare a variable like so:</p>
<p>
<pre class="brush: vb; title: ; notranslate">Dim WithEvents inboxItems As Outlook.Items</pre>
</p>
<p>and then instantiate inboxItems to be the list of items in the inbox, then inboxItems will be aware of any events that occur in the inbox. You can declare event handlers for any interesting events you want to respond to.</p>
<h4>Dealing with existing messages</h4>
<p>Let&#8217;s start simply with the existing messages in the Inbox. To deal with those we need a run-once loop and no event handling. In order to carry out the process outlined above, we will have to get hold of the folder object that represents the inbox in Outlook. We can then loop over the contents of this folder.</p>
<p>While setting the process for existing messages, we will be dealing with mail messages, which are Outlook.MailItem objects. We will be adding a custom property, which is an Outlook.UserProperty object. And we have to deal with the inbox, which is a mail folder &#8212; an Outlook.MAPIFolder object.</p>
<p>Getting hold of the Inbox folder is done by getting the default inbox folder from Outlook&#8217;s MAPI namespace &#8212; this is an object that we can get from the Application object. The Application object is present in every VBA language and represents the application (in this case, Outlook). The MAPI namespace has a getDefaultFolder method which takes a convenient constant to indicate we want the Inbox. After that we can loop over the objects in the Inboxes Items list to set the properties. The result looks like this:</p>
<pre class="brush: vb; title: ; notranslate">Private Sub SetInitialProperties()
  Dim ns As Outlook.NameSpace
  Dim fld As Outlook.MAPIFolder
  Dim objUnknown As Object
  Dim mail As Outlook.MailItem
  Dim prop As Outlook.UserProperty

  Set ns = Application.GetNamespace(&quot;MAPI&quot;)
  Set fld = ns.GetDefaultFolder(olFolderInbox)

  For Each objUnknown In fld.Items
    If TypeOf objUnknown Is MailItem Then
      Set mail = objUnknown
      Set prop = mail.UserProperties.Add(&quot;EmailDate&quot;, olDateTime, True)
      prop.Value = DateValue(mail.ReceivedTime)
      mail.Save
      Set prop = Nothing
      Set mail = Nothing
    End If
  Next

  Set objUnknown = Nothing
  Set fld = Nothing
  Set ns = Nothing
End Sub</pre>
<p>As you can see, adding a custom property is pretty straightforward; there are constants to indicate the type (which is why we are using VBA, of course). Getting the date is a matter of manipulating the existing ReceivedTime property of each mail a little. It is worth noting in the loop that there is a check to see if each item is really a MailItem &#8212; the Inbox may also contain sub folders, you see.</p>
<p>Next, hit the Run button to run the routine. Then check in Outlook (right-click the column headers, select the Field Chooser and select the UDF&#8217;s from the drop-down; drag the new field onto the Inbox columns). The new field contains the date of the mails, but the time midnight (so no more minutes to screw up the grouping). Try grouping by the new column &#8212; this time it works, since the new column has a type.</p>
<h4>Dealing with incoming mail</h4>
<p>In order to set the same property on incoming mail, we need an event handler. As explained above, we can create a special variable that will be made aware of events on any specific object (like the list of items in the Inbox). In fact, that list is particularly useful to monitor since it broadcasts an event every time an item is added. With that information, the actual event handler is pretty straightforward:</p>
<pre class="brush: vb; title: ; notranslate">Private Sub inboxItems_ItemAdd(ByVal Item As Object)
  Dim prop As Outlook.UserProperty
  Dim mail As Outlook.MailItem

  If TypeOf Item Is MailItem Then
    Set mail = Item
    Set prop = mail.UserProperties.Add(&quot;EmailDate&quot;, olDateTime, True)
    prop.Value = DateValue(mail.ReceivedTime)
    mail.Save
    Set prop = Nothing
    Set mail = Nothing
  End If
End Sub</pre>
<p>Again, note the check for whether an item is a MailItem and not a new sub folder.</p>
<p>As you can see, the VBA convention is to have the name of the event handler be &lt;variable&gt;_&lt;event&gt;(&lt;parameters&gt;). This is also how the VBA interpreter links events to methods (or subroutines in this case).</p>
<p>Now, the event handler is pretty simple. But it does depend on the variable inboxItems being initialized to refer to the list of items in the inbox. So how is this accomplished?</p>
<h4>Initializing the inbox variable</h4>
<p>Obviously, since Outlook does not provide a database for its VBA macros, there is no such thing as a persistent variable. We will have to redefine the inboxItems variable each time Outlook starts. You guessed it: we need another event handler, written the same way as the earlier one (a subroutine referring to a variable). But isn&#8217;t that a chicken-and-the-egg problem? How do we initialize <strong>that</strong> variable? Luckily, as remarked before, there is one variable which is always implicitly available: the Application variable. And that represents Outlook which, lucky for us, is exactly what we need (we want to listen for application starts of Outlook). So our primal event handler will look like this:</p>
<pre class="brush: vb; title: ; notranslate">Private Sub Application_Startup()
  Dim ns As Outlook.NameSpace
  Dim fld As Outlook.MAPIFolder

  Set ns = Application.GetNamespace(&quot;MAPI&quot;)
  Set fld = ns.GetDefaultFolder(olFolderInbox)
  Set inboxItems = fld.Items

  Set ns = Nothing
  Set fld = Nothing
End Sub</pre>
<p>Startup is, of course, the event fired when Outlook starts.</p>
<p>&nbsp;</p>
<h4>Testing the event handler</h4>
<p>The simple way to test the event is to run the Application_Startup() subroutine using the Outlook VBA tool to set the system up. Hit Alt-F11, open the ThisOutlookSession module (which contains the code described above), put the cursor in the Application_Startup() routine and hit the Run button. Then go back to Outlook and send yourself a mail. Once it arrives, it will have the new property automatically set.</p>
<p>&nbsp;</p>
<h3>Just when you think you&#8217;re there&#8230;</h3>
<p>If you&#8217;ve been following along, there&#8217;s another test you can do (and which I did): close Outlook and start it up again. Then send yourself another mail. If you&#8217;re running Outlook 2003 or 2007, the new mail probably will <strong>not</strong> have the new UDF set.</p>
<p>So what went wrong? We created the event handler, the Outlook startup event handler to set everything up and tested it to see it working? Well, some debugging will tell you almost immediately that the Outlook startup event handler is not called. And the reason, it eventually occurred to me, is macro security. You see, by default Outlook will not run unsigned macros. Even macros defined in its own macro module.</p>
<p>You can get around this easily by going to the security settings for macros (in Outlook 2007 it&#8217;s called the TrustCenter) and selecting to run unsigned macros with a warning. But a better idea is to create a self-signed certificate and use that to sign your macro module.</p>
<p>To create the certificate, you need a tool called SelfCert.exe, which is installed with Office in the Office install directory (try c:\program files\Microsoft office\office <strong>or</strong> c:\program files\Microsoft office\office12). Run the program, fill in a name for your certificate and click OK. Then go to the Outlook VBA editor and select Digital Signature from the Tools menu. Click Choose and select your certificate. Click Ok and then save the module.</p>
<p>Now restart Outlook. It will give you a warning about macros, but if you select &#8220;Enable macros&#8221; everything will work. You can elect to trust your own certificate in the same dialog, which will eliminate the warning.</p>
<h3>Finally&#8230;</h3>
<p>So, finally, after all that, my Inbox is now grouped by date and then flag status. That took some doing&#8230;..</p>
<p>But perhaps someone else will find the experience useful.</p>
<p>&nbsp;</p>
<h5>Sources</h5>
<p>The following forum archive provided me some valuable insights into how to get all of this working: <a title="http://www.eggheadcafe.com/forumarchives/outlook/Oct2005/post24967825.asp" href="http://www.eggheadcafe.com/forumarchives/outlook/Oct2005/post24967825.asp">www.eggheadcafe.com/forumarchives/outlook/Oct2005/post24967825.asp</a></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F10%2F10%2Fthe-long-and-winding-road-a-tale-of-grouping-my-mails-using-a-user-defined-field-in-outlook%2F&amp;title=The%20Long%20and%20Winding%20Road%3A%20a%20tale%20of%20grouping%20my%20mails%20using%20a%20user-defined%20field%20in%20Outlook&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/10/10/the-long-and-winding-road-a-tale-of-grouping-my-mails-using-a-user-defined-field-in-outlook/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bad science&#8230;</title>
		<link>http://www.gridshore.nl/2009/09/13/bad-science/</link>
		<comments>http://www.gridshore.nl/2009/09/13/bad-science/#comments</comments>
		<pubDate>Sun, 13 Sep 2009 17:58:13 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2009/09/13/bad-science/</guid>
		<description><![CDATA[<p>The last few days I&#8217;ve been reading BAD Astronomy, a book by astronomer Philip Plait that describes common misconceptions, misuses and scientific abuses of astronomy. Partly written to be funny and partly to debunk the nonsense that arises from people misusing and abusing science, it&#8217;s a good and worthwhile read for anybody (especially if [...]]]></description>
			<content:encoded><![CDATA[<p>The last few days I&#8217;ve been reading <strong><em>BAD Astronomy</em></strong>, a book by <a href="http://en.wikipedia.org/wiki/Astronomy">astronomer</a> <a title="Philip Plait" href="http://en.wikipedia.org/wiki/Phil_Plait">Philip Plait</a> that describes common misconceptions, misuses and scientific abuses of <a href="http://en.wikipedia.org/wiki/Astronomy">astronomy</a>. Partly written to be funny and partly to debunk the nonsense that arises from people misusing and abusing science, it&#8217;s a good and worthwhile read for anybody (especially if you have some spare time on your hands).
<div class="amtap-item" lang="en" xml:lang="en"><a href="http://www.amazon.com/Bad-Astronomy-Misconceptions-Revealed-Astrology/dp/0471409766%3FSubscriptionId%3D1K0D2VE3R9MFT576B1G2%26tag%3Dgridshore-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0471409766"><img src="http://ecx.images-amazon.com/images/I/513CRq2HkML._SL110_.jpg" width="73" height="110" alt=""/></a><br />
<h3><a href="http://www.amazon.com/Bad-Astronomy-Misconceptions-Revealed-Astrology/dp/0471409766%3FSubscriptionId%3D1K0D2VE3R9MFT576B1G2%26tag%3Dgridshore-20%26linkCode%3Dxm2%26camp%3D2025%26creative%3D165953%26creativeASIN%3D0471409766">Bad Astronomy</a></h3>
<p class="author">Philip C. Plait.					Wiley 2002, 					Paperback,				288 pages,				&#36;8.38</p>
</div>
<p>Reading through the book I came to chapter 14, which deals with the doomsday advocates who swore up and down that the world was going to come to an end on May 5, 2000 due to a planetary alignment (more or less) of <a href="http://en.wikipedia.org/wiki/Mercury_(planet)">Mercury</a>, <a href="http://en.wikipedia.org/wiki/Venus">Venus</a>, <a href="http://en.wikipedia.org/wiki/Mars">Mars</a>, <a href="http://en.wikipedia.org/wiki/Jupiter">Jupiter</a> and <a href="http://en.wikipedia.org/wiki/Saturn">Saturn</a>. It was quite funny to read Plait&#8217;s description of why this neither would nor <strong>did</strong> cause catastrophe for our planet. But more than that, the chapter got me thinking about how bad science is all around us and affects us in sometimes rather drastic ways.</p>
<p><span id="more-905"></span></p>
<p>In the case of Plait&#8217;s example nothing really very drastic happened to anybody (except a few people who were duped into buying bogus survival gear to help them survive the new <a href="http://en.wikipedia.org/wiki/Ice_age">ice age</a> that the <a href="http://en.wikipedia.org/wiki/Planetary_alignment">planetary alignment</a> was supposed to <a href="http://en.wikipedia.org/wiki/Precession_(astronomy)#Astronomy">drop the planet into</a>). However, not everything that is misunderstood is so innocent. Take for example a court case in the Netherlands (this was quite a long time ago, to be honest):</p>
<p>In this particular case a bridge guard was being sued by a <a href="http://en.wikipedia.org/wiki/Barge">barge</a> captain because the captain felt the bridge guard didn&#8217;t <a href="http://en.wikipedia.org/wiki/Cantilever_bridges">open the bridge</a> often enough daily. The bridge was too low for the barge to pass under (by a meter) and the frequent delays cost the captain money. So he sued to get the bridge opened more often. The judge in this case was a long-standing lord of the bench, properly educated in languages and law (as most judges), but not so much in the sciences. His ruling was that the bridge guard could not be forced to alter his ways and that instead, the captain should pay (out of his own pocket) to have the river bed under the bridge dug out an extra meter. It took testimony from a professor of physics of the <a href="http://www.tudelft.nl/">University of Delft</a> to explain to the judge that <a href="http://en.wikipedia.org/wiki/Buoyancy">that is not how it works</a>.</p>
<p><a href="http://en.wikipedia.org/wiki/Lawyer">Lawyers</a> (and related persons) are particularly good at bad science, it seems. And not just <a href="http://en.wikipedia.org/wiki/Physics">physics</a>, but also <a href="http://en.wikipedia.org/wiki/Mathematics">mathematics</a> and <a href="http://en.wikipedia.org/wiki/Logic">logic</a>. A former professor of mine (a computer scientist, philosopher and master of law) told us some particularly nice anecdotes about the brilliance of Dutch traffic law, for instance. Dutch traffic law specifies that there are priority vehicles (ambulances, police cars, etc.) which have priority in all traffic situations. Dutch traffic law also specifies that traffic signs (signs, lights, arrows painted on the road, etc.) have priority over traffic rules. Makes sense so far, right? Except, my professor pointed out, the law was written by lawyers. Who encoded the two rules mentioned into two separate and completely unrelated articles like so:</p>
<blockquote><p><em>A. One must always give precedence to priority vehicles.</em></p>
<p><em>B. Traffic signs have priority over traffic rules.</em></p></blockquote>
<p>Taken like that, the law says that priority vehicles must stop for red lights. We are all grateful that they disobey the law constantly.</p>
<p>Recently, I got embroiled in an even more far reaching example of bad logic and the law. On some forum somewhere I got into an argument with someone (whom I suspect is a first-year law student) about the <a href="http://en.wikipedia.org/wiki/Dutch_constitution">Dutch constitution</a>. Our constitution is a pretty typical constitutional document which describes the basic organization of country and government, as well as the civil rights of the citizens and other inhabitants. Perhaps a little unusual (but quite well thought-out, I feel), our constitution recognizes that not every right can or should be absolute. Several of our civil rights are therefore worded in the following structure:</p>
<div style="margin-left: 2em" dir="ltr">
<ol>
<li>
<div>Some general rule which applies if no exception is made;</div>
</li>
<li>
<div>The Law determines which exceptions exist to the aforementioned rule.</div>
</li>
</ol>
</div>
<p>For example, our constitution guarantees the right to free speech; but the constitution also leaves room for the law to set limits (such as forbidding insults to whole groups within society).</p>
<p>The suspected law student, <a href="http://hawaii.hawaii.edu/wwwreading/Fallacies/fallacydefinitions.htm">in a bit of brilliant logical derivation</a>, arrived at the conclusion that it is possible for the law in our country to contradict the constitution and therefore that our constitution as a whole is meaningless. That is (to stick with the example above), if it is forbidden to insult all Jews/Christians/Muslims in the country, then the law violates the free speech article and since the constitution is not enforced over the law it means nothing. I&#8217;ll admit that the truth is a little subtle: the constitution sets a <em>general rule</em> and allows the law to create exceptions. So the law creates an exception (or violation) of the general rule, but not of the constitution. But still, you&#8217;d think that even a law student (a lawyer to be) should be able to spot that he&#8217;s claiming that a law whose existence is <strong>explicitly allowed</strong> by the constitution is a violation of that constitution&#8230;</p>
<p>Bad science, I fear, is all around us all the time. Especially since the environment has started playing a major role in decision making. From the greenhouse effect down to whether or not you are poisoning the environment by dumping non-biodegradable plastic in it (you&#8217;re not, by the way &#8212; non-biodegradable plastic isn&#8217;t biodegradable, so it doesn&#8217;t interact with the environment if dumped in nature somewhere), bad science pervades life. Two months ago, in The Netherlands, there was a great commotion is some village about plans to store carbon dioxide gas in an old natural gas pit which has been depleted by the national gas seller. Now, this was a porous rock stratum at over a kilometer depth in which nature has stored flammable gas for millions of years, under pressure, without a single leak or explosion. But for some reason the inhabitants (who had been living, technically, on a bomb for centuries before the gas was pumped out) are now scared of living on top of inert, non-flammable gas that is to be stored in the same stratum under less pressure than the gas was under.</p>
<p>Bad science is often funny to read about. But equally as often it is no joke at all, as it leads to bad decisions. When people misunderstand science and especially when bad people are creating bad science in order to make people make bad decisions. So a valid question arises: where are the scientific and engineering communities amidst this storm of bad science? Why don&#8217;t they have a more active role in society and why doesn&#8217;t society ask them to have a more active part?</p>
<p>In this country, we have several professional societies for scientists and engineers. I&#8217;m even a member of one of them (KIvI/NIRIA). Now, it&#8217;s not that they don&#8217;t try. Really, they do. <a href="http://www.kiviniria.net/">KIvI/NIRIA</a>, the <a href="http://www.onri.nl/cms/publish/content/showpage.asp?themeid=2">ONRI</a>, the VSNU, all sorts of others, they all feel the need to play a more active role in society, to influence decision making and to try and be voices of reason amidst the insanity. But they do it in the way engineers have become accustomed to over the past forty years; silently, in the background, trying to be the quiet advisor in the ear of the board. And so they often miss; they get drowned out in the melee, overruled by the opinions of the crowd that are based on nothing that makes any sense. And then, instead of trying to push bask, they submit to the nonsense because the decision has been made and once the decision has been made you no longer disagree. And that may be the worst science of all&#8230;.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F09%2F13%2Fbad-science%2F&amp;title=Bad%20science...&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/09/13/bad-science/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Upgrade woes and frustrations</title>
		<link>http://www.gridshore.nl/2009/08/06/upgrade-woes-and-frustrations/</link>
		<comments>http://www.gridshore.nl/2009/08/06/upgrade-woes-and-frustrations/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 19:49:26 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=839</guid>
		<description><![CDATA[<p>This Monday my corporate laptop was upgraded. Last week I was in proud possession of an HP/Compaq NC6400, this week I have an IBM Lenovo R400 Thinkpad (an absolute Boer of a laptop, compared with the sleek and polished Compaq). It&#8217;s ugly and the control button is in the wrong place (which is inconvenient), [...]]]></description>
			<content:encoded><![CDATA[<p>This Monday my corporate laptop was upgraded. Last week I was in proud possession of an HP/Compaq NC6400, this week I have an IBM Lenovo R400 Thinkpad (an absolute Boer of a laptop, compared with the sleek and polished Compaq). It&#8217;s ugly and the control button is in the wrong place (which is inconvenient), but it has more RAM and a larger harddrive so I guess I&#8217;ll live with it.</p>
<p>Unfortunately, with the new laptop I was also downgraded: from Windows XP to Windows Vista and from Office 2003 to Office 2007. And no, those are not typos; I&#8217;ve been given new software with my new laptop and I hate every little bit of it. Vista is designed to kill your productivity and break your existing software. And even if you have software like Office (guaranteed to work due to the close ties between development teams), they make sure the new version is so bad that you can&#8217;t use that either.</p>
<p>Among my favorite bugs, failures and stupidies so far are the following:</p>
<p><span id="more-839"></span></p>
<p><strong>The LAN mystery</strong></p>
<p>At my current project, I used to connect to the corporate LAN. Nothing spectacular there: I just plugged in the network cable and set up the proxy script, filled in my username and password when prompted, done. With Vista, it doesn&#8217;t work anymore. Not even in Opera, which doesn&#8217;t even share network access configuration with IE7! The damn thing simply ignores my proxy server settings, doesn&#8217;t prompt me for a password and then cannot connect properly to the internal systems. Is it a new browser version? No, because I used the same browsers on XP. It&#8217;s Vista.</p>
<p>But don&#8217;t think I&#8217;m locked out though &#8212; my wireless can connect. Slower than LAN, but still. Mind, I don&#8217;t think it works properly; I think I&#8217;ve just lucked out in that I have to enter PEAP-authentication details for the wireless and those settings get passed on to the proxy. Because I don&#8217;t think the wireless stack is picking up the proxy settings correctly either.</p>
<p><strong>Opera and Media Player</strong></p>
<p>On my old laptop, I used Opera 9.64 and Windows Media Player 11. Worked together just fine. In Vista, I suddenly need a <a href="http://www.opera.com/support/kb/view/434/" target="_blank">special plugin</a> to enable the same combination. Sorry, but there&#8217;s no way you get that without doing it on purpose. Come on, European Commission, why do you keep screwing around with these guys? The <strong><span style="text-decoration: underline">maximum</span></strong> fine is 10% of their gross, well over $700 million a pop!</p>
<p><strong>Ribbons&#8230;</strong></p>
<p>So after all that joy, I needed Word today. Word 2007, my first application-related WTF moment on my new laptop. Who the hell came up with that damned ribbon? I can&#8217;t find ANYTHING anymore! My normal working day includes IDEs, text editors and browsers. Mostly, I don&#8217;t need Office. So when I DO need it, I don&#8217;t want to be tossed into a bloody maze of having to find out where they put everything. Thankfully there are tools available online that send the ribbons back to the hell they came from and give you back the menus intended for human beings.</p>
<p><strong>I am NOT a moron</strong></p>
<p>While trying to work out why my network connections weren&#8217;t working, I stumbled on this great new feature: not only have all the real settings been hidden beneath at least five layers of useless windows, but now you have to give yourself permission to access most of them. I AM NOT A MORON! I DON&#8217;T NEED A NANNY, NOR A KINDERGARTEN COMPUTER! I HAVE AN ADMINISTRATOR ACCOUNT SO JUST LET ME INTO THE FUCKING SETTINGS!</p>
<p>God, I want a Linux distro on my laptop.</p>
<p><strong>And finally&#8230; shadow files</strong></p>
<p>This one was the final straw that convinced me to spew my wrath in a blog post. One of the more brilliant innovations in Vista is a built-in revision system called Shadow Files. It makes regular copies of all your files so you can rollback any mistakes. Everybody who has ever used <a href="http://subversion.tigris.org/" target="_blank">Subversion</a> will understand the benefits. But of course, Microsoft got it wrong: After I got done installing all my software, end of day Tuesday, I had 105 Gb free (out of 147). By midday today, it was down to 91,4 Gb. Turned off the miserable Shadow Files and shot back up to 113 Gb. 22 Gb just for useless revisions. So here&#8217;s my top tip for the day:</p>
<blockquote><p>TURN THE DAMN THING OFF</p></blockquote>
<p>Seriously. It devours your harddrive, for a feature that you don&#8217;t need. No, I&#8217;m not kidding; you&#8217;ve lived without it for years for the stuff you never touch (most of your system) and if you have files for which you really DO have to save revisions, Subversion does a perfect and controllable job. You&#8217;ll be fine without it, so save your harddrive and the aggravation.</p>
<p><strong>Is there any salvation?</strong></p>
<p>Well, not for me at least. I&#8217;ve asked and I cannot get my old laptop back. Nor can I install WinXP on my own, or any other OS. So I&#8217;m basically screwed until the next system upgrade. But at least I can offer everybody else this wisdom: don&#8217;t downgrade to Vista. If they offer you a new system, resist. It&#8217;s just not worth the gray hair.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F08%2F06%2Fupgrade-woes-and-frustrations%2F&amp;title=Upgrade%20woes%20and%20frustrations&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/08/06/upgrade-woes-and-frustrations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Just a moment of your time&#8230;.</title>
		<link>http://www.gridshore.nl/2009/05/21/just-a-moment-of-your-time/</link>
		<comments>http://www.gridshore.nl/2009/05/21/just-a-moment-of-your-time/#comments</comments>
		<pubDate>Thu, 21 May 2009 14:26:30 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=779</guid>
		<description><![CDATA[<p>Like Jettro in his perspective on content management, I would like to draw your attention to another blog which was published on the Daily WTF and mentioned on The ServerSide. It&#8217;s hilarious and a good lesson as well: Java is Slow!</p> <p>Enjoy!</p> ]]></description>
			<content:encoded><![CDATA[<p>Like Jettro in his <a href="http://www.gridshore.nl/2009/05/19/a-perspective-on-content-management/">perspective on content management</a>, I would like to draw your attention to another blog which was published on the Daily WTF and mentioned on The ServerSide. It&#8217;s hilarious and a good lesson as well: <a href="http://thedailywtf.com/Articles/Java-is-Slow!.aspx">Java is Slow!</a></p>
<p>Enjoy!</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F05%2F21%2Fjust-a-moment-of-your-time%2F&amp;title=Just%20a%20moment%20of%20your%20time....&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/05/21/just-a-moment-of-your-time/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dutch Direct: Celebrating the 50th anniversary of Dijkstra&#8217;s Shortest Path algorithm</title>
		<link>http://www.gridshore.nl/2009/04/20/dutch-direct-celebrating-the-50th-anniversary-of-dijkstras-shortest-path-algorithm/</link>
		<comments>http://www.gridshore.nl/2009/04/20/dutch-direct-celebrating-the-50th-anniversary-of-dijkstras-shortest-path-algorithm/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 13:31:12 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[algorithmics]]></category>
		<category><![CDATA[Dijkstra]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2009/04/20/dutch-direct-celebrating-the-50th-anniversary-of-dijkstras-shortest-path-algorithm/</guid>
		<description><![CDATA[<p>This year, 2009, we celebrate the 50th anniversary of a landmark moment for (Dutch) computing science: it is 50 years ago this year that Edsger Wybe Dijkstra, The Netherlands&#8217; most famous computing scientist, published his Shortest Path Algorithm in Numerische Mathematik, the German journal of numerical mathematics.</p> <p>The shortest path algorithm is a solution [...]]]></description>
			<content:encoded><![CDATA[<p>This year, 2009, we celebrate the 50<sup>th</sup> anniversary of a landmark moment for (Dutch) computing science: it is 50 years ago this year that <a href="http://en.wikipedia.org/wiki/Edsger_Dijkstra">Edsger Wybe Dijkstra</a>, The Netherlands&#8217; most famous computing scientist, published his <a href="http://en.wikipedia.org/wiki/Dijkstra's_algorithm">Shortest Path Algorithm</a> in <a href="http://www-m3.ma.tum.de/twiki/pub/MN0506/WebHome/dijkstra.pdf">Numerische Mathematik</a>, the German journal of numerical mathematics.</p>
<p>The shortest path algorithm is a solution to a problem from graph mathematics. A graph is a mathematical construct consisting of vertices (or nodes) connected by edges (or sides). Each path has a value (a length, a cost, etc.). The object of the problem is to find the shortes path through the graph from one point to a certain other point. And just in case that sounds like abstract mathematical nonsense that nobody will ever have use for: this problem and its solutions have been applied to network routing, traffic pattern regulation and worldwide distribution of goods. For those of you who drive cars: next time you get in you car, take a look at your satnav — then say &#8220;thank you Edsger&#8221;.</p>
<p>Dijkstra&#8217;s algorithm is not the first solution to this problem. However, his solution differed from the solutions presented before in that it is simple and straightforward (most textbooks and professors covering the subject even remark that it is strange that nobody came up with this easy solution sooner). It is also one of the first solutions that was designed with implementation on a computer in mind, so it is optimal with respect to running time and storage need. This in turn undoubtedly explains its pervasiveness throughout computing even (or only?) 50 years after its invention. It&#8217;s also why Dijkstra is most famous internationlly for this algorithm; even to the point of being insulting, because it is really one of the least impressive results of his career, which literally lifted computing science from trial-and-error tinkering to a science.</p>
<p>Dijkstra&#8217;s career focussed mostly on developing the science of computing science, by developing techniques for constructing provably correct solutions to problems by constructing the solutions hand in hand with the proof of correctness. Dijkstra was a great believer in computing science&#8217;s mathematical roots because exactly those roots yield the properties that computing science so desperately needs: correctness, accuracy and elegance. One of Dijkstra&#8217;s axioms in fact is that <em>Beauty is our Business.</em> So in that spirit (and, I hope, in Dijkstra&#8217;s spirit as well) I would like to present this birthday salute to Dijkstra&#8217;s algorithm – and to the man himself as well: a construction of Dijkstra&#8217;s Algorithm.</p>
<p><span id="more-755"></span>
<p>&nbsp;</p>
<h3>Some basics</h3>
<p>&nbsp;</p>
<p>First, let&#8217;s cover some basics from graph theory.</p>
<p>First of all, a graph <strong>G</strong> consists of two sets <strong>V(G)</strong> and <strong>E(G)</strong>.</p>
<ul>
<li>The set <strong>V(G)</strong> is the set of vertices (or nodes) of <strong>G</strong> and is simply a set of names. For example, <strong>V(G) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}</strong> defines a vertex set for a graph consisting of eleven nodes, using a natural number to label each vertex.</li>
<li>The set <strong>E(G)</strong> is the set of edges (or sides) of <strong>G</strong> and consists of pairs of vertices from <strong>V(G)</strong>; the interpretation is that if a pair of vertices is in the set <strong>E(G)</strong>, then those vertices are connected by an edge in the graph <strong>G</strong>. Since we allow for incomplete graphs (graphs in which not every pair of vertices is connected), we formally define <strong>E(G)</strong> to be a subset of the set of all possible pairs of vertices: <strong>E(G) <em><u>in</u></em> V(G) × V(G)</strong>.
<p>For example, given the set <strong>V(G)</strong> above, we might have <strong>E(G) = { (0,1), (1,0), (0,2), (2,0), (0,3), (3,0), (1,5), (5,1), (1,6), (6,1), (2,5), (5,2), (3,4), (4,3), (4,7), (7,4), (4,8), (8,4), (5, 10), (10, 5), (6,9), (9,6), (7,8), (8,7), (8,9), (9,8), (8,10), (10,8)}</strong>.</li>
</ul>
<p>At this point a small note is necessary on the difference between directed and undirected graphs, that is graphs of which the edges can only be traversed in one direction and graphs of which the edges can be traversed in both directions. This can make a difference in how the set <strong>E(G)</strong> is interpreted. For simplicity sake we will pretend in the formal definition that every edge is directed and that an undirected graph is one for which the following predicate holds:</p>
<blockquote>
<p><u><em>forall</em></u> v,w <u><em>in</em></u> <strong>V(G)</strong>: (v,w) <em><u>in</u></em> <strong>E(G)</strong> =&gt; (w,v) <em><u>in</u></em> <strong>E(G)</strong></p>
</blockquote>
<p>That is, if an edge exist in the graph, then the edge in the reverse direction also exists in the graph. If we use these semantics the example of an edge set given above describes an undirected graph.</p>
<p>Of course a graph may also be depicted visually. If the graph is not too large, doing so might provide insight. The graph described in the examples above, for instance, might be depicted like this:</p>
<p align="center"><img height="201" alt="Graph Example" src="http://www.gridshore.nl/wp-content/uploads/graphexample.png" width="301" /></p>
<p>Note that in this example I&#8217;ve drawn the edges as single, undirected lines. A more correct alternative would have been to draw two edges with arrows for each line, one going in one direction and one in the opposite. However, this way of drawing is clearer.</p>
<p>As mentioned earlier each edge has a value which will be used to determine its &#8220;cost&#8221; of use. Formally we do this by introducing a <em>weighting function</em>, which is a function from the set of edges to the natural numbers or the positive real numbers: <strong>weight(G): E(G) &#8211;&gt; R<sup>+</sup></strong>. Note that it is important not to allow a negative weight; as we will see later, this breaks the algorithm. Also note that for undirected graphs we have an extra rule for the weighting function: <em><u>forall</u></em> v,w <em><u>in</u></em> <strong>E(G)</strong>: <strong>weight</strong>((v,w)) = x =&gt; <strong>weight</strong>((w,v)) = x (i.e. in an undirected graph the weight of an edge and its &#8220;reverse&#8221; edge are the same).</p>
<p>As final part of the preliminaries, we have to formalize the concept of a path and the length of a path. Of course we all have an intuitive notion of what a path is: it&#8217;s a route you can follow over the edges of a graph to get from one vertex to another. More formally we will say</p>
<ul>
<li>
<div style="MARGIN-RIGHT: 0px">there is a <em>simple path</em> <strong>P<sub>s</sub></strong>(v,w) from vertex v to vertex w iff (v,w) <em><u>in</u></em> <strong>E(G)</strong></div>
</li>
<li>
<div style="MARGIN-RIGHT: 0px">there is a <em>path</em> <strong>P</strong>(v,w) from v to w iff there is a path from v to z <strong>and</strong> there is a simple path from z to w</div>
</li>
</ul>
<p>Note that we will use the notation ++ to mean adding an edge to a path.</p>
<p>Given the definition above, the following definition of the length or cost <strong>C</strong> of a path won&#8217;t be very surprising. For a path P, the cost <strong>C</strong>(P) =</p>
<ul>
<li>
<div style="MARGIN-RIGHT: 0px">P = <strong>P</strong>(v,v) =&gt; <strong>C</strong>(P) = 0 (i.e. staying where you are is free)</div>
</li>
<li>
<div style="MARGIN-RIGHT: 0px">P = <strong>P<sub>s</sub></strong>(v,w) =&gt; <strong>C</strong>(P) = <strong>weight</strong>((v,w))</div>
</li>
<li>
<div style="MARGIN-RIGHT: 0px">P = <strong>P</strong>(v,z) ++ <strong>P<sub>s</sub></strong>(z,w) =&gt; <strong>C</strong>(P) = C(<strong>P</strong>(v,z)) + <strong>weight</strong>((z,w))</div>
</li>
</ul>
<h3>Some help</h3>
<p>In order to help us out later on, we now introduce a helper thesis Th0:</p>
<blockquote>
<p><strong>Th0: Let P(v,w) be a path on graph G and P<sub>s</sub>(w,z) be a simple path on G. Then C(P(v,w)) &lt; = C(P(v,w) ++ P<sub>s</sub>((w,z)).<br /></strong>Proof: <strong>C</strong>(<strong>P</strong>(v,w) ++ <strong>P<sub>s</sub></strong>(w,z)) = C(<strong>P</strong>(v,w)) + <strong>weight</strong>((w,z)). Due to the definition of the weighting function 0 &lt;=   <strong>weight&lt; /strong&gt; ((w,z)).</strong></p>
</blockquote>
<h3>The shortest path algorithm</h3>
<p>Given a graph and two vertices of that graph (one starting vertex and one end vertex), our goal is to find the shortest (the lowest cost) path between the starting and end vertices. For example, in the example graph above, we might want to find the shortest path between node 0 and node 10.</p>
<p>In general we will not be able to find the shortest path just by looking at the graph, that&#8217;s too difficult. But we might be able to come up with a way of constructing the shortest path one step at a time. This is the idea of the Shortest Path algorithm: building up the shortest path with small steps. Very small steps in fact: one edge at a time.</p>
<p>Let&#8217;s think a little about our problem. We have a set of vertices, two of which have a special meaning (start and end). We also have a set of edges (for simplicity sake we will assume the graph is connected, i.e. there is some way to get from any node to any other). And we have a weighting function, so we have costs for each edge in the graph.</p>
<p>After some thought on this problem, it occurs to us that we can also make a partition of the vertices into two separate sets: a &#8220;green&#8221; set of vertices of which we know the shortest path to the starting node, and an uncolored set containing all the other nodes. But do we know any such shortest paths? Yes: the shortest path from the starting vertex to itself has cost 0.</p>
<p>Here&#8217;s another thought: we know individual costs of each edge. That means that, in addition to our green set, we can create a &#8220;blue&#8221; set of vertices as well: a set of vertices not the in green set, but connected by a single edge to a vertex in the green set. Of the vertices in the blue set we know the length of a path to the starting node. It may not be the shortest path, but certainly a path. Having the blue set also has another consequence: for every node in the green set, we know something of each of its neighbors, each vertex to which it is directly connected. Specifically, each neighbor of a vertex in the green set is either in the green set or in the blue set.</p>
<p>So now we have three sets of vertices: the green set (of which we know the length of the shortest path to the starting node), the blue set (of which we know the length of a path to the starting node) and the rest (let&#8217;s call that the white set). So here&#8217;s a question: can we come up with rules for moving vertices from one set to another (preferably to the green set)?</p>
<p>Well, adding a node to the blue set is easy: pick a node from the green set. All of its neighbors can be added to the blue set.</p>
<p>But what about the green set? How do we pick a node from the blue set to add to the green set? That&#8217;s not so easy, because before we can move a vertex from the blue to the green set we must be able to guarantee that we know the length of the shortest path to the starting vertex. And we don&#8217;t.</p>
<p>The problem is that we don&#8217;t know enough about the blue set. We&#8217;ve been rather lax in how we&#8217;ve added vertices to the blue set — so far we&#8217;ve said that a vertex being in the blue set means it&#8217;s connected to a green vertex and that we know the length of a path from that node to the starting vertex. But we need more. And if we&#8217;re careful, we can actually know more: we can know the shortest path from the starting vertex to each blue vertex <em>that we&#8217;ve seen so far</em>.</p>
<p>For each green vertex, we know the shortest path from the starting vertex. Say that we&#8217;ve just determined the shortest path for a vertex <em>V</em> and have added it to the green set. Now let&#8217;s examine all the neighbors of <em>V</em> that are not in the green set. There are two possibilities for each neighbor <em>Z</em>:</p>
<ul>
<li><em>Z</em> is in the white set. Then we can add <em>Z</em> to the blue set. The path <strong>P</strong>(starting vertext, <em>V)++</em><strong>P<sub>s</sub></strong>(<em>V</em>,<em>Z</em>) is the shortest path to <em>Z</em> we&#8217;ve seen so far.</li>
<li><em>Z</em> is in the blue set. Then there are two possibilities:</li>
<li>
<ul>
<li>The path <strong>P</strong>(starting vertext, <em>V)++</em><strong>P<sub>s</sub></strong>(<em>V</em>,<em>Z</em>) is shorter than the shortest path to <em>Z</em> we&#8217;ve seen so far. Then we&#8217;ve found a new shortest-path-so-far to <em>Z</em>.</li>
<li>The path <strong>P</strong>(starting vertext, <em>V)++</em><strong>P<sub>s</sub></strong>(<em>V</em>,<em>Z</em>) is not shorter than the shortest path to <em>Z</em> we&#8217;ve seen so far. Then we stick with the path we already had found.</li>
</ul>
</li>
</ul>
<p>If we use this process consistenly when adding vertices to the blue set, then we will always have a shortest-path-so-far associated with each blue vertex. And now we have a full solution in reach:</p>
<ul style="MARGIN-RIGHT: 0px">
<li><strong>Theorem Th1: The blue vertex with the shortest shortest-path-so-far can be moved to the green set.<br /></strong>After we&#8217;ve added a vertex to the green set and recalculated all the shortest-paths-so-far for the blue set, at least one of the blue vertices will be associated with the shortest of all the shortest-paths-so-far. That path to that vertext (say <em>Z</em>) is the shortest path from the starting vertex to <em>Z</em>. In this path <em>Z</em> is directly connected to green node <em>V</em>.
<p>Proof:</li>
<li>
<ul>
<li>The path <strong>P</strong>(starting vertext, <em>V</em>)++P<sub>s</sub>(<em>V</em>,<em>Z</em>) is the shortest path from the starting node over all-green vertices and then directly to <em>Z</em>. We know this because we have examined all such paths while constructing the blue and green sets.</li>
<li>There is no shorter path to <em>Z</em> over green and blue vertices. We know this because the path to <em>Z</em> we have now found is the shortest shortest-path-so-far and adding more edges will only result in a longer path (due to theorem Th.0).</li>
<li>There is no shorter path to <em>Z</em> over white vertices either. Any path to <em>Z</em> over white vertices, by construction, must consist of a shotest-path-so-far to some blue vertex, plus a path over some white vertices. Theorem Th.0 tells us such a path must be longer than the shortest-path-so-far we have found to <em>Z</em>.</li>
</ul>
</li>
</ul>
<p>So now we have all the parts we have to come up with a working shortest path algorithm:</p>
<blockquote>
<p>{* VG is the set of vertices, START is the starting vertex, END is the end vertex *}<br />
<u>set</u> G := {START}, B := {}, W := VG \ {START};<br />
<u>node</u> working := START;<br />
START.length := 0;<br />
START.prev := -;</p>
<p><u>while</u> <u>not</u> END <em><u>in</u></em> G &#8211;&gt;</p>
<blockquote>
<p><u>for</u> <u>node</u> n in neighbors(working) <u>and</u> n <u>not</u> <em><u>in</u></em> G &#8211;&gt;</p>
<blockquote>
<p>if n <em><u>in</u></em> W &#8211;&gt;</p>
<blockquote>
<p>n.length := working.length + weight(working, n);<br />
n.prev := working;<br />
B, W := B <u><em>union</em></u> {n}, W \ {n}</p>
</blockquote>
<p>[] n <em><u>in</u></em> B <u>and</u> working.length + weight(working, n) &lt; n.length &#8211;&gt;</p>
<blockquote>
<p>n.length := working.length + weight(working, n);<br />
n.prev := working;</p>
</blockquote>
<p><u>fi</u></p>
</blockquote>
<p><u>rof</u>;<br />
<u>let</u> <u>node</u> m = &#8220;the node with the minimum length in B&#8221;;<br />
G, B := G <u><em>union</em></u> {m}, B \ {m}</p>
</blockquote>
<p><u>elihw</u></p>
</blockquote>
<p>Note that in this implementation we save a &#8220;back reference&#8221; for each node as it is added to the blue/green set. This allows us to store the shortest paths and know the path as well as the length once the entire algorithm is done. The following animation demonstrates the process visually for our example graph for one possible weighting function:</p>
<p align="center"><img height="201" alt="ShortestPathAlgorithm" src="http://www.gridshore.nl/wp-content/uploads/shortestpathalgorithm.gif" width="307" /></p>
<h3>Some notes on the weighting function</h3>
<p>I mentioned earlier that it is important that no negative weights be used in the Shortest Path Algorithm. The reason for that can be seen in the reasoning for moving a node from the blue to the green set. If we are to assume that a path over the white nodes cannot be shorter than the shortest-path-so-far, we must really know that a path extended with an edge cannot be shorter than the path without that edge. If we allow negative weights, we can no longer rely on this. Consider the following graph for instance — the shortest path algorithm will not find the shortest path in this case.</p>
<p align="center"><img height="201" alt="Counterexample" src="http://www.gridshore.nl/wp-content/uploads/counterexample-1.png" width="301" /></p>
<h3>Summary</h3>
<p>This article has presented a derivation of Dijkstra&#8217;s shortest path algorithm, in the constructionist style of Edsger Dijkstra. It has done so as a birthday salute to the algorithm and the man who invented it.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F04%2F20%2Fdutch-direct-celebrating-the-50th-anniversary-of-dijkstras-shortest-path-algorithm%2F&amp;title=Dutch%20Direct%3A%20Celebrating%20the%2050th%20anniversary%20of%20Dijkstra%27s%20Shortest%20Path%20algorithm&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/04/20/dutch-direct-celebrating-the-50th-anniversary-of-dijkstras-shortest-path-algorithm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

