<?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>Late Bound</title>
	<atom:link href="http://www.haltingproblem.net/weblog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haltingproblem.net/weblog</link>
	<description>Personal weblog of Roland Sadowski</description>
	<lastBuildDate>Mon, 24 May 2010 12:37:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Channels (almost like in Newsqueak) but in C#. Again.</title>
		<link>http://www.haltingproblem.net/weblog/2010/05/24/channels-almost-like-in-newsqueak-but-in-c-again/</link>
		<comments>http://www.haltingproblem.net/weblog/2010/05/24/channels-almost-like-in-newsqueak-but-in-c-again/#comments</comments>
		<pubDate>Mon, 24 May 2010 12:37:14 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Message]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[concurrency]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/?p=105</guid>
		<description><![CDATA[Updating old code. Learning new things about .NET 4

Years ago I saw a really good presentation by Rob Pike about a
little known language called Newsqueak. I can&#8217;t remember if I had
anything more than a mild interest in concurrent programming, but that
talk got my attention. I read all I could find about concurrency in
Newsqueak. Fun ideas [...]]]></description>
			<content:encoded><![CDATA[<h3>Updating old code. Learning new things about .NET 4</h3>

<p>Years ago I saw a really good <a href="http://video.google.pl/videoplay?docid=810232012617965344">presentation by Rob Pike</a> about a
little known language called Newsqueak. I can&#8217;t remember if I had
anything more than a mild interest in concurrent programming, but that
talk got my attention. I read all I could find about concurrency in
Newsqueak. Fun ideas are fun to play with.</p>

<p>I wrote a <a href="http://www.haltingproblem.net/programming/newsqueakcsharp_en">short article</a> about <code>channels</code>, which are
Newsqueak&#8217;s construct for synchronization between threads. I tried to
emulate behavior of channels in C# via locking and signaling. I was
aware that there probably is no 1:1 mapping between what Newsqueak
calls processes and managed threads in .NET (though I&#8217;m not sure to this
day how many processes could Newsqueak spawn before bringing machine
to a halt) but the exercise was fun enough to do it anyway.</p>

<p>Now, this was long enough ago, that C# didn&#8217;t have syntax for lambdas
and was missing all the concurrency goodness that .NET 4 brings. I
decided to update the code, expecting it to be a 5 minute
operation. It took a bit longer.</p>

<p><a href="/files/newsqueakcsharp.zip">Code</a> to be upgraded consisted of 2 projects: a <code>Channel&lt;t&gt;</code>
class and a nice example adapted from the presentation mentioned
above. Implementation of channel didn&#8217;t need any changes, but the
example (an interesting take on Eratosthenes prime sieve) was spawning
<code>System.Threading.Thread</code>s. Replacing occurrences of</p>

<pre><code>new Thread(foo).Start();
</code></pre>

<p>with</p>

<pre><code>Task.Factory.StartNew(foo);
</code></pre>

<p>resulted in this:</p>

<p><img src="http://late-bound.s3.amazonaws.com/chanlib_contentions.png" class="s3-img" border="0" alt="Contentions graph. Summary: lots of synchronization. Bad." /> </p>

<p>The Y axis on the graph is the number of contentions. In other words,
the program spend 94% of its time on synchronization. A disaster.</p>

<p>Fixing this took me a couple of minutes but it is not obvious. The
prime sieve works by starting new <code>Task</code> for filtering out multiplies
of a certain number. The filters are chained together and every
integer which comes out at the end, has to go through all of
them. Newly discovered primes cause a new filter to be added; making
sure multiplies of this new prime get rejected from now on. </p>

<p>New filters are chugging along, each in a new <code>Task</code> created via a
factory as shown above. So why all the contention?</p>

<p>Tasks are scheduled on the thread pool and apparently the default
hints passed to the scheduler are not enough. We can fix that by
being more explicit about the nature of our task:</p>

<pre><code>  Task.Factory.StartNew(Filter, arg, TaskCreationOptions.LongRunning);
</code></pre>

<p>our filters are kept alive as long as the program is
running, therefore the <code>TaskCreationOptions.LongRunning</code>. </p>

<p>While entertaining, the prime sieve is obviously abusing Tasks and
managed threads; cost of synchronization is greater than the cost of
the computation performed in each thread. But finding out the
differences between <code>System.Threading.Thread</code> and
<code>System.Threading.Tasks.Task</code>, the new recommended method of spawning
new threads from .NET 4.0, may come in handy. Especially if one
decides to make some changes in older code.</p>

<p>I pushed the revised version on github: <a href="http://github.com/rosado/prime-sieve-cs">prime-sieve-cs</a>.</p>

<p><em>Side note: I&#8217;ve been meaning to have a look at Go language, which I
 know expands on themes present in Newsqueak. I finally found some
 time and want to write down some thoughts on Go, Clojure and other
 things.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2010/05/24/channels-almost-like-in-newsqueak-but-in-c-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Three Big Lies</title>
		<link>http://www.haltingproblem.net/weblog/2010/03/20/three-big-lies/</link>
		<comments>http://www.haltingproblem.net/weblog/2010/03/20/three-big-lies/#comments</comments>
		<pubDate>Sat, 20 Mar 2010 10:58:19 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/?p=91</guid>
		<description><![CDATA[A Presentation by Insomniac Games

Mike Acton from Insomniac Games, creators of Ratchet &#38; Clank, gave a talk at this years Game Developer&#8217;s Conference. This  blog post bares the same title as the presentation. 



Though I wish I could hear the talk, the slides (pdf) from the talk available from Insomniac&#8217;s blog seem to capture [...]]]></description>
			<content:encoded><![CDATA[<h3>A Presentation by Insomniac Games</h3>

<p>Mike Acton from Insomniac Games, creators of Ratchet &amp; Clank, gave a talk at this years Game Developer&#8217;s Conference. This  blog post bares the same title as the presentation. </p>

<p><img src="http://late-bound.s3.amazonaws.com/3BigLies_slide.jpg" class="s3-img" border="0" alt="3BigLies_slide.jpg" /></p>

<p>Though I wish I could hear the talk, the slides (pdf) from the talk available from <a href="http://www.insomniacgames.com/research_dev/articles/2010/1522262">Insomniac&#8217;s blog</a> seem to capture the main points well. </p>

<p>Instead of designing your code around the model of the world (presumably with OO), Acton suggests to come up with way to <em>transform</em> the data given the constraints of the platform (hardware). They also equate <em>World Modeling</em> to &#8220;self helf books for programming.&#8221; </p>

<p>Thinking about your program as a series of transforms is the standard mind-set employed people doing functional style programming. Sometimes the language doesn&#8217;t leave you much choice, because everything is immutable. In game programming you have as much mutable state as you can. But according to Mike Acton, thinking in terms of explicit data transforms can bring us a lot of value: in performance and ease of maintenance. </p>

<p>That&#8217;s just a quick summary, see the slides for a more complete debunking of the Three Big lies.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2010/03/20/three-big-lies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>gen-struct: a Clojure macro for generating classes with mutable state</title>
		<link>http://www.haltingproblem.net/weblog/2009/08/03/making-clojure-a-bit-more-mutable/</link>
		<comments>http://www.haltingproblem.net/weblog/2009/08/03/making-clojure-a-bit-more-mutable/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 19:36:38 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/?p=72</guid>
		<description><![CDATA[Sometimes the only way to get the desired performance is to shun
immutability.

In case of Clojure, that means using arrays or importing mutable
classes from an existing Java library - assuming the library already
has classes with properties/fields that fit our needs. Otherwise, we
have to write some Java code.

Dropping to another language for performance is pretty
disappointing. But sometimes [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes the only way to get the desired performance is to shun
immutability.</p>

<p>In case of Clojure, that means using arrays or importing mutable
classes from an existing Java library - assuming the library already
has classes with properties/fields that fit our needs. Otherwise, we
have to write some Java code.</p>

<p>Dropping to another language for performance is pretty
disappointing. But sometimes it&#8217;s the only sane choice. </p>

<p>I&#8217;ve created <a href="http://github.com/rosado/gen-struct/tree/clean">gen-struct</a> library to avoid some of those
situations. This simple macro, which in reality is a modified version
of the gen-class macro created by Rich Hickey, allows you to create
simple, mutable and immutable structures. You can customize only one
aspect of those classes: their fields. Here&#8217;s an example:</p>

<pre><code>(gen-struct
 :name my.test.struct
 :mutable-fields [[float x]
                  [float y]]
 :final-fields [[int timeout]
                [static int MAX_TIMEOUT :is 1000]
                [java.io.File input]])
</code></pre>

<p>gen-struct automatically generates a constructor which lets you
initialize all the final, non-static fields. In the above example,
single constructor accepting an <code>int</code> value and a <code>File</code> object would
be generated (you pass the arguments in order in which they were
declared in the macro).</p>

<p>gen-struct classes need to be compiled, just like with gen-class.</p>

<p>This is an ugly duckling, since it doesn&#8217;t allow for inheritance,
probably not everyone will be happy with no possibility of overriding <code>equals</code>, 
and static final fields can only be of primitive type. At least it doesn&#8217;t let you mix state and behavior in one entity.</p>

<p>My main motivation for creating it was that some of my experiments in
<a href="http://github.com/rosado/clj-processing/tree">clj-processing</a> needed a lot of mutation.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2009/08/03/making-clojure-a-bit-more-mutable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Only one paragraph about Denmark</title>
		<link>http://www.haltingproblem.net/weblog/2009/02/15/only-one-paragraph-about-denmark/</link>
		<comments>http://www.haltingproblem.net/weblog/2009/02/15/only-one-paragraph-about-denmark/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 00:40:54 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/2009/02/15/only-one-paragraph-about-denmark/</guid>
		<description><![CDATA[I&#8217;ve been in Denmark for over a month and haven&#8217;t really seen much of it. I&#8217;m waiting for warmer weather. But the people are cool. Lots of different nationalities in the place I work in makes things even more interesting. 

I&#8217;m doing mostly .NET related stuff right now, I only have time for Clojure on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been in Denmark for over a month and haven&#8217;t really seen much of it. I&#8217;m waiting for warmer weather. But the people are cool. Lots of different nationalities in the place I work in makes things even more interesting. </p>

<p>I&#8217;m doing mostly .NET related stuff right now, I only have time for Clojure on weekends. I&#8217;m trying to get a feel for getting better performance out of Clojure code; yesterday I&#8217;ve dug up an old code sample, but now I see I was doing a bunch of subtle things wrong. Rewrite ahead! </p>

<p>Back in December I&#8217;ve begun to prototype a Swing app in Java (I needed auto-completion to get used to the giantic API). Right now I&#8217;m in the process of building it from scratch in Clojure. I want to see how far I can go without dropping down to Java, and how to combine Java and Clojure in one project effectively (mostly from the design perspective).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2009/02/15/only-one-paragraph-about-denmark/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clojure goodies</title>
		<link>http://www.haltingproblem.net/weblog/2008/11/25/clojure-goodies/</link>
		<comments>http://www.haltingproblem.net/weblog/2008/11/25/clojure-goodies/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 10:54:06 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/?p=45</guid>
		<description><![CDATA[Processing + Clojure

Processing is a java library for doing visualizations and various
media related stuff. A while ago I did a Clojure wrapper for it. You
can get it from github: clj-processing. 

Cloak

A couple of months ago I saw examples of config files of ruby&#8217;s
rake. Rake is a build tool, like ant or msbuild, but unlike
those, it [...]]]></description>
			<content:encoded><![CDATA[<h4>Processing + Clojure</h4>

<p><a href="http://processing.org/">Processing</a> is a java library for doing visualizations and various
media related stuff. A while ago I did a Clojure wrapper for it. You
can get it from github: <a href="http://github.com/rosado/clj-processing/tree/master">clj-processing</a>. </p>

<h4>Cloak</h4>

<p>A couple of months ago I saw examples of config files of ruby&#8217;s
<a href="http://rake.rubyforge.org/">rake</a>. Rake is a build tool, like <code>ant</code> or <code>msbuild</code>, but unlike
those, it doesn&#8217;t involve editing XML files. And thanks to ruby&#8217;s
quite flexible syntax, the resulting configuration files don&#8217;t hurt
your eyes.</p>

<p>I don&#8217;t know ruby and didn&#8217;t really feel like learning it just for one
tool. Googling for something similar to rake in the python universe didn&#8217;t
yield any results.</p>

<p>Since I&#8217;m investing much time in Clojure lately, I decided that I
might as well write something useful in it. Hence <a href="http://github.com/rosado/cloak/tree">Cloak</a>, a
simplistic automation tool written in Clojure. It&#8217;s heavily inspired by
rake; I had rake&#8217;s docs opened most of the time when writing the app.</p>

<p>Here&#8217;s how to use it. You put a file named <code>CLOAK</code> in your project&#8217;s
directory, and in it you define tasks, like this:</p>

<pre>
(task :task-name [:other-task :another]
    (when (exists? "some.file")
        (rm  "some.file"))
    (sh "command arg1 arg2 arg3" :dofail))
</pre>

<p>Task name should be a keyword. To run it from the command line, type
<code>cloak task-name</code>, without the semicolon (assuming <code>cloak</code> is the name
of the shell script that launches cloak). Second argument to task is an
optional list of dependencies, which can be other tasks or files. For
example <code>[:compile "classes/my.lib"]</code>. To refer to a file, use it&#8217;s
file name. Apart from regular tasks, you can specify file tasks:</p>

<pre><code> (file "index.html" ["template.xml" "content/main.txt"]
       (sh "genhtml template.xml content/main.txt index.html"))
</code></pre>

<p><code>file</code> tasks differ from regular <code>tasks</code> in one detail: they compare
modification time of the target and all its dependencies. Task is
executed only if mtime of target &lt; mtime of source.</p>

<p>Cloak is not a replacement for <code>maven</code> or <code>ant</code>. It would take me ages
to reach the level of functionality of those tools. I just wanted
something simple, to automate the generation of my website (among
other things). So far, it&#8217;s still a work in progress but it&#8217;s usable enough for me to use it with my own projects.</p>

<h4>Utility Libs</h4>

<p>I&#8217;ve also put my <a href="https://github.com/rosado/libs4clj/tree">utility libs</a> on github. Cloak requires them (but has
them in in a jar, so no need to download them separately). There&#8217;s
some IO and math related stuff in there. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2008/11/25/clojure-goodies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Autumn Update</title>
		<link>http://www.haltingproblem.net/weblog/2008/11/20/autumn-update/</link>
		<comments>http://www.haltingproblem.net/weblog/2008/11/20/autumn-update/#comments</comments>
		<pubDate>Wed, 19 Nov 2008 22:23:13 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[Journal]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/?p=39</guid>
		<description><![CDATA[Since the end of the year is near, and because at the beginning of January
I&#8217;ll be pretty busy with other things (see below), I decided I&#8217;ll post
something while I still have spare time on my hands.

On a personal note, that was a good year (I finished school, among
other things). On the professional level, well, I [...]]]></description>
			<content:encoded><![CDATA[<p>Since the end of the year is near, and because at the beginning of January
I&#8217;ll be pretty busy with other things (see below), I decided I&#8217;ll post
something while I still have spare time on my hands.</p>

<p>On a personal note, that was a good year (I finished school, among
other things). On the professional level, well, I didn&#8217;t work
anywhere, was too busy with my thesis. But in September I started
sending out my CV and found something really nice. In Denmark.</p>

<p>I&#8217;m starting in January, that&#8217;s why I won&#8217;t have much time at the
beginning of next year for fancy retrospectives. I&#8217;ll spend 1+ year in
Denmark. I always wanted to live there, at least for a while. I mean,
they invented Lego, best toy <em>ever</em>.</p>

<p>But till then, I have lots of free time and so far I&#8217;m spending it
mostly on reading and programming. I&#8217;m gradually replacing Python with
<a href="http://www.clojure.org/">Clojure</a> as my weapon of choice and I&#8217;ll post something on that
topic shortly. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2008/11/20/autumn-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MathTalker Went Live</title>
		<link>http://www.haltingproblem.net/weblog/2008/08/31/mathtalker-went-live/</link>
		<comments>http://www.haltingproblem.net/weblog/2008/08/31/mathtalker-went-live/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 00:18:01 +0000</pubDate>
		<dc:creator>roland</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[appengine]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mathtalker]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.haltingproblem.net/weblog/?p=35</guid>
		<description><![CDATA[On friday I uploaded the 1.0 version of MathTalker to
   Google&#8217;s servers. It&#8217;s a simple chat application which allows you to write
   mathematical formulas (using syntax similar to TeX). It was written in
   Python and runs on App Engine. 


MathTalker has pretty steep requirements for a web app: Firefox
 [...]]]></description>
			<content:encoded><![CDATA[<p>On friday I uploaded the 1.0 version of <a href="http://mathtalker.appspot.com">MathTalker</a> to
   Google&#8217;s servers. It&#8217;s a simple chat application which allows you to write
   mathematical formulas (using syntax similar to TeX). It was written in
   Python and runs on <a href="http://appengine.google.com">App Engine</a>. 
</p>

<p><em>MathTalker</em> has pretty steep requirements for a web app: Firefox
   browser and special math fonts (download links on <em>MathTalker</em>
   page). Displaying math formulas is possible thanks to <a href="http://asciimathml.sourceforge.net/">ASCIIMathML</a>
   library, which converts ASCII to MathML. I know about the plug-in that
   lets you render MathML in IE, but I decided to drop support for that
   browser after spending a couple of hours trying to make the UI work.
</p>

<h4>App Engine</h4>

<p>App Engine SDK comes with a little web framework and that&#8217;s what I
   used. You can also use <a href="http://www.djangoproject.com/">Django</a>, but I wanted to keep things
   simple. The built-in framework is nothing special, but it doesn&#8217;t get
   in your way. What requires more attention is Google&#8217;s Datastore -
   their distributed database. Honestly, I used only relational databases
   so far (oh, and flat files&#8230;), so I had to watch one or two talks
   from Google IO conference to get the idea.
</p>

<p>What pissed me off the most was lack of support for nested
   transactions and some bugs in existing transaction code. To run some
   piece of code, you have to pass a function to
   <code>db.run_in_transaction()</code>, but whenever I tried to make the code more
   generic (as in: not to write two almost identical functions) stuff
   exploded. It&#8217;s pretty bad, because creating an entity and updating a
   counter should be a single atomic action. But they aren&#8217;t, so you end
   up hoping for the best.
</p>

<h4>JavaScript</h4>

<p>Little bit of history: At first I hated it, then I really liked
   it. Now I&#8217;m just using it and ignoring its deficiencies. And regarding
   the period that I liked JS: it was the time that JS libraries were
   becoming really, really good, and I was just impressed (shocked, even)
   that it&#8217;s possible to build anything with it without cursing like mad.
</p>

<p>But even JS 1.7, which has generators and list comprehensions, is
   pretty verbose, and you can only take it so far as
   <a href="http://jquery.org">jQuery</a> - the best attempt for creating domain
   specific language in JavaScript. Great for traversing/manipulating
   DOM.
</p>

<p>Another thing: I used Emacs with <a href="http://code.google.com/p/js2-mode/">js2-mode</a>. The style of formating
   code encouraged (somewhat) by jQuery drives Emacs insane and beaks the
   indentation. At the beginning it bothered me, but then I stopped
   nesting function definitions and <code>js2-mode</code> let me do my work, and my
   code looked more readable. I don&#8217;t know if that was how <code>js2-mode</code>
   supposed to work or if it was just a bug, but it&#8217;s done more good than
   harm.
</p>

<h4>Blueprint</h4>

<p>I&#8217;ve also tried out <a href="http://blueprintcss.org/">Blueprint</a> CSS framework. I&#8217;ve used
   Yahoo&#8217;s CSS reset library before (and I don&#8217;t want to work without CSS
   reset <em>ever</em> again), but never Blueprint. It&#8217;s pretty good, but
   somehow feels not <em>clean</em> enough. I guess it provides to much defaults
   for my taste. But I&#8217;ll probably use it again someday.
</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haltingproblem.net/weblog/2008/08/31/mathtalker-went-live/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
