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

<channel>
	<title>Warren Falk</title>
	<atom:link href="http://www.warrenfalk.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.warrenfalk.com/blog</link>
	<description>readers are plentiful, thinkers are rare</description>
	<pubDate>Wed, 18 Jun 2008 11:14:39 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
	<language>en</language>
			<item>
		<title>Singletons by delegate</title>
		<link>http://www.warrenfalk.com/blog/2008/02/02/singletons-by-delegate/</link>
		<comments>http://www.warrenfalk.com/blog/2008/02/02/singletons-by-delegate/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 00:19:58 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2008/02/02/singletons-by-delegate/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p>Singletons are a common programming model, wherein a program ever only uses a single instance of a certain class, and that instance is shared program-wide.</p>
<p>The typical implementation of this is an if-null/lock/if-null setup that looks something like this:</p>
<pre>
class OnlyOne
{
  private OnlyOne _instance;
  public OnlyOne Instance
  {
    get
    {
      if (_instance == null)
      {
        lock (typeof(OnlyOne))
        {
          if (_instance == null)
          {
            _instance = new OnlyOne();
          }
        }
      }
      return _instance;
    }
  }
}</pre>
<p>The reason for the if-null/lock/if-null is one for a different discussion, but it is basically the fastest portable way to allow thread-safe access to the single instance. However, it requires that the first if-null be executed every time a request for the instance is made.  If your instance never changes, this is needless overhead.</p>
<p>I developed a quick and dirty solution using delegates.  The basic idea is that when you create the first instance and you know it can no longer be null, you change the &#8220;GetInstance&#8221; routine to point to a routine that does not check for null.  I created a generic for this.  Here&#8217;s the result:</p>
<pre>
public class Singleton&lt;T&gt; where T: new()
{
  public delegate T InstanceGetter();

  private static T _instance;
  public static InstanceGetter GetInstance = new InstanceGetter(_GetNewInstance);
  private static T _GetNewInstance()
  {
    if (_instance == null)
    {
      lock (typeof(T))
      {
        if (_instance == null)
        {
          _instance = new T();
          GetInstance = new InstanceGetter(_GetInstance);
        }
      }
    }
    return _instance;
  }
  private static T _GetInstance() { return _instance; }
}</pre>
<p>And then reusing it is quite easy:</p>
<pre>
class OnlyOne : Singleton&lt;OnlyOne&gt;
{
}</pre>
<p>Now only the first call to OnlyOne.GetInstance() will actually check for null in a single threaded environment.  And in the worst-case multithreaded environment, only the first simultaneous calls will check, the rest will just return the instance immediately.</p>
<p>My tests showed about a 25% performance gain.  This is actually of questionable usefulness because you should not be calling the GetInstance method in a tight loop, you should call it once and assign it to a local.  But I thought I&#8217;d share the basic idea because using delegates in this fashion might be useful in other scenarios.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2008/02/02/singletons-by-delegate/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Monodevelop</title>
		<link>http://www.warrenfalk.com/blog/2007/12/11/monodevelop/</link>
		<comments>http://www.warrenfalk.com/blog/2007/12/11/monodevelop/#comments</comments>
		<pubDate>Wed, 12 Dec 2007 02:46:04 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Computer Programming]]></category>

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

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2007/12/11/monodevelop/</guid>
		<description><![CDATA[I&#8217;m still relatively new to Mono, which is a cross platform, open-source implementation of .Net.  The implementation has proved surprisingly gap free for the most part.
But, what Mono suffers from is its lack of Visual Studio.  Much of what makes .Net development so effortless is what is a really good implementation of an [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m still relatively new to Mono, which is a cross platform, open-source implementation of .Net.  The implementation has proved surprisingly gap free for the most part.</p>
<p>But, what Mono suffers from is its lack of Visual Studio.  Much of what makes .Net development so effortless is what is a really good implementation of an IDE (refactoring, a really good debugger, smart tags, and several other nice things).  An IDE is beyond the scope of the Mono project, and another project, &#8220;Monodevelop&#8221; is filling in that gap.</p>
<p>Unfortunately, there are still gaping holes which makes it frustrating to anyone who has been spoiled by Visual Studio.  I miss the refactoring, the smart tags which prompt you to effortlessly add a &#8220;Using&#8221; if necessary, but most of all, a debugger.</p>
<p>It is not hard to write complex code, it isn&#8217;t hard to write code quickly, but if you need to do both, you really need a debugger to get it right.  And this is where Monodevelop (and also Mono) are way short.  It&#8217;s relatively young still and free open source; and most importantly the developers are planning to implement all these things.  I may see about getting in on that myself.  But for now, Monodevelop is slightly refreshing but mostly frustrating.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2007/12/11/monodevelop/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Latest mono on Ubuntu</title>
		<link>http://www.warrenfalk.com/blog/2007/12/05/latest-mono-on-ubuntu/</link>
		<comments>http://www.warrenfalk.com/blog/2007/12/05/latest-mono-on-ubuntu/#comments</comments>
		<pubDate>Thu, 06 Dec 2007 01:52:15 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2007/12/05/latest-mono-on-ubuntu/</guid>
		<description><![CDATA[The current version of mono on Ubuntu 7.10 is 1.2.4.2.  There are fixes in 1.2.5.2 which I need.  Getting 1.2.5.2 built is no problem, but getting it installed without causing all kinds of problems appears to be.  This is something I miss about Gentoo.
I&#8217;ve tried building my own package, but the official [...]]]></description>
			<content:encoded><![CDATA[<p>The current version of mono on Ubuntu 7.10 is 1.2.4.2.  There are fixes in 1.2.5.2 which I need.  Getting 1.2.5.2 built is no problem, but getting it installed without causing all kinds of problems appears to be.  This is something I miss about Gentoo.</p>
<p>I&#8217;ve tried building my own package, but the official packages for mono are split up into many smaller packages which made that impossible.</p>
<p>I think what I&#8217;ll have to do in order to upgrade is to get the source package using apt-get source, unpack it all, and see if I can just replace the 1.4.2.2 code with the 1.2.5.2 code.</p>
<p>I have already pulled the source package down successfully and unpacked it.  It looks like the Ubuntu guys applied many patches to it.  I don&#8217;t know if those patches will work with the new version of code, or if the new version of code contains those patches.  It&#8217;s probably some combination of the two.  This will take some time.  I&#8217;ll post a follow up if I ever get this working.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2007/12/05/latest-mono-on-ubuntu/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Back to Linux</title>
		<link>http://www.warrenfalk.com/blog/2007/12/04/back-to-linux/</link>
		<comments>http://www.warrenfalk.com/blog/2007/12/04/back-to-linux/#comments</comments>
		<pubDate>Tue, 04 Dec 2007 21:51:09 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2007/12/04/back-to-linux/</guid>
		<description><![CDATA[Over two years ago I shed Windows from my desktop and built a Gentoo desktop.  At the time, I was working from home only and had lots of extra time to tweak, compile and troubleshoot.  When I changed jobs again, the lack of time, and compatibility issues with being back in a Microsoft [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ubuntu.com/" title="Ubuntu.com" style="margin: 0pt 0pt 1em 1em; float: right"><img src="http://www.warrenfalk.com/blog/wp-content/uploads/2007/12/icon-ubuntu.png" alt="Ubuntu Icon" /></a>Over two years ago I shed Windows from my desktop and built a Gentoo desktop.  At the time, I was working from home only and had lots of extra time to tweak, compile and troubleshoot.  When I changed jobs again, the lack of time, and compatibility issues with being back in a Microsoft environment at work forced me to abandon my Gentoo and go back to Windows.</p>
<p>Well, I&#8217;m still in a Microsoft environment at work, and I still don&#8217;t have any time, but now I&#8217;m trying to make a go of it again.  This time, however, noting my lack of available tinker time, I&#8217;m going with the flow and have installed Ubuntu.  (I love Gentoo but just don&#8217;t have the time to deal with its idiosyncrasies right now).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2007/12/04/back-to-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>PHP Class Autoload</title>
		<link>http://www.warrenfalk.com/blog/2006/08/31/php-class-autoload/</link>
		<comments>http://www.warrenfalk.com/blog/2006/08/31/php-class-autoload/#comments</comments>
		<pubDate>Fri, 01 Sep 2006 03:50:43 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2006/08/31/php-class-autoload/</guid>
		<description><![CDATA[It&#8217;s been a long time since I posted.  I just wanted to write up a quick post today to say how much I like the new __autoload() function in PHP.  For those not familiar with it, the function gets called when a class is used in PHP that has not been defined.  This gives the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a long time since I posted.  I just wanted to write up a quick post today to say how much I like the new __autoload() function in PHP.  For those not familiar with it, the function gets called when a class is used in PHP that has not been defined.  This gives the developer a chance to allow the script to find the include file it needs and include it to define the class.</p>
<p>The function&#8217;s not all that new, but I&#8217;m just getting around to using it and it&#8217;s changing the way I design my sites.</p>
<p>So now I don&#8217;t use ever need to manually include a file anymore.  I don&#8217;t use any global functions.  I make all my otherwise-global functions static functions of some class and call them that way.  I never have to remember to include the file at the top of the page, I never have to worry about including it twice because of the quirks of include_once(), and I don&#8217;t have a bunch of orphaned include()s at the top of the script anymore from removing a function but leaving it&#8217;s include.</p>
<p>I&#8217;m sure there&#8217;s someone out there that thinks this isn&#8217;t a good idea for whatever reason.  I&#8217;m all ears, but for now, this has made my PHP development much easier.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2006/08/31/php-class-autoload/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Margin of Error</title>
		<link>http://www.warrenfalk.com/blog/2006/07/12/margin-of-error/</link>
		<comments>http://www.warrenfalk.com/blog/2006/07/12/margin-of-error/#comments</comments>
		<pubDate>Wed, 12 Jul 2006 23:11:53 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2006/07/12/margin-of-error/</guid>
		<description><![CDATA[Here, provided for your enjoyment, are the results of a poll displayed, today, on Headline Prime with Erica Hill:
Is It OK To Lie? 
52% lying is never justified
65% lying OK to avoid hurting feelings.
source: AP/IPSOS Poll

I just simply could not resist blogging this.  What does this mean about at least 17% of survey respondents?
To [...]]]></description>
			<content:encoded><![CDATA[<p>Here, provided for your enjoyment, are the results of a poll displayed, today, on Headline Prime with Erica Hill:</p>
<blockquote><p><strong>Is It OK To Lie? </strong></p>
<p><strong>52%</strong> lying is <em>never </em>justified</p>
<p><strong>65%</strong> lying OK to avoid hurting feelings.</p>
<p align="left"><em>source: AP/IPSOS Poll</em></p>
</blockquote>
<p>I just simply could not resist blogging this.  What does this mean about at least 17% of survey respondents?</p>
<p>To me, this means that in addition to the margin of error on polls, we need to be aware that the margin of too-frickin-stupid is at least 17%.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2006/07/12/margin-of-error/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Stupid Standards</title>
		<link>http://www.warrenfalk.com/blog/2006/06/01/stupid-standards/</link>
		<comments>http://www.warrenfalk.com/blog/2006/06/01/stupid-standards/#comments</comments>
		<pubDate>Thu, 01 Jun 2006 23:41:34 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2006/06/01/stupid-standards/</guid>
		<description><![CDATA[
I&#8217;m all for standards in web browsers. But it really bugs me when the standards-compliant behavior is worse than the non-compliant browsers&#8217; behavior. So here we have made a standard protocol, and to follow the protocol means making your browser behave poorly. This isn&#8217;t always the case. Quite often the standard is better, and for [...]]]></description>
			<content:encoded><![CDATA[<p><meta name="qrichtext" content="1" /></p>
<p>I&#8217;m all for standards in web browsers. But it really bugs me when the standards-compliant behavior is worse than the non-compliant browsers&#8217; behavior. So here we have made a standard protocol, and to follow the protocol means making your browser behave poorly. This isn&#8217;t always the case. Quite often the standard is better, and for the most part a standard is almost always better than no standard.</p>
<p>It&#8217;s almost strange how little agreement there is between browser makers on the best way to implement what&#8217;s known as the box model. The box model refers to the dimensions and spacing given to html tags. For instance, a box in html has the main body where the text goes, surrounded by the padding which is filled with the object&#8217;s background color but is otherwise empty of text. That is surrounded by the border, which is surrounded by the margin, which is more empty space which is transparent and collapses against (is allowed to overlap) margins of other elements. The confusion comes when it&#8217;s time to set the width of the element. To which part of the box model does/should the width refer?</p>
<p>The standard apparently says that the width refers to the body part, not the padding. Internet Explorer, on the other hand, says that the width refers to the body plus the padding plus the border. Oddly, in standards compliant mode, IE still says that the width refers to the body plus the padding. IE&#8217;s &#8220;quirks&#8221; way makes the most sense to me. The standard way does not. Why? Because the standard way makes certain things impossible, whereas, IE&#8217;s way does not.</p>
<p>Take for instance a table of data. In one column of the table, you have an input field in each row so that the user can edit information. You want the input field to expand horizontally in size to fill the cell it&#8217;s in. So you set its width to 100% and that works perfectly, except you notice that the text seems to butt up against the left edge too closely, so you add padding to the left (about five pixels (5px) or so). Ah, that seems to work fine in IE, but in Firefox, now, the right edge of your input field has encroached five pixels into the neighboring cell on the right. Why? Because the 100% width you set doesn&#8217;t apply to the padding. So how do you take the padding into account? You can&#8217;t, because you can&#8217;t do math in CSS. Otherwise 100% - 5px would be nice. Or it might be nice to be able to actually specify which part of the box model you want width to affect.</p>
<p>Now IE gets a lot of flack when it doesn&#8217;t adhere to the standard, and for the most part it should. And I like that IE can be switched into &#8220;compliance&#8221; mode with a DOCTYPE declaration (even though it is only a little more compliant). However, I often find that it is the standard which is most annoying.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2006/06/01/stupid-standards/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Development in Variable Width (follow up)</title>
		<link>http://www.warrenfalk.com/blog/2006/05/30/development-in-variable-width-follow-up/</link>
		<comments>http://www.warrenfalk.com/blog/2006/05/30/development-in-variable-width-follow-up/#comments</comments>
		<pubDate>Tue, 30 May 2006 14:45:55 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2006/05/30/development-in-variable-width-follow-up/</guid>
		<description><![CDATA[I am still using variable width for my development.  I still have not noticed any more annoyances besides those I had already noted in my first post (space character too thin, developers that try to line stuff up too often etc.).  I have corrected the space-too-thin problem by editing the font.  I [...]]]></description>
			<content:encoded><![CDATA[<p>I am still using variable width for my development.  I still have not noticed any more annoyances besides those I had already noted in <a href="/blog/2006/05/10/development-in-variable-width/">my first post</a> (space character too thin, developers that try to line stuff up too often etc.).  I have corrected the space-too-thin problem by editing the font.  I took the liberty of merging the monospace versions of the parentheses, angle brackets, and curly braces (I used Bitstream Vera Mono for that) into my favorite proportional font so far (Verdana - like Tahoma, but with wider spacing between letters).</p>
<p>I also fixed some other annoyances, such as the tiny margin on either side of single and double quotes.  This made it very hard to read, and made things such as a single quote, wrapped in double quotes, a very hard thing to decipher.  So I increased that margin significantly.</p>
<p>Then I did a couple more things.  I made the parentheses (that I copied in from the monospace font) to be more concave.  I like that much better.  I also made their footprints wider to compensate.  Then I added a dot in the middle of the zero, and even put a very thin line through the seven, just because.</p>
<p>I even adjusted the kerning between certain characters to make operators easier to read.  I made >>, => and -> spaced closer together, but when I tested them out, I found that my development environment does not seem to take advantage of kerning.  If it had, I might have also added some more operator kerning.</p>
<p>So for anyone who is interested, here is the font: <a href="/blog/wp-content/uploads/2006/05/WF-Programmer.pfb">WF-Programmer Postscript Font file</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2006/05/30/development-in-variable-width-follow-up/feed/</wfw:commentRss>
		</item>
		<item>
		<title>DOM Builder Shortcut Function</title>
		<link>http://www.warrenfalk.com/blog/2006/05/16/dom-builder-shortcut-function/</link>
		<comments>http://www.warrenfalk.com/blog/2006/05/16/dom-builder-shortcut-function/#comments</comments>
		<pubDate>Tue, 16 May 2006 15:40:38 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2006/05/16/dom-builder-shortcut-function/</guid>
		<description><![CDATA[I've created a library to aid in the creation of DOM trees from within Javascript using a json-like syntax.  If you've ever <code>createElement</code>ed or <code>appendChild</code>ed your way to a DOM tree, you know why this might be handy.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a library to aid in the creation of DOM trees from within Javascript using a json-like syntax.  If you&#8217;ve ever <code>createElement</code>ed or <code>appendChild</code>ed your way to a DOM tree, you know why this might be handy.</p>
<p>I like having a standardized DOM, but the language is so incredibly verbose that to build even the most rudimentary DOM tree in javascript takes long line after long line of code.  Take the following HTML excerpt for example:</p>
<pre><code>&lt;div class="player"&gt;
	&lt;img class="icon" src="img/p1.gif"/&gt;
	&lt;p class="playername"&gt;
		&lt;span class="name"&gt;Warren&lt;/span&gt; (next to move)
	&lt;/p&gt;
	&lt;p class="actions"&gt;
		[ &lt;a href="lastmove.php"&gt;last move&lt;/a&gt; ]
	&lt;/p&gt;
	&lt;br class=&#8221;clear&#8221;/&gt;
&lt;/div&gt;
</code></pre>
<p>Now if we want to do this in raw standard DOM javascript code, it will look like this:</p>
<pre><code>var div_player = document.createElement('div');
div_player.className = 'player';
var img_icon = div_player.appendChild(document.createElement('img'));
img_icon.className = 'icon';
img_icon.setAttribute('src', 'img/p1.gif');
var p_playername = div_player.appendChild(document.createElement('p'));
p_playername.className = 'playername';
var span_name = p_playername.appendChild(document.createElement('span'));
span_name.className = 'name';
span_name.appendChild(document.createTextNode('Warren'));
p_playername.appendChild(document.createTextNode(' (next to move)'));
var p_actions = div_player.appendChild(document.createElement('p'));
p_actions.className = 'actions';
p_actions.appendChild(document.createTextNode('[ '));
var a_lastmove = p_actions.appendChild(document.createElement('a'));
a_lastmove.setAttribute('href', 'lastmove.php');
a_lastmove.appendChild(document.createTextNode('last move'));
p_actions.appendChild(document.createTextNode(' ]&#8216;));
br_clear = div_player.appendChild(document.createElement(&#8217;br&#8217;));
br_clear.className = &#8216;clear&#8217;;
</code></pre>
<p>And to be fair, I even took advantage of the <code>.className</code> property available for HTML instead of the DOM&#8217;s more verbose <code>setAttribute</code> method.  The resulting code is much harder to read or debug and is horribly bulky in an environment where code is actually transmitted to the client over a network.</p>
<p>To solve the problem, I created a function called <code>jcreate()</code>.  The function takes a single parameter and returns a single node.  But the range of parameters it can take is its power.  If you pass a string, it will return a DOMTextNode containing that string.  If you pass in an array, the first element of the array becomes the &#8220;tag descriptor,&#8221; and the following elements become the child nodes (becoming parameters, themselves to recursive calls to <code>jcreate()</code>).  The descriptor format is simply &#8220;tagname.classname#idname&#8221; and so it works like this:</p>
<pre><code>jcreate('Warren'); // creates a text node
jcreate(['div']); // creates a div element
jcreate(['div.test#name']); // creates a div element with attributes class=&#8221;test&#8221; and id=&#8221;name&#8221;
jcreate(['div.test#name', 'Warren']); // identical div, but with a child text node
jcreate(['div.test#name, ['p.text', 'Warren'], ['p.subtext', 'super genius']]); // here the div contains two paragraphs
// now let&#8217;s format that with indents
jcreate(
	['div.test#name,
		['p.text', 'Warren'],
		['p.subtext', 'super genius'],
		]);
</code></pre>
<p>In addition to the CSS-like descriptor above, you can also have an attribute descriptor of the format &#8220;@attrname.&#8221;  An attribute is coded then as <code>['@href', '#help']</code> and so a link is coded as <code>['a', ['@href', '#help'], &#8216;click for help&#8217;]</code>.</p>
<p>You can also use DOM nodes in the json-syntax instead of the json-like alternative.  Why would you?  Because it can give you a reference variable to that node that you can use later in your code to change the contents.  It looks like this:</p>
<pre><code>jcreate(
	['div.test#name,
		x = jcreate(['p.text', 'Warren']),
		['p.subtext', 'super genius'],
		]);
	.
	.
	.
	x.className = &#8216;text highlight&#8217;;
</code></pre>
<p>The HTML code at the beginning of this article can be then built dynamically using the following code:</p>
<pre><code>x = jcreate(
['div.player',
	['img.icon', ['@src', 'img/p1.gif']],
	['p.playername', ['span.name', 'Warren'], &#8216; (next to move)&#8217;],
	['p.actions',
		'[ ',
		['a', ['@href', 'lastmove.php'], &#8216;last move&#8217;],
		&#8216; ]&#8217;,
		]
	['br.clear']]);
</code></pre>
<p>The overhead for all this convenience is a few functions:</p>
<pre><code>function create(n,c,i) { var e = document.createElement(n); if(c) e.className = c; if(i) e.id = i; return e; }
function attr(n,v) { var a = document.createAttribute(n); a.value = v; return a; }
function nodecreate(n) { return create(n.tagName, n.className, n.id); }
function text(s) { return document.createTextNode(s); }

function jid(s)
{
	a = s.split('#');
	b = a[0].split(&#8217;.');
	return {tagName: b[0], className: b[1], id: a[1]};
}
function jcreate(j)
{
	if (j.nodeType) return j;
	if (typeof(j) == &#8217;string&#8217;) return text(j);
	if (j[0])
	{
		var id = j[0];
		if (id.substring(0,1) == &#8216;@&#8217;) return attr(id.substring(1), j[1]);
		var e = nodecreate(jid(id));
		for (var i = 1; i &lt; j.length; i++)
		{
			c = jcreate(j[i]);
			c &#038;&#038; ((c.nodeType == 2) ? e.setAttributeNode(c) : e.appendChild(c));
		}
		return e;
	}
	return null;
}
</pre>
<p></code></p>
<p>In the future, I might extend this to allow javascript objects more complex than arrays (<em>more</em> like json syntax).  But so far, I haven&#8217;t really found a good reason to.</p>
<p>I&#8217;ve tested this, so far, in IE, Mozilla, Opera, and Konqueror.  I am confident it works in Safari also but if someone could verify that and comment here, I&#8217;d be grateful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2006/05/16/dom-builder-shortcut-function/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Development in Variable Width</title>
		<link>http://www.warrenfalk.com/blog/2006/05/10/development-in-variable-width/</link>
		<comments>http://www.warrenfalk.com/blog/2006/05/10/development-in-variable-width/#comments</comments>
		<pubDate>Wed, 10 May 2006 14:51:52 +0000</pubDate>
		<dc:creator>Warren Falk</dc:creator>
		
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.warrenfalk.com/blog/2006/05/10/development-in-variable-width/</guid>
		<description><![CDATA[The traditional font family for use in writing computer code is monospace.  Partly this is because monospace was all that was available when computer programming began and remained largely the only choice until relatively recently.  Mostly, though, monospace is used because coders use spacing to line up their code to make it more [...]]]></description>
			<content:encoded><![CDATA[<p>The traditional font family for use in writing computer code is monospace.  Partly this is because monospace was all that was available when computer programming began and remained largely the only choice until relatively recently.  Mostly, though, monospace is used because coders use spacing to line up their code to make it more readable.</p>
<p>I visited a website which listed some favorite programming fonts and described the properties of each font which made it suitable for programming.  All the fonts were monospace as one would assume.  However a commentor on the site said that he began using a variable width font a few years previously and never looked back.</p>
<p>So I&#8217;ve decided to give it a try, and so far, I like it.  Variable width fonts are just easier on the eyes after a while.  Still, you need a decent programming font.  I would like one where the parentheses (and brackets) have wider than average spacing, and similar characters such as zero and the letter &#8216;O&#8217; are distinguishable.  Interestingly, I&#8217;ve found that when I don&#8217;t intentionally line my code up, I actually don&#8217;t want it to line up.  I have found that it is actually easier to read the code when all the characters in the line below do not line up directly under characters in the line above.  My left margin is always clean because the spaces and tabs are always the same size.  For the most part, I don&#8217;t see spacing as a problem.  In my particular font, I wish the space character was bigger, though.  Another &#8220;pro&#8221; is that I can fit a whole lot more on one line without using a small font or a harder to read, narrow font.</p>
<p>There are some &#8220;cons&#8221; though.  That narrow font means that people who wrap their comments to more than one line seem to wrap them way too soon.  And using a variable width font means I will, likewise, tend to wrap mine later than would be readable for a monospace-font developer.  My left margin is always clean, but every once in a great while, I find that code that was intended to line up does not.  However, this hasn&#8217;t been a problem for me.  Coders, I think, often over-format their code, even reducing readability to some degree.</p>
<p>What I would like to see is an editor that can mitigate the downsides of variable width fonts by manipulating the whitespace and recognizing the language syntax.  For instance, the editor should be able to detect when a monospace-font developer adds superfluous whitespace for the purpose of lining up code and then expand the variable width whitespace as necessary to make sure the code is lined up.  Though this can&#8217;t ever be perfect, it can be perfected to a reasonable degree.  Also, comment blocks that are obviously wrapped intentionally could be &#8220;unwrapped&#8221; then &#8220;rewrapped.&#8221;  There are email applications that do this with email text wrapped to the standard 80-or-so lines.  The editor can then automatically wrap comments back to monospace width when saving.</p>
<p>I am currently using KDevelop, KDE&#8217;s development environment, for my C++ development.  I might just try to find out where the editor code is and see if I can implement something like this.  In the mean time, though, I think I&#8217;ll keep experimenting with different variable width fonts anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.warrenfalk.com/blog/2006/05/10/development-in-variable-width/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
