<?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/"
	>

<channel>
	<title>For.example</title>
	<atom:link href="http://www.iam.unibe.ch/~akuhn/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.iam.unibe.ch/~akuhn/blog</link>
	<description>Random notes on software, programming and languages.</description>
	<pubDate>Tue, 08 May 2012 02:10:00 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>757 Days</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2012/757-days/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2012/757-days/#comments</comments>
		<pubDate>Tue, 08 May 2012 02:10:00 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=616</guid>
		<description><![CDATA[757 days is a long time. Way too long. Expect new content soon.
]]></description>
			<content:encoded><![CDATA[<p>757 days is a long time. Way too long. Expect new content soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2012/757-days/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Software by Night</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/software-by-night/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/software-by-night/#comments</comments>
		<pubDate>Wed, 21 Apr 2010 08:34:49 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=608</guid>
		<description><![CDATA[In this post I&#8217;ll present an idea from unpublished work that uses light effects to visualize dynamic information in Software Cartography. (If you are unfamiliar with spatial-representation of software please refer to &#8220;A Software cartographer&#8217;s Vision&#8221; previously featured on this blog.)

&#8220;Software is not just structural, but behavioral; so the next thing I would like to [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I&#8217;ll present an idea from unpublished work that uses light effects to visualize dynamic information in <a href="http://scg.unibe.ch/codemap">Software Cartography</a>. (If you are unfamiliar with spatial-representation of software please refer to <a href="http://www.iam.unibe.ch/~akuhn/blog/2009/a-software-cartographers-vision">&#8220;A Software cartographer&#8217;s Vision&#8221;</a> previously featured on this blog.)</p>
<blockquote>
<p>&#8220;Software is not just structural, but behavioral; so the next thing I would like to see is traffic and people walking.&#8221; &#8212; <a href="url.needed">Rob Deline</a>, in the question session of <a href="url.needed">Frank Steinbr&uuml;ckner&#8217;s presentation</a> at <a href="url.needed">MSA 2010</a></p>
</blockquote>
<p>Software visualizations typically convey a static view of software systems. Software maps are no different. On a software map all code of a system is shown&#8212;no matter whether it is used at runtime or dead code. This is just the same as with Earth when seen from space: at day you see all land masses but only at night it is revealed where human activity takes place and where not. So my idea is to realize the same for software maps.</p>
<ul>
<li>use static information to group the software artifacts into structural clusters, visualized as land masses. </li>
<li>use dynamic information to embellish the visualization with behavior activity, visualized as sources of lights.</li>
</ul>
<p>Light effects, such as flares and glow, make the execution of software visible. What we actually do is to add more dimensions to a two-dimensional visualization, just as Michele Lanza did with his seminal <a href="http://www.moosetechnology.org/docs/polymetricviews">polymetric views</a>. There seem to be three promising dimensions for light effects</p>
<ul>
<li>brightness of light source,</li>
<li>blurriness of surrounding glow,</li>
<li>intensity of flares that flash up, </li>
</ul>
<p>that are possibly best used in combination to visualize one or two behavioral properties. </p>
<p>When modelling animated visualization the notion of change is essential. <a href="http://benfry.com">Ben Fry</a>&#8217;s work on <a href="http://benfry.com/organic">organic visualization</a> is a good source of inspiration to model time-dependent values, In his work he proposed <em>intergrators</em> as a new numerical data-type with first-class support for continuously changing values (as eg ease-in and ease-out).</p>
<blockquote>
<p>Other than static numericals, integrators continuously change their value over time. Integrator values are in the continuous rather than discrete domain, they grow and decay rather than increment and decrement.</p>
</blockquote>
<p>Fry associates each visual component with a set of set of static and changing values, using the data-types <code>Numerical</code> and <code>Integrator</code>. He describes an integrator as &#8220;a continuously changing value&#8221; and defines the following operations on integrators:</p>
<blockquote>
<ul>
<li><code>set()</code> explicitly set the current value of the Integrator. Normally, this is  only used to set an initial value for the Integrator. </li>
<li><code>impulse()</code> adds a specified amount of force to the Integrator. Equivalent to<br />
  incrementing a Numeric value, but executed in the continuous domain,<br />
  i.e. the amount added attenuates over time. </li>
<li><code>decay()</code> the opposite of an impulse. This is a decrease in the continuous domain. Often used to atrophy values over time. </li>
<li><code>attract()</code> apply a force to move the Integrator towards a particular value. Instead of setting the Integrator to a particular value, a target value is set for the Integrator that it will reach over time. Enables smooth<br />
  transitions if the target is changing. </li>
<li><code>repel()</code> the opposite of attract, moves the value of the Integrator away from a particular numeric value. If the value being avoided is greater, the<br />
  Integrator is decreased further. If less, the Integrator is increased. </li>
<li><code>update()</code> this is used internally to update the Integrator’s current value on each time step, after calculating a new velocity based on the forces<br />
  that have been applied to the Integrator by the rules that affect it. </li>
<li><code>reset()</code> after each the current value is updated, the forces are cleared. New forces are added on each time step by re-applying the rules. </li>
</ul>
</blockquote>
<p>To implement software by night integrators are best used in order to add light effects to the still view of a static software map. Currently we formalized two light dimensions, flare and glow. So when a software artifact is used then it flashes up with a sudden impuls to attract the users attention and then decays in a slowly disappearing glow. Calls are visualized by sparks that jump from call-site to call-site. So users can se where current action is taking place, but also where past action has been taking place and how often it has been doing so. </p>
<p>Please note that &#8220;Software at Night&#8221; is not yet available in the downloadable <a href="http://scg.unibe.ch/codemap">Codemap</a> plug-in. I am working on an external prototype for an upcoming publication, thought. The missing integration in Eclipse is mainly due to the lack of an easy accessible source of dynamic information within Eclipse. </p>
<p>To learn about new Codemap releases, follow <a href="http://twitter.com/codemap">http://twitter.com/codemap</a></p>
<p>Happy Hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/software-by-night/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Exploring the Layout of Software Maps</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/explorin-the-layout-of-software-maps/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/explorin-the-layout-of-software-maps/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 08:46:30 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Software Cartography]]></category>

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=604</guid>
		<description><![CDATA[In this post I will cover my current work on Software Cartography. If you are unfamiliar with spatial-representation of software please refer to “A Software cartographer’s Vision” previously featured on this blog.
→ Codemap is available for download as Eclipse plug-in.
A major issue of software cartography is the base layout of software maps. A good base [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I will cover my current work on <a href="http://scg.unibe.ch/codemap">Software Cartography</a>. If you are unfamiliar with spatial-representation of software please refer to <a href="http://www.iam.unibe.ch/~akuhn/blog/2009/a-software-cartographers-vision">“A Software cartographer’s Vision”</a> previously featured on this blog.</p>
<p>→ <a href="http://scg.unibe.ch/codemap">Codemap is available for download as Eclipse plug-in</a>.</p>
<p>A major issue of software cartography is the base layout of software maps. A good base layout is both stable over time and conveys a meaningful grouping of software artifacts into islands (ie clusters). My initial attempt was to based the layout on vocabulary found in the source code, that is identifier names and comments. Vocabulary has the nice property that it is more stable over time than structure, and that it naturally conveys a meaningful clustering of latent topics.</p>
<p>However a first user study has shown that a vocabulary-based layout does not meet the developers intuition. Even though developers had been well aware that the layout was based on vocabulary, they took conclusions that assumed a structure-based layout. We learnt this from the think-aloud protocol used in the user study.</p>
<p>The user study included six developers that each had 1.5 hours time to explore an unknown software system. They were given six tasks of increasing complexity—cumulating in fixing an actual bug.</p>
<p>I will cover the user study in more details in a future blog post. In this post I shall discuss some proposals for alternative layouts…</p>
<p><center>* * *<center/></p>
<p><em>Package-based layout</em> — is typically the first layout that comes to people’s mind when they hear about software cartography. In fact there is a rich set of previous work that uses packag-based layout. For example, <a href="http://www.inf.usi.ch/phd/wettel/codecity.html">Codecity</a> uses a treemap layout to visualize software systems based in their package structure.</p>
<p>A treemap layout makes good use of screen space, and using packages is likely to convey a meaningful clustering (ignoring for the moment that Java’s package nesting is a mere naming convention and bears no language semantics what so ever.)</p>
<p>However, packaging layouts are not stable in the face of change. They are gap-less and thus major parts of the map have to be moved aside in order to make space for new elements (and vice-versa for disappearing elements). Codecity works around this limitation by offering an after-the-fact analysis mode where the layout of past snapshots anticipates the latest state of the system. However, this is only applicable to post-mortem analysis but not to tools that are embedded in a development environment with live changes.</p>
<p><em>Callgraph-based layout</em> — is the other common layout of software visualization. Static analysis is used to find the call-relations between software artifacts, and then standard force-based graph drawing is applied visualize to the system. Force-based graph drawing adapt well to change, however this is canceled by call-relations having a very high change frequency.</p>
<p>Call-relations are well understood by developers and possibly quite close to developers’s intuitive understanding of distance in software systems. Personally however, I would prefer if the map were based on a more abstract distance measurement.</p>
<p>For example, It would be desirable if call-relations that are displayed on the map had a meaningful interpretation. A long-distance-call should have a diagnostic interpretation. Given a layout based on call-graphs however, a long-distance-call would just indicate failure of the force-based layout to find a solution where all calls have the same length.</p>
<p><em>Law-of-demeter layout</em> — the “Law of Demeter” is a guideline in software design. It states that each method should only talk to its friends, which are defined as its class’s fields, its local variables and its method arguments. Based on this we can defined an <em>idealized</em> call-based distance between software artifacts.</p>
<p>Given a LOD-based layout, software artifacts are close to one another if they are supposed to call one another and far apart if they better oughta not call one another. Thus we get the desired property that visualizing call-graphs conveys meaningful arrow distances. And also, compared to a raw call-graph, a LOD-based graph is less connected and thus better suited for graph drawing.</p>
<p>Best fo all: on a LOD-based map, any long-distance-call has a diagnostic interpretation that helps developers to take actions: long calls possibly violates the “Law of Demeter”!</p>
<p><em>History-driven layout</em> — Claus Lewerentz and Frank Steinbrückner developed a layout for software cities that is based on historical data. They start out with a central plaza and then each new packages branches off as a new street, and each new class is a building along these streets. This generates visually awesome and intuitively stable software maps.</p>
<p>Their work has been (first?) presented at the recent <a href="http://seal.ifi.uzh.ch/msa2010">MSA 2010</a> workshop and will be published soon. I will cover their work in more detail when their publication appears. For the moment please refer to this <a href="http://seal.ifi.uzh.ch/uploads/media/16_frank_steinbrueckner.pdf">slide deck of Frank Steinbrückner’s MSA presentation</a>…</p>
<p><em>Test-dependency-based layout</em> — despite Agile claims, <a href="http://scg.unibe.ch/jexample">unit tests do depend on one another</a>. We can record this dependencies using dynamic instrumentation and profiling, and establish a partial-order of unit tests. Based on that partial-order we can do a radial tree layout of tests and place each software artifact closest to their corresponding tests (kernel method).</p>
<p>Test-dependency-based layout is stable, since changes to test code are typically less frequent than changes to the code under tests. In particular, changes to the dependencies between tests.</p>
<p>Also, a test-dependency-based layout has a clear diagnostic interpretation. Along any radial axis, software artifact on the inside provide services to their clients on the outside. Thus the map’s layout is like a cell, with API interfaces on the outside and a basic kernel at the core.</p>
<p><center>* * *<center/></p>
<p>An important criterion, that has not yet been discussed, is “ease of retrieval” (there might be  proper term in data mining for that). What I mean is availability and accessibility of required data. For example, vocabulary data is always available and easy to access (you don’t even need to parse the source code) while historical data and dynamic instrumentation are often either not available or not easy accessible. So far, I’ve thus only implement vocabulary-based layout (featured in the current download of <a href="http://scg.unibe.ch/codemap">Codemap</a>) and a prototype of law-of-demeter-based layout.</p>
<p>In this post I’ve only scratched the surface of possible map layouts and their design space. For example, Niko Schwarz took inspiration from Richard Dawkins and proposed <a href="http://smalltalkthoughts.blogspot.com/2010/02/distance-measure-between-software.html">code hospitality</a> as a foundation for software maps. Code hospitality is a measure for how likely snippets of one class are to run when copied into another class.</p>
<p>If you’ve got your own crazy ideas, tweet or blog about it!</p>
<p>I’ll collect all pingbacks in a future blog post.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/explorin-the-layout-of-software-maps/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pharo Superpower: Respond to any Message</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-respond-to-any-message/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-respond-to-any-message/#comments</comments>
		<pubDate>Tue, 19 Jan 2010 07:38:58 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Smalltalk]]></category>

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

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=597</guid>
		<description><![CDATA[
For the fifth week in a row we’re stepping into the Pharo superpowers booth. Today we shall learn how to create objects that respond to any message. That is, objects that respond to a message without implementing a corresponding method. Again, as with sending any message, this superpower can be used for the good (if [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin-left:1em;margin-top:-1ex"><a href="http://pharo-project.org/"><img style="border:none;margin:0px" title="Logo of the Pharo Smalltalk programming languages." src="http://www.iam.unibe.ch/~akuhn/blog/wp-content/uploads/2010/01/pharo-logo-200px.png" alt="" width="194" height="194" /></a></div>
<p>For the fifth week in a row we’re stepping into the Pharo <a href="http://www.iam.unibe.ch/~akuhn/blog/category/superpowers/">superpowers</a> booth. Today we shall learn how to create objects that respond to any message. That is, objects that respond to a message without implementing a corresponding method. Again, as with <a href="http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-send-any-messag/">sending any message</a>, this superpower can be used for the good (if used with care) and I will thus discuss an example that I consider good use below.</p>
<p>When a message is sent to a Smalltalk object, the message name is looked up in the method dictionary of the object’s class and its superclasses. If a method whose name matches the message is found, that method is executed. However, if no matching method is found a special message is sent to the object, which is</p>
<pre><code>#doesNotUnderstand:</code></pre>
<p>By default, the implementation of <code>#doesNotUnderstand:</code> opens a debugger (or more precise, the pre-debugger dialog that we all know from test-driven development). However, we are free to override <code>#doesNotUnderstand:</code> and thus respond to any unknown message.</p>
<p>As a (dadaistic) example, let’s implement a Lorem ipsum object</p>
<pre><code>Object subclass: #Lorem instanceVariableNames: 'expects'
</code></pre>
<p>with an <code>ipsum</code> constructor</p>
<pre><code>Lorem class &gt;&gt; ispum
    ^ self new
</code></pre>
<p>and the following two methods</p>
<pre><code>Lorem &gt;&gt; initialize
    expects := #(dolor sit amet "to be continued ad nauseam..." nil)

Lorem &gt;&gt; doesNotUnderstand: aMessage
    ^ aMessage selector == expects first
        ifTrue: [ expects := expects allButFirst. self ]
        ifFalse: [ super doesNotUnderstand: aMessage ]
</code></pre>
<p>So, if you ever doubted that <em>virtually any</em> English sentence is valid Smalltalk, here is your proof :)</p>
<pre><code>Lorem ipsum dolor sit amet.
</code></pre>
<p>This executes as valid Smalltalk code, without ever having implement any <code>#dolor</code> , <code>#sit</code> or <code>#amet</code> method! If however, we deviate from the canonical Lorem ipsum sequence we’ll get the usual <code>MessageNotUnderstood</code> error.</p>
<pre><code>[ Lorem ipsum dolor zork ] should signal: MessageNotUnderstood.
</code></pre>
<p>As a more sensible examples let’s consider a list that responds to any messages understood by all its elements.</p>
<pre><code>OrderedCollection subclass: #Group.

Group &gt;&gt; eachRespondsTo: aSelector
    ^ self allSatisfy: [ :each | each respondsTo: aSelector ]

Group &gt;&gt; doesNotUnderstand: aMessage
    ^ (self eachRespondsTo: aMessage selector)
        ifTrue: [ self collect: [ :each | aMessage sendTo: each ] ]
        ifFalse: [ super doesNotUnderstand: aMessage ]
</code></pre>
<p>As you can see, the implementation of <code>#doesNotUnderstand:</code> follows the same pattern as above. We check whether we want to handle the message, and if not, we delegate to the default implementation in object (which will open a pre-debugger dialog).</p>
<p>Keen readers might have already noted a limitation of above approach: when you override <code>#doesNotUnderstand:</code> but not <code>#respondsTo:</code> your object will respond to a new message (through the means of <code>#doesNotUnderstand:</code>) but still insists that it does not respond to that message when queried with <code>#respondsTo:</code>.</p>
<p>So we’ll have to override <code>#respondsTo:</code> as well</p>
<pre><code>Group &gt;&gt; respondsTo: aSelector
    ^ (super respondsTo: aSelector) or: [ self eachRespondsTo: aSelector ]
</code></pre>
<p>It is a sad but true fact, that over 90% of all <code>#doesNotUnderstand:</code> overriders that you’ll find out there do not override <code>#respondsTo:</code> as well—even though they should!</p>
<p>So now our new class is ready for a bunch of expectations (please refer to <a href="http://www.squeaksource.com/phexample.html">Phexample</a> for more details on expectation matchers)</p>
<pre><code>g := Group new.
g should not respondTo: #x.
[ g x ] should raise: MessageNotUnderstood.
g add: 2 @ 3.
g add: 3 @ 4.
g add: 1 @ 2.
g should respondTo: #x.
g x should beSameSequence: #(2 3 1).
g y should beSameSequence: #(3 4 2).
</code></pre>
<p>BTW, <em>if you are an OSX user and looking for a language that provides this feature by default, take a look at <a href="http://www.fscript.org">F-Script</a> by Philippe Mougin. F-Script also offers a plethora of awesome features beyond projection of messages, for example it allows you to manipulate the Cocoa objects of any OSX application—at runtime!</em></p>
<p>As a best practice, you should only override <code>#doesNotUnderstand:</code> and <code>#respondsTo:</code> on your own classes. Just imagine what might happen when two or more stakeholders attempt to override <code>#doesNotUnderstand:</code> in, for example, <code>Collection</code>, only one of the extensions will eventually remain and thus leave the system in an undefined state with overloaded extensions.</p>
<p>If you know more good (or evil, <em>uoarharhar</em>) uses of <code>#doesNotUnderstand:</code> share them in the comments.</p>
<p>Hackety hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-respond-to-any-message/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pharo Superpower: Send Any Message</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-send-any-messag/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-send-any-messag/#comments</comments>
		<pubDate>Tue, 12 Jan 2010 10:20:55 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Smalltalk]]></category>

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

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=579</guid>
		<description><![CDATA[
In Pharo Smalltalk you may send any message even if it&#8217;s name is not known at compile time. Sending any message is one of the superpowers that can be used for the good, even when doing application programming, therefore I will discuss best practices in the end.
First of all, recall that &#8220;sending a message&#8221; is [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin-left:1em;margin-top:-1ex"><a href="http://pharo-project.org/"><img style="border:none;margin:0px" src="http://www.iam.unibe.ch/~akuhn/blog/wp-content/uploads/2010/01/pharo-logo-200px.png" title="Logo of the Pharo Smalltalk programming languages." width="194" height="194" /></a></div>
<p>In <a href="http://pharo-project.org/">Pharo Smalltalk</a> you may send any message even if it&#8217;s name is not known at compile time. Sending any message is one of the superpowers that can be used for the good, even when doing application programming, therefore I will discuss best practices in the end.</p>
<p>First of all, recall that &#8220;sending a message&#8221; is Smalltalk jargon for calling a method. Since sending a message is synchronous in Smalltalk, <em>ie</em> it blocks until the receiver returns, it is basically the same as a method call and the actual difference thus of philosophical nature only. (There is an implementation difference deep down at the language&#8217;s core, but that shall not be discussed today as it does not matter to programmers.)</p>
<p>BTW, <em>this is the fourth post in the <a href="http://www.iam.unibe.ch/~akuhn/blog/category/superpowers/">Superpower</a> series.</em></p>
<p>There are many ways to send any message, mainly due to optional and variable arguments which are not well supported by Smalltalk syntax. The most basic form is </p>
<pre><code>object perform: #symbol withArguments: anArray
</code></pre>
<p>Let&#8217;s consider a real example</p>
<pre><code>string = 'Lorem'.
string perform: #size. "=&gt; 5"
string perform: #at: with: 1. "=&gt; $L"
string perform: #copyFrom:to: with: 2 with: 4. "=&gt; 'ore'"
</code></pre>
<p>If the number of arguments is not known at compile time, we may use</p>
<pre><code>string perform: aSymbol withArguments: anArray.
string perform: aSymbol withEnoughArguments: anArray.
</code></pre>
<p>the first expects that the array matches the arity (number of arguments) of the target method, the latter will just use as many arguments are required. This is most useful to send a message with optional arguments.</p>
<p>So when is sending any message for the good or for the evil?</p>
<p>Whenever possible, try to avoid using <code>#perform:</code> because it is less readable. When a reader of your program looks at the a <code>#perform:</code> it is not obvious which message is being sent at runtime. Also, messages that are sent with <code>#perform:</code> will not be shown when browsing all senders of a message. There is one subtle difference here: If the dynamically sent message is stored somewhere as symbols, at least that symbols will show up when looking for senders. If however, the dynamically sent message is composed using string concatenation, it wont show up at all. It might even seem as if its implementers are never used, which can be very confusing to the reader.</p>
<p>For all above reasons you should only use <code>#perform:</code> when you have good reason to do so. And <em>if</em> you use it, make sure that the dynamically sent messages are all stored as a symbol somewhere else. Best of all, make sure that <em>all</em> code involved into dynamically sending message is encapsulated by one single class.</p>
<p>I will provide an example from <a href="http://scg.unibe.ch/staff/adriankuhn/hapax">Hapax</a>&#8217;s clustering algorithm. When you do hierarchical clustering, there are different ways to link small clusters into large clusters. The call to this linkage method is buried deep down in the internals of the clustering algorithm, so the <code>ClusteringEngine</code> class uses a strategy pattern to pick the right linkage method. The choice of strategy is stored as a symbol in an instance variable and then used as follows </p>
<pre><code>Object subclass: #ClusteringEngine
    instanceVariableNames: 'distanceMatrix dendrogram linkage'
    classVariableNames: ''

ClusteringEngine &gt;&gt; linkage: aSelector
    linkage := aSelector

ClusteringEngine &gt;&gt; linkage
    ^ linkage

ClusteringEngine &gt;&gt; allLinkageSelectors
    ^ #( averageLinkage centroid completeLinkage meanLinkage singleLinkeage wardsMethod )

ClusteringEngine &gt;&gt; run
    (distanceMatrix size - 1) timesRepeat:
        [self findMinimum.
        self perform: linkage].

ClusteringEngine &gt;&gt; averageLinkage
    "implementation omitted..."

"et cetera..."
</code></pre>
<p>All code is encapsulated with one class such that a reader can find it all in one place when browsing the source code.</p>
<p>Any other use of <code>#perform:</code>, in particular when string concatenation of selectors is involved, is evil and <a href="http://www.iam.unibe.ch/~akuhn/blog/2009/superpowers-in-library-design/">should be limited to library design</a>, if used at all.</p>
<p>A note regarding performance. Using <code>#perform:</code> is as fast as sending a message the normal way. So contrary to popular believe there is not performance penalty&mdash;at least not in Pharo Smalltalk, in other dialects that do use JIT compilation there might be severe performance penalties though).</p>
<p>Hackety hacking!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-send-any-messag/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Imagine, IDE search so faaaaast that&#8230;</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/imagine-ide-search-so-faaaaast-that/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/imagine-ide-search-so-faaaaast-that/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 23:33:36 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[SUITE]]></category>

		<category><![CDATA[SUITE 2010]]></category>

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

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=545</guid>
		<description><![CDATA[Imagine an IDE where search were so fast that it became the sole means of navigation.
In such a system, one would not write //TODO but just this.todo() since browsing the callers of todo is so fast that is it faster than using a dedicated task view. The system might even be hidden to your Yahoogle [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine an IDE where search were so fast that it became the sole means of navigation.</p>
<p>In such a system, one would not write <code>//TODO</code> but just <code>this.todo()</code> since browsing the callers of <code>todo</code> is so fast that is it faster than using a dedicated task view. The system might even be hidden to your Yahoogle query for &#8220;fast search in IDE&#8221; since in such a system search is so fast and ease-to-use that its ceases to be used as a verb. For example, the devs might speak of “browse callers” rather than “search callers” since no intermediate search step is between them and their need.</p>
<p>I can see some of my readers smile now :) …because…</p>
<p>There is such a system. It is little known since it predates the invention of today’s filesystems and has never made the transition to file based software development itself. It is <a href="http://www.pharobyexample.org/">Smalltalk</a>, the old lady of dynamic programming languages.</p>
<p>In the IDE of Smalltalk “browse callers of” and “browse implements of” are the main means of navigation. Executing these actions opens&ndash;in the same instant&ndash;a new editor window with all callers (or implementers) of a given method. No spinning wheel, no tree list of search results, no browsing of results even, you are right there and can start editing.</p>
<p>NB: <em>in fact, seasoned Smalltalk devs even omit “browse” and just say “senders’of” (in message-oriented languages such as Smalltalk and Ruby, objects don’t call methods but send each other messages) and “implementers’of” instead of a proper verbs.</em></p>
<p>For the alert reader: yes, graphical UIs predate hierarchical file systems. And even better, Smalltalk invented graphical windows. But we’ll stop the children’s games here. It does not matter who was first, but who makes the best out of it. And there, the winner is obvious.</p>
<p>The point I want to make is rather that there is a system out there with a 30-year head start in IDE search. So as researchers we can go and learn from the experience of that community, and then used what we learned to advance the state of current IDEs beyond it. Breakpoints, for example, are also just another method call in Smalltalk. You insert a call to <code>#halt()</code> where ever you want, and to view the list of current break points you browse all callers of halt. Again, no need for a dedicated view. As you see, search-driven development simplifies your tool set.</p>
<p>Of course, not all your navigation needs can be satisfied by hyperjumping. Sometimes you need to drill down from top-levels packages to methods. To do so Eclipse offers the code browsing perspective, which is however never used because the package explorer view offers the same drill-down capabilities without change of perspective. In Smalltalk we get a code browsing interface as well. In fact, Eclipse inherited that perspective from its predecessor VisualAge which was IBM’s prime Smalltalk IDE before they switched to Java.</p>
<p>So before I start to tell the story of how Eclipse’s elimination of the compilation step was inherited from VisualAge as well, lemme summarize this post.</p>
<ul>
<li>Search so fast that is disappears from the list of “verbs” in your IDE.</li>
<li>Search so fast that it is called “browse code” instead.</li>
<li>Search so fast that developers, for example, us method calls as <code>TODO</code> markers.</li>
<li>Plus a drill-down interface for the remaining navigation needs that are not covered by hyperjumping.</li>
</ul>
<p>The comparison with compilation is actually quite nice: With Eclipse “compile” and “build” ceased to be used as verbs in Java development. Now devs just execute code, done. This feature was brought to Java from Smalltalk. It would be awesome if we could achieve the same kind of “knowledge transfer” for IDE search. </p>
<p>I&#8217;d say that our job as providers of IDE search is only done when search ceases to be used as a verb in software development.</p>
<p>&mdash; that said, <a href="http://scg.unibe.ch/wiki/events/suite2010">paper submission for SUITE</a> is open until January 19, 2010.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/imagine-ide-search-so-faaaaast-that/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sneak Peak: Codemap User Study</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/sneak-peak-codemap-user-study/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/sneak-peak-codemap-user-study/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 16:49:01 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Research]]></category>

		<category><![CDATA[Software Cartography]]></category>

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=528</guid>
		<description><![CDATA[Here is a preview of a recently submitted paper on Software Cartography. We report on preliminary results of an ongoing user study with both students and professional developers. Results are mixed and revised the assumption that lexical similarity is sufficient to layout the map. We are now working on a new distance metric that includes [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a preview of a recently submitted paper on <a href="http://scg.unibe.ch/codemap">Software Cartography</a>. We report on preliminary results of an ongoing user study with both students and professional developers. Results are mixed and revised the assumption that lexical similarity is sufficient to layout the map. We are now working on a new distance metric that includes the ideal structural proximity proposed by the &#8220;Law of Demeter&#8221;. Also we are looking into new layout algorithms. For example, <i>anchored</i> MDS would allow developers to rearrange the map according to their system&#8217;s architecture.</p>
<p><strong>NB</strong> <em>if you are a professional developer from Switzerland, we encourage you to participate in our user study. Please contact <a href="http://twitter.com/deiferni">David</a> or <a href="http://scg.unibe.ch/akuhn">me</a> for more information.</em></p>
<p><img src="http://www.iam.unibe.ch/~akuhn/blog/wp-content/uploads/2010/01/towards-an-improved-mental-model-of-software-developers-through-cartographic-visualization-icse-nier-2010.png" alt="towards-an-improved-mental-model-of-software-developers-through-cartographic-visualization-icse-nier-2010" title="towards-an-improved-mental-model-of-software-developers-through-cartographic-visualization-icse-nier-2010" width="817" height="300" class="alignnone size-full wp-image-529" /></p>
<p>The preview was created with <a href="http://wordle.org">Wordle</a>, an idea that I owe to <a href="http://thomas-zimmermann.com/">Tom Zimmermann</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/sneak-peak-codemap-user-study/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pharo Superpower: Change of Class</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-change-of-class/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-change-of-class/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 13:49:54 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Smalltalk]]></category>

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

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=482</guid>
		<description><![CDATA[
Smalltalk objects are ordered by classes hierarchies. But still, an object may change its class membership! Objects are able to move between classes and hierarchies at runtime.
In this post I shall show how to transform a rabbit into a light house!
First let us create two classes Rabbit and Lighthouse with the same format. We use [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;margin-left:1em;margin-top:-1ex"><a href="http://pharo-project.org/"><img style="border:none;margin:0px" src="http://www.iam.unibe.ch/~akuhn/blog/wp-content/uploads/2010/01/pharo-logo-200px.png" title="Logo of the Pharo Smalltalk programming languages." width="194" height="194" /></a></div>
<p>Smalltalk objects are ordered by classes hierarchies. But still, an object may change its class membership! Objects are able to move between classes and hierarchies at runtime.</p>
<p>In this post I shall show how to transform a rabbit into a light house!</p>
<p>First let us create two classes <code>Rabbit</code> and <code>Lighthouse</code> with the same format. We use Pharo’s public API to do so.</p>
<pre><code>Object subclass: #Rabbit instanceVariableNames: 'age size'.
Object subclass: #Lighthouse instanceVariableNames: 'latitude longitude'.
</code></pre>
<p>Lets check that both classes are of the same format, but neither is a subclass of the other. (Please refer to <a href="http://www.squeaksource.com/phexample.html">Phexample</a> for more information on expectation matchers.)</p>
<pre><code>Rabbit format should = Lighthouse format.
Rabbit should not beKindOf: Lighthouse.
Lighthouse should not beKindOf: Rabbit.
</code></pre>
<p>Now, lets create a rabbit and transform it into an instance of a light house.</p>
<pre><code>r := Rabbit new.
r class should beKindOf: Rabbit.
r primitiveChangeClassTo: Lighthouse new.
r class should beKindOf: Lighthouse.
</code></pre>
<p>And, <em>abra cadabra</em>, we&#8217;ve turned <code>r</code> from a <code>Rabbit</code> into a <code>Lighthouse</code>!</p>
<p>To do so we use the <code>#primitiveChangeClassTo:</code> method. This method expects an instance of the target class as argument. However this instance is only used to determine the target class of the receiver. (In other Smalltalk dialects, as for example <a href="http://www.cincomsmalltalk.com/">Cincom Smalltalk</a>, <code>#changeClassTo:</code> expects a class rather than an instance. We can only guess why Pharo and its sibling <a href="http://www.squeak.org/">Squeak</a> require an instance of the target class. My guess is that this required as proof that the target class is a valid class, since otherwise it would not have been possible to create an instance of itself.)</p>
<p>Hackety hacking!</p>
<p>Post scriptum: <em>please note that it is not possible to change the class of a point to that of an associations even though both got two instance variables. This is because both are so called “compact” classes with a smaller header. We’ll cover that in another superpowers issue.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/pharo-superpower-change-of-class/feed/</wfw:commentRss>
		</item>
		<item>
		<title>How-to Revert Safari to Version 4.0.2 and Thus Fix Inquisitor</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2010/how-to-revert-safari-to-version-4-0-2-and-thus-fix-inquisitor/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2010/how-to-revert-safari-to-version-4-0-2-and-thus-fix-inquisitor/#comments</comments>
		<pubDate>Tue, 05 Jan 2010 07:31:49 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=474</guid>
		<description><![CDATA[Recent versions of Safari don&#8217;t play nice with the Inquisitor search plugin. The only sensible fix seems to revert Safari to an older version.
Inquisitor is supposed to plug into Safari&#8217;s search bar to display a list of search engines instead of Google suggestions. However, after installing Safari 4.0.3 (or higher) that won&#8217;t work anymore. Google [...]]]></description>
			<content:encoded><![CDATA[<p>Recent versions of Safari don&#8217;t play nice with the <a href="http://www.inquisitorx.com/safari/">Inquisitor</a> search plugin. The only sensible fix seems to revert Safari to an older version.</p>
<p>Inquisitor is supposed to plug into Safari&#8217;s search bar to display a list of search engines instead of Google suggestions. However, after installing Safari 4.0.3 (or higher) that won&#8217;t work anymore. Google suggestion are being displayed on top of the Inquisitor drop-down! </p>
<p>Here is how to revert Safari back to version 4.0.2 once you&#8217;ve installed the latest version by mistake:</p>
<ol>
<li>Get a copy of the Safari 4.0.2 installer. This ain&#8217;t as simple as it sounds. Apple&#8217;s website offers the latest version only, and all usual download sites refer to Apple&#8217;s website only. You have to search the interwebs for a file called <code>Safari4.0.2Leo.dmg</code>. I was lucky enough to find a copy on an anonymous website, but Rapidshare or friends should do fine as well.</li>
<li>Once you got the file, you should double check it&#8217;s SHA-1 digest against the one given in the Apple security announcement <a href="http://lists.apple.com/archives/security-announce/2009/jul/msg00000.html">APPLE-SA-2009-07-08-1</a>. Execute <code>openssl sha1 Safari4.0.2Leo.dmg</code> an the command line and compare the output to
<pre><code>SHA1(Safari4.0.2Leo.dmg)= 48676afbb5c5bacac8610ba13f6851d3b266cb69</code></pre>
<p>If your output is not the same, the file has been tampered and you should <em>not</em> install it!</li>
<li>Next you&#8217;ll have to patch the version number of Safari&#8217;s current installation. Otherwise the installer will refuse to revert Safari. To do so open the files
<pre><code>/System/Library/Frameworks/WebKit.framework/Versions/A/Resources/Info.plist
/Applications/Safari.app/Contents/version.plist</code></pre>
<p>and replace the version numbers with lower numbers. Anything lower than <code>5530.19</code> should do fine. You might have to change access rights to be able to edit these files.</li>
<li>Now, you may eventually run the Safari 4.0.2 installer!</li>
</ol>
<p>&nbsp;</p>
<p>PS: <em>As an Inquisitor user you might also be interested in turning off Inquisitor&#8217;s  Yahoo suggestions. Being tracked by Yahoo instead of Google is &#8220;vom Regen in die Traufe geraten&#8221; as we&#8217;d say in German. To cover up your traces, open <code>/etc/hosts</code> and add the following lines</em></p>
<pre><code>0.0.0.0 sugg.search.yahoo.net
0.0.0.0 clients1.google.com
</code></pre>
<p><em>this blocks the URL that are used to retrieve both Google and Yahoo suggestions.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2010/how-to-revert-safari-to-version-4-0-2-and-thus-fix-inquisitor/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Dependency Injection vs. Virtual Classes</title>
		<link>http://www.iam.unibe.ch/~akuhn/blog/2009/dependency-injection-vs-virtual-classes/</link>
		<comments>http://www.iam.unibe.ch/~akuhn/blog/2009/dependency-injection-vs-virtual-classes/#comments</comments>
		<pubDate>Wed, 30 Dec 2009 17:45:43 +0000</pubDate>
		<dc:creator>akuhn</dc:creator>
		
		<category><![CDATA[Java]]></category>

		<category><![CDATA[Programming Languages]]></category>

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

		<guid isPermaLink="false">http://www.iam.unibe.ch/~akuhn/blog/?p=459</guid>
		<description><![CDATA[Every time you create an instance of a class by using the new keyword, you tightly couple your code to that class, and you will not be able to substitute that particularly implementation with a different one (at least not without recompiling the code).
Taken from an answer on stackoverflow that motivates dependency injection. Dependency injection [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Every time you create an instance of a class by using the <code>new</code> keyword, you tightly couple your code to that class, and you will not be able to substitute that particularly implementation with a different one (at least not without recompiling the code).</p></blockquote>
<p>Taken from <a href="http://stackoverflow.com/questions/1980182/what-are-dependency-injection-spring-framework-about/1980243#1980243">an answer on stackoverflow</a> that motivates dependency injection. Dependency injection however is not the real solution, it is rather a workaround for missing <em>virtual classes</em>. In this post I will show you why.</p>
<p>For example in</p>
<pre><code>public class MyClass {
  public string sendMessage(String contents) {
    return new MailService().sendMessage(contents);
  }
}
</code></pre>
<p>you cannot use a different MessageService. This might not seem limiting at first sight, but think for example of testing. Your tests might be better off using a stub service that does not send actual emails.</p>
<p>This can and is being solved with dependency injection, yes. But the actual problem is rather a language problem: Classes are not virtual. While methods are virtual and thus looked up at runtime, classes are not.</p>
<p>In the following example, we can change the mail service by subclassing and overriding a method. This works because methods are virtual and thus late bound.</p>
<pre><code>public class MyClass {
  public string sendMessage(String contents) {
    return newMailService().sendMessage(contents);
  }
  public MailService newMailService() {
    return new MailService();
  }
}
</code></pre>
<p>What a difference a single whitespace can make!</p>
<p>When <code>newMailService</code> is called, that method name is looked up in the context of the calling method. The context of the calling method is its class. Therefore, by subclassing the containing class we can provide a different mail service.</p>
<p>Imagine the same would happen with class names. Whenever we call <code>new MailService()</code> then the class name would be looked up in the containing context. Imagine further the lookup would not stop with the class but bubble up to the containing package. Then, by “subclassing” that package we might provide a different mail service.</p>
<p>Subclassing a package is nonsense terminology, let’s rather say that we instantiate a package … and let’s further assume that packages and classes are the same, and that our system is built of nested classes.</p>
<pre><code>public class MyApplication {
  public class MyClass {
    public string sendMessage(String contents) {
      return new "MailService"().sendMessage(contents);
    }
  }
}
</code></pre>
<p>I have put the class name of <code>MailService</code> in quotes to remind you that it is the name of a virtual class name and thus looked up in the containing context.</p>
<p>Imagine further that we could pass the binding of classes to a class when creating it, then we could instantiate two versions of our application: one for real, and one for testing.</p>
<pre><code>Application forTesting = new Application(MailService = TestMailer);
Application forReal = new Application(MailService = InterwebMailer);
</code></pre>
<p>Testing and production are not the only possible contexts. Imagine for example an XML parser. Typically it creates DOM nodes, but maybe you would prefer you own implementation of nodes. Maybe even the DAO objects of your application? There we go</p>
<pre><code>XMLParser custom = new XMLParser(Node = Application.DAO);
XMLDocument doc = custom.new XMLDocument("example.xml");
</code></pre>
<p><small>
<p>NB, the second line is actually valid Java syntax: this is how you create an instance of an inner class when you are not in the same file as its outer class.</p>
<p></small></p>
<p>— So this is how dependency injection should <em>really</em> work!</p>
<p>And it is even not that far from reality. Both <a href="http://www.daimi.au.dk/~beta/">Beta</a> and <a href="http://newspeaklanguage.org/">Newspeak</a> (the new language by <a href="http://gbracha.blogspot.com/">Gilad Bracha</a>) do have virtual classes and both do have nested classes, and in both classes what I just described is how you decouple your packages in these languages.</p>
<p>And, <em>hup hup hup</em>, another design pattern has been disguised as a missing language feature :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.iam.unibe.ch/~akuhn/blog/2009/dependency-injection-vs-virtual-classes/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.692 seconds -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-23 13:13:42 -->
