<?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>Everything old is new again</title>
	<atom:link href="http://www.svendtofte.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.svendtofte.com</link>
	<description>rantings &#38; scraps on code and web development</description>
	<lastBuildDate>Sat, 06 Nov 2010 20:55:12 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>A beauty of things imperfect, impermanent and incomplete</title>
		<link>http://www.svendtofte.com/other/a-beauty-of-things-imperfect-impermanent-and-incomplete/</link>
		<comments>http://www.svendtofte.com/other/a-beauty-of-things-imperfect-impermanent-and-incomplete/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 20:54:21 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[aesthetics]]></category>
		<category><![CDATA[philosophy]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=331</guid>
		<description><![CDATA[I&#8217;ve been reading a bit about a certain kind of japanese philosophy called &#8220;wabi-sabi&#8221;, which is a japanese world-view and aesthetic. The list, which contrasts wabi-sabiwith modernism, is from Koren&#8217;s book, which contains many beautiful pictures of objects that embody the wabi-sabi philosophy. There seems to an inherit satisfaction in thinking about these juxtapositions for [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve been reading a bit about a certain kind of japanese philosophy called &#8220;wabi-sabi&#8221;, which is a japanese world-view and aesthetic. The list, which contrasts wabi-sabiwith modernism, is from <a href="http://www.amazon.com/Wabi-Sabi-Artists-Designers-Poets-Philosophers/dp/1880656124">Koren&#8217;s book</a>, which contains many beautiful pictures of objects that embody the wabi-sabi philosophy. There seems to an inherit satisfaction in thinking about these juxtapositions for me. Perhaps favoring neither, but seeing the validity of each of the opposing stances.</p>
<p><span id="more-331"></span></p>
<table class="tufteDesign" style="width:470px;margin-left:auto;margin-right:auto;">
<tr>
<th>Modernism</th>
<th>Wabi-sabi</th>
</tr>
<tr>
<td>Primarily expressed in the public domain</td>
<td>Primarily expressed in the public domain</td>
</tr>
<tr>
<td>Implies a logical, rational worldview</td>
<td>Implies an intuitive worldview</td>
</tr>
<tr>
<td>Absolute</td>
<td>Relative</td>
</tr>
<tr>
<td>Looks for universal, prototypical solutions</td>
<td>Looks for personal, idiosyncratic solutions</td>
</tr>
<tr>
<td>Mass-produced/Modular</td>
<td>One-of-a-kind/variable</td>
</tr>
<tr>
<td>Expresses faith in progress</td>
<td>There is no progress</td>
</tr>
<tr>
<td>Future-oriented</td>
<td>Present-oriented</td>
</tr>
<tr>
<td>Believes in the control of nature</td>
<td>Believes in the fundamental uncontrollability of nature</td>
</tr>
<tr>
<td>Romanticizes technology</td>
<td>Romanticizes nature</td>
</tr>
<tr>
<td>People adapting to machines</td>
<td>People adapting to nature</td>
</tr>
<tr>
<td>Geometric organization of form (sharp, precise, definite shapes and edges)</td>
<td>Organic organization of form (soft, vague shapes and edges)</td>
</tr>
<tr>
<td>The box as a metaphor (rectilinear, precise, contained)</td>
<td>The bowl as a metaphor (free shape, open at top)</td>
</tr>
<tr>
<td>Manmade materials</td>
<td>Natural materials</td>
</tr>
<tr>
<td>Ostensibly slick</td>
<td>Ostensibly crude</td>
</tr>
<tr>
<td>Needs to be well-maintained</td>
<td>Accommodates to degradation and attrition</td>
</tr>
<tr>
<td>Purity make its expression richer</td>
<td>Corrosion and contamination make its expression richer</td>
</tr>
<tr>
<td>Solicits the reduction of sensory information</td>
<td>Solicits the expansion of sensory information</td>
</tr>
<tr>
<td>Is intolerant of ambiguity and contradiction</td>
<td>Is comfortable with ambiguity and contradiction</td>
</tr>
<tr>
<td>Cool</td>
<td>Warm</td>
</tr>
<tr>
<td>Function and utility are primary values</td>
<td>Function and utility are not so important</td>
</tr>
<tr>
<td>Perfect materiality is an ideal</td>
<td>Perfect immateriality is an ideal</td>
</tr>
<tr>
<td>Everlasting</td>
<td>To every thing there is a season</td>
</tr>
</table>
<p>What&#8217;s so fascinating about these two philosophies and aesthetics is how they contrast so sharply, and yet share so many conceptual similarities. As Koren puts it in his book:</p>
<blockquote>
<ul>
<li>Both apply to all manner of manmade objects, spaces and designs.</li>
<li>Both are strong reactions against the dominant, established sensibilities of their time. Modernism was a radical depature from 19th-century classicism and eclecticsism. Wabi-sabi was a radical depature from the Chinese perfection and gorgeousness of the 16th-century and earlier.</li>
<li>Both eschew any decoration that is not integral to structure.</li>
<li>Both are abstract, nonrepresentational ideasl of beauty.</li>
<li>Both have readily identifiable surface characteristics. Modernism is seamless, polished, and smooth. Wabi-sabi is earthy, impefect, and variegated.</li>
</ul>
</blockquote>
<p>Wabi-sabi being summed up as the beauty of things imperfect, impermanent, and incomplete. Is is a beauty of things modest and humble.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/other/a-beauty-of-things-imperfect-impermanent-and-incomplete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript Testing</title>
		<link>http://www.svendtofte.com/javascript/javascript-testing/</link>
		<comments>http://www.svendtofte.com/javascript/javascript-testing/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 14:13:52 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=327</guid>
		<description><![CDATA[I had a new experience (for me anyway), someone approached me with offer of reviewing a new Javascript book that Packt recently published called &#8220;Javascript Testing&#8220;. I guess this is mainly a way of promoting ones book, but it&#8217;s been a while since I actually read anything new on Javascript, since Douglas Crockford mostly has [...]]]></description>
				<content:encoded><![CDATA[<p>I had a new experience (for me anyway), someone approached me with offer of reviewing a new Javascript book that Packt recently published called &#8220;<a href="http://www.packtpub.com/javascript-testing-beginner?s-guide/book?utm_source=svendtofte.com&#038;utm_medium=bookrev&#038;utm_content=blog&#038;utm_campaign=mdb_004576">Javascript Testing</a>&#8220;. </p>
<p>I guess this is mainly a way of promoting ones book, but it&#8217;s been a while since I actually read anything new on Javascript, since Douglas Crockford mostly has this business down in terms of the core language itself these days. But a book about testing sounds interesting to me, because while I have always loved the core language, JS has often had rather mediocre tools in my eyes, and will be interesting to see what the book offers up in this area.</p>
<p>On an unrelated note, I can add that while I rarely update this blog, I do run a <a href="http://twitter.com/svendtofte/">rather useless twitter account</a> which I attempt to spam with inane stuff as much as possible, as is the custom!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/javascript/javascript-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vim stuff</title>
		<link>http://www.svendtofte.com/other/vim-stuff/</link>
		<comments>http://www.svendtofte.com/other/vim-stuff/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 22:38:34 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[remotedesktop]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=302</guid>
		<description><![CDATA[Vim is a nice editor, but I never liked the way it handles files. Thankfully I recently found a great script, which adds great quick browsing capabilities to Vim, called lusty-explorer.vim. Since 7, Vim has supported not just it&#8217;s own homegrown (and honestly fairly bastardized language) called VimScript, but also it has included bindindgs for [...]]]></description>
				<content:encoded><![CDATA[<p>Vim is a nice editor, but I never liked the way it handles files. Thankfully I recently found a great script, which adds great quick browsing capabilities to Vim, called <a href="http://www.vim.org/scripts/script.php?script_id=1890">lusty-explorer.vim</a>. Since 7, Vim has supported not just it&#8217;s own homegrown (and honestly fairly bastardized language) called VimScript, but also it has included bindindgs for popoular scripting languages such as Ruby and Python, so extending this script with some extra functionality was a great way to see how Vims extensibility works. And with lusty-explorer written in Ruby, this was a nice chance to learn these new aspects of Vim.</p>
<p><span id="more-302"></span></p>
<p>Anyway, lusty-explorer adds quick ways to browse either the loaded buffers, or browse the filesystem, but doing both in a way which blows away the built-in directory browser in Vim. But the way I like to browse files is basicly with a &#8220;recently used&#8221; file list, which should include currently open files. So with some changes to the lusty-explorer script, it now has a great &#8220;recently used&#8221; explorer, which I find totally eliminates any need to check currently loaded buffers. Want to open a file you know you&#8217;ve opened recently? Just hit <code>&lt;leader&gt;lu</code>, and the last many files you opened are there, easy to get to. If the file is alredy open, Vim just switches to that buffer, just like if you had entered <code>:e <em>file</em></code>.</p>
<p>Get <a href="/wp-content/uploads/2009/08/lusty-explorer-mod.vim">lusty-explorer-mod.vim</a>.</p>
<h3>Remote Desktop, Consolas and ClearType, oh my</h3>
<p>Something else which I&#8217;ve found a need for, is a capability to detect when Vim is used in a remote desktop session. Since I spend maybe half of all my time working in a RD, where ClearType is usually disabled, that means that my preferred font, <a href="http://www.codinghorror.com/blog/archives/000969.html">Consolas</a> <a href="http://www.codinghorror.com/blog/archives/000356.html">looks like shit</a>. While not the same as having ClearType disabled, I found that the easiest way out was to check <a href="http://msdn.microsoft.com/en-us/library/ms724385%28VS.85%29.aspx">if the current session was via Remote Desktop</a> (look for the <code>SM_REMOTESESSION</code>.) Thankfully that&#8217;s pretty easy to check. Here&#8217;s a minuscule C program which does this.</p>
<pre>#include &lt;windows.h&gt;
#pragma comment(lib, "user32.lib")

int main(void) {
    if (GetSystemMetrics(SM_REMOTESESSION)) {
        printf("1");
    } else {
        printf("0");
    }
    return 0;
}</pre>
<p>The precompiled <a href="/wp-content/uploads/2009/08/remotesession32bit.exe">file here</a> is compiled for 32bit, on WinXP, but tested on 64bit 2008 Server as well, where it should work just fine, through the miracle of <a href="http://en.wikipedia.org/wiki/Windows_on_Windows" title="Not World of Warcraft damnit!">WOW</a>. You can use this small executable, by dropping it in the path of computers where you use Vim, and where you might also log in via Remote Desktop, and then you can tweak your _vimrc like this:</p>
<pre>if has("gui_running") " gvim is running
    if has('win32')
        set guifont=Consolas:h11:cANSI
        if system("remotesession") == "1"
            set guifont=Lucida_Console:h10:cANSI
        endif
    endif
endif</pre>
<p>Lets you get the best of both worlds, Consolas, when ClearType is (probably) present, and Lucida when not (Lucida Console is still fairly decent.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/other/vim-stuff/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Javascript ghost debugging</title>
		<link>http://www.svendtofte.com/javascript/javascript-ghost-debugging/</link>
		<comments>http://www.svendtofte.com/javascript/javascript-ghost-debugging/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 00:46:35 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[debugger]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=262</guid>
		<description><![CDATA[Recently, I tried to use jQuery, as a way of dynamically loading all the scripts that a certain page requires. Instead of utilizing script tags in the header section, using a simple $.getScript("script.js"); loads the same code, what&#8217;s more, this code is loaded asynchronously, which helps improve loading performance. The only problem is that loading [...]]]></description>
				<content:encoded><![CDATA[<div style="float:right;"><img src="/wp-content/uploads/2009/07/mario-boo.jpg" alt="Boo"></div>
<p>Recently, I tried to use jQuery, as a way of dynamically loading all the scripts that a certain page requires. Instead of utilizing script tags in the header section, using a simple <code>$.getScript("script.js");</code> loads the same code, what&#8217;s more, this code is loaded asynchronously, which helps <a href="http://www.stevesouders.com/blog/2008/12/27/coupling-async-scripts /">improve loading performance</a>. The only problem is that loading scripts this way, makes them <em>unavailable for debugging</em>.</p>
<p>Debugging dynamically included script files presents some special challenges on it&#8217;s own. The primary being that that the web is basicly not a structured enviroment, like a folder on disk, and references to files and/or code is can be very intermittent.</p>
<p><span id="more-262"></span></p>
<h3>Some methods for loading remote code</h3>
<p>Here&#8217;s just some of the many ways that code may be included dynamically in a page (these are just rough outlines, buyer beware.) Be especially wary that this code is specifically for loading scripts, if you want to load JSON, you&#8217;ll need a different approach, just spilling your guts in the global scope is quite messy.</p>
<ol>
<li>
<p>Using XMLHttpRequest to load the script, and then insert via DOM methods into the page itself.</p>
<pre>
var req = new XMLHttpRequest();
req.open('GET', 'delayed.js', true)
req.onreadystatechange = function(e) {
    var head= document.getElementsByTagName('body')[0];
    var delayed = document.createElement('script');
    var txt = document.createTextNode(req.responseText);
    delayed.appendChild(txt);
    head.appendChild(delayed);
}
req.send();
</pre>
</li>
<li>
<p>Using XMLHttpRequest to load the script, and then use <code>eval</code> to execute the code in the global scope.</p>
<pre>
var req = new XMLHttpRequest();
req.open('GET', 'delayed.js', true)
req.onreadystatechange = function(e) {
    eval(req.responseText);
}
req.send();
</pre>
</li>
<li>
<p>Dynamically create a script tag with DOM methods, and then point it&#8217;s <code>src</code> attribute to the script you wish download.</p>
<pre>
var head= document.getElementsByTagName('head')[0];
var delayed = document.createElement('script');
delayed.onreadystatechange = function() {
    if (delayed.readyState == "loaded" || 
        delayed.readyState == "complete") delay();
}
delayed.src = "delayed.js";
head.appendChild(delayed);
</pre>
<p>This code also details how you can get a callback for when the actual script has loaded, so you&#8217;re not &#8220;missing&#8221; out on the callback functionality of XMLHttpRequest.</p>
</li>
</ol>
<p>jQuery basicly executes the first approach. The little twist is that just after the script has been added to the browser, it removes the tag again, so it&#8217;s not &#8220;littering&#8221; the document DOM with these script tags the author himself didn&#8217;t insert. This can be seen in the jQuery script at around line 646, where you find the <code>globalEval</code> function (assuming the development version, not the minified versions.)</p>
<h3>The problem with anonymous code</h3>
<p>This is all dandy, the problem simply is that no debuggers expose the anonymous code which enters the global scope in this fashion.</p>
<p class="imgWithCaption"><img src="http://www.svendtofte.com/wp-content/uploads/2009/07/firebug-html-view.gif" alt="Firebug showing a webpage with a static and dynamic node of Javascript" /><br /> Firebug showing a webpage with both a static and a dynamically loaded script (the script was loaded with jQuery, but with a modified jQuery so that it leaves the node in the DOM). Everything looks fine.</p>
<p class="imgWithCaption"><img src="http://www.svendtofte.com/wp-content/uploads/2009/07/firebug-js-view.gif" alt="Firebug's Javascript tab with only the static node available for debugging." /><br /> Firebug&#8217;s script tab shows a different view, namely the one where the dynamically loaded script block is gone, and thus not available for debugging.  </p>
<p>If you try to load the following script, with this piece of jQuery, <code>$.getScript("delay.js", function() { delay(); });</code>, will lead the debugger to exclaim that the method name is &#8220;anonymous&#8221;!</p>
<pre>
function delay() {
    alert("hello from delayed.js");
    console.trace();
}
</pre>
<h3>Loading code for proper debugging</h3>
<p>As you can see, the way that jQuery (and many other libs) chooses to load their scripts is a rather high-tech one, and the solution is as simple as not using XMLHttpRequest. By utilizing the third method of remotely loading scripts, allows you to morely accurately debug the scripts.</p>
<p>Take the following page and two script files for instance:</p>
<pre>
&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
function load(scriptSrc, callback) { 
    var head= document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.onreadystatechange = function() {
        if (script.readyState == "loaded" || 
            script.readyState == "complete") callback();
    }
    script.src = scriptSrc;
    head.appendChild(script);    
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;p&gt;&lt;a href="javascript:load('load1.js',function() { load1(); });"&gt;load 1&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="javascript:load('load2.js',function() { load2(); });"&gt;load 1&lt;/a&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<pre>
function load1() {
    alert("hello from load1");
}
</pre>
<pre>
function load2() {
    alert("hello from load2");
}
</pre>
<p>If we look at IE8&#8242;s Developer Tools JS debugger, you&#8217;ll notice that on page load, the scripts drop-down does not contain neither load1.js or load2.js.</p>
<p class="imgWithCaption"><img src="/wp-content/uploads/2009/07/ie-dev-tools-initial.gif" width="535" height="198" alt="IE8 Developer Tools on initial page load" /><br /> IE8&#8242;s Developer Tools on initial loading of a simple HTML page.</p>
<p>If we try to click the links however, the scripts we load will appear in the  dropdown, and allow easy debugging.</p>
<p class="imgWithCaption"><img src="/wp-content/uploads/2009/07/ie-dev-tools-loaded.gif" alt="IE8 Developer tools showing script available for debugging." width="535" height="198" /><br />IE8&#8242;s Developer Tools after having clicked the load link, the loaded script is now available for easy debugging (this works just as well in Firebug btw.)</p>
<h3>Debuggers</h3>
<p>Debuggers are still lacking behind in this area, compared to debuggers operating in more stable enviroments. There&#8217;s no denying that the web presents unique challenges, but the fact remains that the code is available for execution, but is not exposed for debugging. So while JS debuggers has moved forward since the days of <a href="/code/learning_venkman">Venkman</a>, I think there&#8217;s still ways to improve (and this need will become more pronounced as the dynamic nature of the web increases with time).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/javascript/javascript-ghost-debugging/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Zealotry versus advocacy</title>
		<link>http://www.svendtofte.com/geek-angst/zealotry-versus-advocacy/</link>
		<comments>http://www.svendtofte.com/geek-angst/zealotry-versus-advocacy/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 19:24:48 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Geek angst]]></category>
		<category><![CDATA[gpg]]></category>
		<category><![CDATA[morons]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=249</guid>
		<description><![CDATA[Recently, I was compelled by a friend to download GNU Privacy Guard, GPG in short, in order to do things &#8220;properly&#8221;, when we were gonna exchange some possibly sensitive data. Now, GPG is a open-source re-implentation of the venerable PGP, Pretty Good Privacy, which was one of the first widely used programs using the public-key [...]]]></description>
				<content:encoded><![CDATA[<p>Recently, I was compelled by a friend to download <a href="http://www.gnupg.org/">GNU Privacy Guard</a>, GPG in short, in order to do things &#8220;properly&#8221;, when we were gonna exchange some possibly sensitive data. Now, GPG is a <a href="http://www.opensource.net/">open-source</a> re-implentation of the venerable PGP, Pretty Good Privacy, which was one of the first widely used programs using the public-key cryptography. Public-key crypto is socalled asymmetric-key system, since the sender and receiver of a messege do not share a key before hand. It allows total strangers to communicate securely over in-secure lines. The internet&#8217;s SSL (which is usually what&#8217;s used when you see <em>https</em> in the address bar of your browser) is built on this technology. So what we&#8217;re dealing with here is a serious attempt at a full blown cryptographic system, used by people across the globe, wishing to communicate securely. With all this in mind, the experience I had when reading the following snippet in the Windows readme was even more jarring</p>
<blockquote><p>The term &#8220;W32&#8243; is used to describe the API used by current Microsoft Windows versions.  We don&#8217;t use the Microsft terminology here; in hacker terminology, calling something a &#8220;win&#8221; is a form of praise. Keep in mind that Windows ist just a temporary workaround until you can switch to a complete Free Software system.  Be the source always with you.</p></blockquote>
<p>The Windows <a href="http://en.wikipedia.org/wiki/API">API</a> is normally referred to as &#8220;win32&#8243; (the 32 is a reference to the fact that it&#8217;s a 32 bit machine API). So by <em>refusing</em> to refer to the term &#8220;win32&#8243;, and instead use &#8220;W32&#8243;, it merely comes across as a totally juveline display of non-professionalism. Being termed a &#8220;hacker&#8221; is an honorary term in the programmer community, and as with all such things, you don&#8217;t get to name yourself a hacker. So it&#8217;s not only slightly buffoonish with the allusion to the hacker term &#8220;win&#8221;, it&#8217;s also quite campy with it&#8217;s Star Wars reference. </p>
<p>I&#8217;m all for the Unix philosophy and open source. In fact, I think it&#8217;s healthy for the IT world, that some people think in terms of more then just money. But when dogmatic advocacy gives trumps real world pragmatism, I&#8217;m off the train. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/geek-angst/zealotry-versus-advocacy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Non-english domain naming issues in programming</title>
		<link>http://www.svendtofte.com/other/non-english-domain-naming-issues-in-programming/</link>
		<comments>http://www.svendtofte.com/other/non-english-domain-naming-issues-in-programming/#comments</comments>
		<pubDate>Mon, 30 Mar 2009 16:55:31 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[encoding]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[meaning]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=206</guid>
		<description><![CDATA[This is a problem I&#8217;ve been thinking a good deal about lately, without really coming to any conclusion, maybe because there is no right way. The issue can be summed up fairly easily, but it does betray the multitude of issue that lie beneath. How do you handle non-english terms in your code? I imagine [...]]]></description>
				<content:encoded><![CDATA[<p>This is a problem I&#8217;ve been thinking a good deal about lately, without really coming to any conclusion, maybe because there is no right way. The issue can be summed up fairly easily, but it does betray the multitude of issue that lie beneath.</p>
<blockquote><p><em>How do you handle non-english terms in your code?</em></p></blockquote>
<p><span id="more-206"></span></p>
<p>I imagine most programmers write their code in english. This simply makes the most sense, I&#8217;m sure people will agree with this. The vast majority of pre-existing code (libraries, APIs) is in english. The literature and enviroments that programmers need to work in or with are english. And sometimes even technical issues, such as tool chain inabilities to handle some more complex character sets. While the issue is fairly banal, it does relate to the core issues in programming, semiotics and the encoding of meaning in the written word.</p>
<p>Programming is solving problems in some domain, be it mathematics, the local post office or a ticket seating systems for a stadium, and as such, you deal in the terms found in that domain. But when you&#8217;re <em>not</em> dealing with an english domain term, how do you handle that? I&#8217;m sure almost every non-english CS student has come across this issue, as universities tend to be a place where the native language is valued highly (and rightly so), and thus even very technical terms have found local translations.</p>
<p class="imgWithCaption"><img src="http://www.svendtofte.com/wp-content/uploads/2009/03/the_rosetta_stone_top.jpg" alt="The top part of the Rosetta stone" title="The top part of the Rosetta stone" width="500" height="253" class="alignnone size-full wp-image-216" /><br/>The problems of encoding and translations are not new issues. The image depicts the top of the <a href="http://en.wikipedia.org/wiki/Rosseta_Stone">Rosetta Stone</a>, showing the then lost egyption heiroglyphs encoding.</p>
<h3>Indblikskode versus Access code</h3>
<p>To keep it from being completely abstract, let&#8217;s take on an example. At work, we have a massive <acronym title="Electronic Document Management">EDM</acronym> system. As part of the security of this system, there&#8217;s a term called &#8220;indblikskode&#8221;. This denotes a code which a user has in the system. The code allows the user to view (and otherwise interact) with documents in the system. So, do we translate this danish term, or do we use it as is?</p>
<p>Indblikskode is an exact term with a specific meaning when coupled with our EDM system, but if I translate it into for example  &#8220;access code&#8221;, which may well mean the same thing, it has lost all the embedded meaning when coupled with our EDM system. If we forego a translation, we risc ending up with pidgin english, such as <code>getIndblikskode();</code>. Having myself, and anyone who may have to handle the code, plays translator isn&#8217;t exactly very productive either. And herein lies the issue.</p>
<blockquote><p><em>How to properly balance the loss of information as you move away from the terms of the problem domain, versus the problems of mixing languages.</em></p></blockquote>
<p>As always the answer is probably &#8220;it depends&#8221;. Who will look at the code after you&#8217;re done with it? How well can translations actually be made? Can only some terms be translated? The issue is that this problem is most oftenly handled by programmers, who sit with their editors, and are naming variables. It&#8217;s unrealistic to expect to commitee such work, and most programmers must simply work from a gut feeling.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/other/non-english-domain-naming-issues-in-programming/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SQL split function</title>
		<link>http://www.svendtofte.com/geek-angst/sql-split-function/</link>
		<comments>http://www.svendtofte.com/geek-angst/sql-split-function/#comments</comments>
		<pubDate>Mon, 09 Mar 2009 08:08:55 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Geek angst]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[sql server]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=162</guid>
		<description><![CDATA[Every time I need to work with SQL, it never ceases to amaze. The language is simply such an abortion in terms of development enviroments and simple programmer usability. Naturally, alot of this stems from my inexperience with the language. Mostly this post is just my own personal gripes with about SQL. So, at work [...]]]></description>
				<content:encoded><![CDATA[<p>Every time I need to work with SQL, it never ceases to amaze. The language is simply such an abortion in terms of development enviroments and simple programmer usability. Naturally, alot of this stems from my inexperience with the language. Mostly this post is just my own personal gripes with about SQL.</p>
<p>So, at work I find that I need a function which takes a variable number of GUIDs, and presents me with a compounded status integer, pulling status indicators for each GUID, and producing a single status. Should be simple right?</p>
<p><span id="more-162"></span></p>
<p>First off, I need this to be a function, so I can use it in <code>SELECT</code> constructs for a view. Why SQL has these random limitations on what can appear where, I&#8217;ll never know, but there it is. Then, the wild notion that I could pass in a variable number of GUIDs is killed fairly off quickly as SQL doesn&#8217;t support <a href="http://en.wikipedia.org/wiki/Variadic_function">variadic functions</a>.</p>
<p>So ok, I need to pass in the GUIDs in a single data structure. Of course, I know right off the bat, that I can&#8217;t pass tables (&lt;sarcasm&gt;why would anyone wanna do that anyway?&lt;/sarcasm&gt;), so we&#8217;ll just pack a string with the GUIDs I need. I&#8217;ll live with <code>myFunction("guid1,guid2,guid3")</code>. So taking a look over the <a href="http://msdn.microsoft.com/en-us/library/ms186323(SQL.90).aspx">extremely rich string function library in SQL</a>, I notice there&#8217;s no split function. So I need to write that first.</p>
<h3>Writing an SQL string split function</h3>
<p>So let&#8217;s just lay it out there. In all it&#8217;s glory.</p>
<pre>CREATE FUNCTION dbo.Split (@String VARCHAR(500), @Delimeter CHAR(1))
RETURNS @Strings TABLE (String VARCHAR(500))
AS
BEGIN
    DECLARE @Position INT,
            @Next INT,
            @DelimeterWidth INT,
            @Substring VARCHAR(500)

    SET @Position = 1
    SET @Next = 1 -- set to 1, just to get past initial while cond
    SET @DelimeterWidth = LEN(@Delimeter)

    WHILE @Next > 0
    BEGIN
        SET @Next = CHARINDEX(@Delimeter, @String, @Position)
        IF (@Next-@Position) >= 1
        BEGIN
            SET @Substring = SUBSTRING(@String, 
                                       @Position+1, 
                                       @Next - @Position - @DelimeterWidth)
            INSERT INTO @Strings(String) VALUES(@Substring)
        END
        SET @Position = @Next
    END

    RETURN 
END
</pre>
<p>You&#8217;ll notice this returns a table. This table is btw also the <em>only one</em> you have to work with, no creating temporary tables! For some reason, <a href="http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html">you&#8217;re not allowed to create tables inside functions</a>. So once you&#8217;re past the 1-indexed strings, you&#8217;re almost there . I know that 0 versus 1 indexing is <a href="http://c2.com/cgi/wiki?WhyNumberingShouldStartAtZero">a religious war onto itself</a>, but given <a href="http://en.wikipedia.org/wiki/Ordinal_number">Cantor&#8217;s ordinals</a> start at 0, it does not seem entirely silly either. For a language so focused on sets, it seems a strange choice.</p>
<h3>They phoned it in</h3>
<p>SQL sometimes really feels like they sat down, thought about <code>SELECT</code>, sub-selects, joins, and the related set algebra, and <em>decided &#8220;nice work&#8221; and <a href="http://www.urbandictionary.com/define.php?term=phone+it+in">phoned the rest in</a></em>. Even <code>INSERT</code> makes no sense, why do we need to seperate the column names from the values?</p>
<pre>INSERT INTO tbl(col1, col2, col3) VALUES(val1, val2, val3)</pre>
<p><code>UPDATE</code> does it right.</p>
<pre>UPDATE tbl SET col1=val1, col2=val2, col3=val3</pre>
<p>Know what&#8217;s being sold as a exciting new feature in SQL 2008? <a href="http://www.vandeputte.org/2007/06/sql-2008-declaring-variables-and.html">Declaring and assigning values in one line!</a>. This is how low the bar is set. SQL is obviously not going anywhere, but I can&#8217;t for the life fathom why it has to be so abysmal at almost everything, except the little core which it does so well.</p>
<p><!--<br />
Transpose tables, WTF. says SQL is masterful in manipulating data my ass.</p>
<p>http://www.sommarskog.se/arrays-in-sql-2005.html</p>
<p>http://msdn.microsoft.com/en-us/library/ms186323(SQL.90).aspx</p>
<p>http://msdn.microsoft.com/en-us/library/ms187748(SQL.90).aspx</p>
<p>http://c2.com/cgi/wiki?ZeroAndOneBasedIndexes</p>
<p>http://c2.com/cgi/wiki?WhyNumberingShouldStartAtZero</p>
<p>http://c2.com/cgi/wiki?OrdinalsAndCardinals</p>
<p>http://databases.aspfaq.com/database/should-i-use-a-temp-table-or-a-table-variable.html</p>
<p>--></p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/geek-angst/sql-split-function/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>New host!</title>
		<link>http://www.svendtofte.com/uncategorized/new-host/</link>
		<comments>http://www.svendtofte.com/uncategorized/new-host/#comments</comments>
		<pubDate>Wed, 18 Feb 2009 10:53:38 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=159</guid>
		<description><![CDATA[My site has been down for quite some time, while I both arranged some new hosting, and tried to save the contents of the old site. I want to once more, thank my buddy and old coworker, Lasse, for hosting this site for near on 9 years. Thankfully, seems that restoring WordPress is a simply [...]]]></description>
				<content:encoded><![CDATA[<p>My site has been down for quite some time, while I both arranged some new hosting, and tried to save the contents of the old site. I want to once more, thank my buddy and old coworker, Lasse, for hosting this site for near on 9 years. Thankfully, seems that restoring WordPress is a simply matter of re-importing the SQL tables, and then uploading the whole thing to my new host.</p>
<p>Let me know if there&#8217;s any bumps on the site!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/uncategorized/new-host/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>C# Generics and anonymous methods</title>
		<link>http://www.svendtofte.com/csharp/c-generics-and-anonymous-methods/</link>
		<comments>http://www.svendtofte.com/csharp/c-generics-and-anonymous-methods/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 20:11:59 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[anonymous-methods]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[list-comprehension]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=155</guid>
		<description><![CDATA[I&#8217;ve never been much of a C# maven or anything, but I&#8217;ve really fallen in love with this construct in the language. One thing which I guess almost anyone does alot of is building a string, from a list of business objects. Let&#8217;s say you have a list of GUIDs, and you either want to [...]]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve never been much of a C# maven or anything, but I&#8217;ve really fallen in love with this construct in the language. One thing which I guess almost anyone does alot of is building a string, from a list of business objects. Let&#8217;s say you have a list of GUIDs, and you either want to display them, or build an SQL string from them for use in a query.</p>
<pre>List&lt;Guid&gt; gs;
string s;

foreach (Guid g in gs) {
    s += "Id='" + g.ToString() + "' OR ";
}

if (result.Length &gt; 0) {
    s = s.Substring(0, s.Length-3);
}</pre>
<p>That&#8217;s some good ole fashioned string fucking, and since I&#8217;ve come over from HTML/JavaScript/(Classic) ASP/PHP, that&#8217;s bussiness as usual by all standards. But I&#8217;ve never liked several aspects of it.</p>
<p><span id="more-155"></span></p>
<ul>
<li>Since you&#8217;re appending to the string always, you need to take the last bit off, or the string turns malformed. That&#8217;s what the <code>if</code> construct does. It can sometimes be hard to connect a large <code>foreach/for</code> block with a succedding <code>if</code> block.</li>
<li>Contains magic numbers, in this case, 3. Can be avoided of course, if the bit that you&#8217;re appending is saved as a variable, and then you take the length of it. But that&#8217;s just more work.</li>
</ul>
<p>Another approach, using generics and anonymous methods is the following</p>
<pre>s = string.Join(" OR ", 
        gs.ConvertAll(
            new Converter&lt;Guid, string&gt;(
                delegate(Guid g) { 
                    return string.Format("Id='{0}'", g.ToString()); 
                }
            )
        ).ToArray()
    );</pre>
<p>or, if you&#8217;re running C# 3.0 (my work is still using 2.0), you can do away with most of the syntax for the <code>delegate</code> construction.</p>
<pre>s = string.Join(" OR ",
        gs.ConvertAll(
            new Converter&lt;Guid, string&gt;(
                g => string.Format("Id='{0}'", g.ToString())
            )
        ).ToArray()
    );</pre>
<p>Which is a radical departure from the <code>for</code> loops of yore. Probably debatable if it&#8217;s an improvement in actual performance (<code>string.Format</code> is faster then old string concatenation, but you could use <code>string.Format</code> with the first approach too of course). It&#8217;s a much more functional approach, with no side-effects. But in terms of what is pleasing to the eye, I have no doubts, even if it&#8217;s spanning more lines, it just feels more right. You never end up over doing it, so there&#8217;s never any string to remove. The act of creating the strings you need, and then joining them is also seperated, which feels more right.</p>
<p>The downside is that it does become harder to debug. If you have a line like for instance</p>
<pre>bool b = SomeMethod(GetSomeValue(param1, param2), param3);</pre>
<p>Using either a normal debugger it&#8217;s not easy to break on the method call to <code>GetSomeValue</code>. The same would be the case with the list comprehension at work here. With no assigned value, it&#8217;s a little harder for the debugging. But given the simplicity, it usually proves to be a non-issue for myself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/csharp/c-generics-and-anonymous-methods/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The utterly retarded IE PNG implementation (and pngstrip)</title>
		<link>http://www.svendtofte.com/web/the-utterly-retarded-ie-png-implementation-and-pngstrip/</link>
		<comments>http://www.svendtofte.com/web/the-utterly-retarded-ie-png-implementation-and-pngstrip/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 19:40:07 +0000</pubDate>
		<dc:creator>Svend</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[gamma]]></category>
		<category><![CDATA[internet explorer]]></category>
		<category><![CDATA[png]]></category>
		<category><![CDATA[pngstrip]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=117</guid>
		<description><![CDATA[pngstrip (32bit, Windows Executable at 59 kb) is a small program I&#8217;ve written to strip out the various kinds of gamma and chromacity information from PNG files. It&#8217;s written in standard ANSI C, so should compile on anything reasonable, though it has only been tested on Windows XP. The source code is also freely available. [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.svendtofte.com/wp-content/uploads/2008/08/pngstrip.exe">pngstrip</a> (32bit, Windows Executable at 59 kb) is a small program I&#8217;ve written to strip out the various kinds of gamma and chromacity information from PNG files. It&#8217;s written in standard ANSI C, so should compile on anything reasonable, though it has only been tested on Windows XP. <a href="http://www.svendtofte.com/wp-content/uploads/2008/08/pngstrip.c">The source code is also freely available.</a> It&#8217;s console program, just type out <code>pngstrip filename.png</code>, and <code>filename.png</code> will be stripped.</p>
<p>We spent years <a href="http://www.alistapart.com/stories/pngopacity/">agonizing over the lack of 8-bit alpha channel in PNG in IE</a>, and when we filly get it <a href="http://blogs.msdn.com/ie/archive/2005/04/26/412263.aspx">natively/nicely supported in IE</a> they go and botch is so horribly.</p>
<p>Most of us have heard about gamma. But unless you do something in the graphics/print field, it mostly remains a button on our screen, where we tweak the luminocity of the screen. But of course, when an artist makes a snazzy PNG picture, making sure that it appears at the same display intensity as it did on his screen is understandably an laudarble goal. So PNG embeds gamma information, saying that this and that color, should be show at this and that intensity. The problem occurs when the BOG STANDARD (for 15 years and counting) HTML and CSS colors are NOT processed through the same system and thus don&#8217;t get the same gamma correction applied. <a href="http://www.svendtofte.com/wp-content/uploads/2008/08/iepng.html">The problem is easy to spot</a> (need to be viewed in IE). The PNG files, once stripped, appears correctly.</p>
<p>I won&#8217;t really bother explaining this problem more, since it goes beyond stupid, I&#8217;ll just link further reading materials if you don&#8217;t know why you may wish to strip your PNG files for gamma information. <a href="http://hsivonen.iki.fi/png-gamma/">Henri Sivonen</a> has the best treatment on the topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/web/the-utterly-retarded-ie-png-implementation-and-pngstrip/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
