<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.2.2" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: JavaScript date formatting benchmarks</title>
	<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/</link>
	<description>Stay curious!</description>
	<pubDate>Thu, 24 Jul 2008 00:14:48 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.2.2</generator>

	<item>
		<title>By: Five great Perl programming techniques to make your life fun again &#171; Jfree&#8217;s dreaming</title>
		<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-13498</link>
		<author>Five great Perl programming techniques to make your life fun again &#171; Jfree&#8217;s dreaming</author>
		<pubDate>Tue, 09 Oct 2007 01:33:52 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-13498</guid>
		<description>[...] great example is the Behaviour JavaScript library, and the techniques it encourages. Or my own JavaScript date formatting and parsing library, which are not only clearer and simpler to use than their alternatives, but much more powerful and [...]</description>
		<content:encoded><![CDATA[<p>[&#8230;] great example is the Behaviour JavaScript library, and the techniques it encourages. Or my own JavaScript date formatting and parsing library, which are not only clearer and simpler to use than their alternatives, but much more powerful and [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-1789</link>
		<author>Xaprb</author>
		<pubDate>Wed, 13 Sep 2006 12:42:46 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-1789</guid>
		<description>&lt;p&gt;I'm glad to see a good use for it too.  Up till now it's mostly been a solution in search of a problem (the actual product, that is... the "technique demo" is practical itself, from my point of view).&lt;/p&gt;

&lt;p&gt;Writing such an article as this is difficult for me to do gracefully, and I don't always strike the right balance.  If it's hard for me to do that, how much harder is it for the people with longer bars in the graph to gracefully react?  If I were the creator of one of those longer bars, I can only hope I'd receive this article openhandedly.  But I understand if they don't.  Thanks for writing in.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>I&#8217;m glad to see a good use for it too.  Up till now it&#8217;s mostly been a solution in search of a problem (the actual product, that is&#8230; the &#8220;technique demo&#8221; is practical itself, from my point of view).</p>
<p>Writing such an article as this is difficult for me to do gracefully, and I don&#8217;t always strike the right balance.  If it&#8217;s hard for me to do that, how much harder is it for the people with longer bars in the graph to gracefully react?  If I were the creator of one of those longer bars, I can only hope I&#8217;d receive this article openhandedly.  But I understand if they don&#8217;t.  Thanks for writing in.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johan Sundström</title>
		<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-1788</link>
		<author>Johan Sundström</author>
		<pubDate>Wed, 13 Sep 2006 09:52:46 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-1788</guid>
		<description>&lt;p&gt;What not all recognize is that optimality too is a relative term, relative to what you optimize for. Speed, code size and memory footprints being common, I think it's unfortunately often more important to javascript programmers that a neophyte programmer would feel instantly at home with your approach to problem solving, which isn't going to happen with high quality code on an abstraction level where usually only people with a lisp or functional programming background move.&lt;/p&gt;

&lt;p&gt;It's great to see the YUI grid above adopt your approach, and it's been both very rewarding and refreshing reading your articles. Few recognize and actually make good use of the dynamic aspect of javascript like this, and it's very commonplace to be defensive of one's own choices when presented with someone elses. I hope I would have received your article more openhandedly, had I written either of the other comparison targets.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>What not all recognize is that optimality too is a relative term, relative to what you optimize for. Speed, code size and memory footprints being common, I think it&#8217;s unfortunately often more important to javascript programmers that a neophyte programmer would feel instantly at home with your approach to problem solving, which isn&#8217;t going to happen with high quality code on an abstraction level where usually only people with a lisp or functional programming background move.</p>
<p>It&#8217;s great to see the YUI grid above adopt your approach, and it&#8217;s been both very rewarding and refreshing reading your articles. Few recognize and actually make good use of the dynamic aspect of javascript like this, and it&#8217;s very commonplace to be defensive of one&#8217;s own choices when presented with someone elses. I hope I would have received your article more openhandedly, had I written either of the other comparison targets.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jack Slocum&#8217;s Blog &#187; Adding built-in editing support to the Yahoo! UI Extensions Grid</title>
		<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-1768</link>
		<author>Jack Slocum&#8217;s Blog &#187; Adding built-in editing support to the Yahoo! UI Extensions Grid</author>
		<pubDate>Tue, 12 Sep 2006 06:57:38 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-1768</guid>
		<description>&lt;p&gt;[...] format - The date format for the editor. It supports only numeric based date formats, no text. For example, mm/dd/yy, dd.mm.yyyy, yyyy-mm-dd are all valid formats, but MMM dd, yyyy is not. The format is now identical to PHP date() and text is allowed. Credit for that goes to this fantastic date library. This format is for the editor only and doesn&#8217;t affect the rendering of the cell when not in edit mode. Your rendering function can use any date format it wants. [...]&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>[&#8230;] format - The date format for the editor. It supports only numeric based date formats, no text. For example, mm/dd/yy, dd.mm.yyyy, yyyy-mm-dd are all valid formats, but MMM dd, yyyy is not. The format is now identical to PHP date() and text is allowed. Credit for that goes to this fantastic date library. This format is for the editor only and doesn&#8217;t affect the rendering of the cell when not in edit mode. Your rendering function can use any date format it wants. [&#8230;]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Xaprb</title>
		<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-874</link>
		<author>Xaprb</author>
		<pubDate>Wed, 14 Jun 2006 12:41:54 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-874</guid>
		<description>&lt;p&gt;Svend,&lt;/p&gt;

&lt;p&gt;Thanks for writing in.  I wrote:&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;All I’m trying to do is demonstrate the general coding methodology I used, because I often see folks using a much less optimal solution...&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;Even though it sounds like it, I didn't mean to say the other JS date-formatting systems were less optimal.  I was again speaking about general application of code-generation techniques.  I have seen other situations where code generation would be the best solution by far, but a programmer has avoided it, or as I speculate, the idea may not have even occurred to the programmer.&lt;/p&gt;

&lt;p&gt;I agree with you that optimality is hard to gauge.  I disagree that the code complexity is increased.  I think code generation can significantly &lt;strong&gt;decrease&lt;/strong&gt; complexity in many cases.&lt;/p&gt;

&lt;p&gt;If it takes a few lines of code to write something that can make decisions at runtime, that's a lot less complexity than hard-coding all possible decisions.  Once those few lines are debugged and working, every decision is correctly handled at runtime; on the other hand, if every decision is hard-coded, every single one has to be debugged separately.  There are a couple dozen date-formatting characters.  Each one, if hard-coded, is susceptible to typos and edge cases, etc etc.&lt;/p&gt;

&lt;p&gt;The general pattern I'm trying to point out in this comment is how to view the code from a higher level and abstract away from it, writing a machine to solve the tedious stuff.  I think doing that can vastly simplify the code.  Sometimes it's much easier to solve a general problem than dozens of specific ones.&lt;/p&gt;

&lt;p&gt;Back to specifics, your date-formatting code is actually a tiny bit longer than mine.  I stripped comments and empty lines, and took the date-parsing code out of mine, leaving only the formatting code:&lt;/p&gt;

&lt;pre&gt;wc date-functions.js formatDate.js 
  209   719  6128 date-functions.js
  216   927  7439 formatDate.js&lt;/pre&gt;

&lt;p&gt;Again, that doesn't prove anything about code complexity, just like the benchmarks above don't prove anything about optimality, but I think it's impossible to say code generation "significantly increases the complexity of the code" across the board.&lt;/p&gt;

&lt;p&gt;Speed does matter sometimes.  Sometimes it doesn't, and when it doesn't, then other factors -- maintainability, small code size, ease of deployment, etc etc -- are obviously to be striven for.  In every coding project, getting the priorities straight is the first priority.  But if you were writing a JavaScript spreadsheet, which is a hot topic these days, speed would matter hugely.&lt;/p&gt;

&lt;p&gt;Finally, your code isn't the slowest.  The tests aren't apples-to-apples comparisons.  The dojo code is the slowest.  If the dojo code implemented three dozen formatting instructions, it would be enormously slow.&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Svend,</p>
<p>Thanks for writing in.  I wrote:</p>
<blockquote><p>All I’m trying to do is demonstrate the general coding methodology I used, because I often see folks using a much less optimal solution&#8230;</p>
</blockquote>
<p>Even though it sounds like it, I didn&#8217;t mean to say the other JS date-formatting systems were less optimal.  I was again speaking about general application of code-generation techniques.  I have seen other situations where code generation would be the best solution by far, but a programmer has avoided it, or as I speculate, the idea may not have even occurred to the programmer.</p>
<p>I agree with you that optimality is hard to gauge.  I disagree that the code complexity is increased.  I think code generation can significantly <strong>decrease</strong> complexity in many cases.</p>
<p>If it takes a few lines of code to write something that can make decisions at runtime, that&#8217;s a lot less complexity than hard-coding all possible decisions.  Once those few lines are debugged and working, every decision is correctly handled at runtime; on the other hand, if every decision is hard-coded, every single one has to be debugged separately.  There are a couple dozen date-formatting characters.  Each one, if hard-coded, is susceptible to typos and edge cases, etc etc.</p>
<p>The general pattern I&#8217;m trying to point out in this comment is how to view the code from a higher level and abstract away from it, writing a machine to solve the tedious stuff.  I think doing that can vastly simplify the code.  Sometimes it&#8217;s much easier to solve a general problem than dozens of specific ones.</p>
<p>Back to specifics, your date-formatting code is actually a tiny bit longer than mine.  I stripped comments and empty lines, and took the date-parsing code out of mine, leaving only the formatting code:</p>
<pre>wc date-functions.js formatDate.js
  209   719  6128 date-functions.js
  216   927  7439 formatDate.js</pre>
<p>Again, that doesn&#8217;t prove anything about code complexity, just like the benchmarks above don&#8217;t prove anything about optimality, but I think it&#8217;s impossible to say code generation &#8220;significantly increases the complexity of the code&#8221; across the board.</p>
<p>Speed does matter sometimes.  Sometimes it doesn&#8217;t, and when it doesn&#8217;t, then other factors &#8212; maintainability, small code size, ease of deployment, etc etc &#8212; are obviously to be striven for.  In every coding project, getting the priorities straight is the first priority.  But if you were writing a JavaScript spreadsheet, which is a hot topic these days, speed would matter hugely.</p>
<p>Finally, your code isn&#8217;t the slowest.  The tests aren&#8217;t apples-to-apples comparisons.  The dojo code is the slowest.  If the dojo code implemented three dozen formatting instructions, it would be enormously slow.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Svend Tofte</title>
		<link>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-872</link>
		<author>Svend Tofte</author>
		<pubDate>Wed, 14 Jun 2006 08:00:12 +0000</pubDate>
		<guid>http://www.xaprb.com/blog/2006/05/14/javascript-date-formatting-benchmarks/#comment-872</guid>
		<description>&lt;p&gt;Hello, it was interesting seeing this test (though disheartening to see my code was the slowest). I went back to read what this "amazing" technique was, and yes, that's a novel thing to do in JS! :)&lt;/p&gt;

&lt;p&gt;I respect that this is not a diss on anyone (I could have written, and probably have, much worse crap on my own site), but I have to admit, I take objection to these other solutions as "much less optimal". Optimality is a hard thing to gauge, and I would firmly argue that speed is usually not of the essence in JS.&lt;/p&gt;

&lt;p&gt;Dynamic code generation is no simple thing, to be glossed over, and significantly increases the complexity of the code. And for the most part, I do like to keep my JS simple (I've yet to actually use any JS lib, maybe my less, but well).&lt;/p&gt;

&lt;p&gt;But it's nice to be reminded of the fact that code-generation is available, should you choose if suitable (with the client tier becoming more heavy, this is probably already happening all over the world).&lt;/p&gt;</description>
		<content:encoded><![CDATA[<p>Hello, it was interesting seeing this test (though disheartening to see my code was the slowest). I went back to read what this &#8220;amazing&#8221; technique was, and yes, that&#8217;s a novel thing to do in JS! :)</p>
<p>I respect that this is not a diss on anyone (I could have written, and probably have, much worse crap on my own site), but I have to admit, I take objection to these other solutions as &#8220;much less optimal&#8221;. Optimality is a hard thing to gauge, and I would firmly argue that speed is usually not of the essence in JS.</p>
<p>Dynamic code generation is no simple thing, to be glossed over, and significantly increases the complexity of the code. And for the most part, I do like to keep my JS simple (I&#8217;ve yet to actually use any JS lib, maybe my less, but well).</p>
<p>But it&#8217;s nice to be reminded of the fact that code-generation is available, should you choose if suitable (with the client tier becoming more heavy, this is probably already happening all over the world).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
