<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>w3 Programming with .NET &#38; JavaScript</title>
	<atom:link href="http://w3programming.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://w3programming.wordpress.com</link>
	<description>.NET and JavaScript web development</description>
	<lastBuildDate>Thu, 01 Sep 2011 17:56:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='w3programming.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/062ec6ed5994049ffe6f68d8fd620d74?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>w3 Programming with .NET &#38; JavaScript</title>
		<link>http://w3programming.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://w3programming.wordpress.com/osd.xml" title="w3 Programming with .NET &#38; JavaScript" />
	<atom:link rel='hub' href='http://w3programming.wordpress.com/?pushpress=hub'/>
		<item>
		<title>SugarSync vs. DropBox in 2011</title>
		<link>http://w3programming.wordpress.com/2011/08/28/sugarsync-vs-dropbox-in-2011/</link>
		<comments>http://w3programming.wordpress.com/2011/08/28/sugarsync-vs-dropbox-in-2011/#comments</comments>
		<pubDate>Sun, 28 Aug 2011 13:41:56 +0000</pubDate>
		<dc:creator>Kevin K. Nelson</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[Cloud Storage]]></category>
		<category><![CDATA[DropBox]]></category>
		<category><![CDATA[Online Backup]]></category>
		<category><![CDATA[Online Storage]]></category>
		<category><![CDATA[Online Sync]]></category>
		<category><![CDATA[SugarSync]]></category>

		<guid isPermaLink="false">http://w3programming.wordpress.com/?p=50</guid>
		<description><![CDATA[Many of the reviews that I&#8217;ve read online that come up in searches are outdated reviews that no longer have accurate information. So, in an attempt to compare the two in 2011, I&#8217;m doing a very quick overview of the two online storage giants (the two biggest services of this type). I like them both, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=50&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Many of the reviews that I&#8217;ve read online that come up in searches are outdated reviews that no longer have accurate information. So, in an attempt to compare the two in 2011, I&#8217;m doing a very quick overview of the two online storage giants (the two biggest services of this type). I like them both, but I pay for SugarSync, and here&#8217;s why:</p>
<table style="width:100%;">
<tbody>
<tr>
<td>
<h3>DropBox</h3>
<ul>
<li>2 GB Free</li>
<li>250 MB/referral</li>
<li>250 MB tutorial bonus</li>
<li>$9.99/mo for 50 GB</li>
<li>Single Folder Simplicity</li>
<li>Faster Uploading (subjective)</li>
</ul>
</td>
<td>
<h3>SugarSync</h3>
<ul>
<li>5 GB Free</li>
<li>500 MB/referral</li>
<li>750 MB tutorial bonus</li>
<li>$4.99/mo for 30 GB</li>
<li>Single folder simplicity or custom folders</li>
<li>Slower Uploading (subjective)</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>First thing to note is that even after I&#8217;ve gotten quite a few referrals, I&#8217;m only up to a little over 3 GB on DropBox, whereas I started with 5 GB w/ SugarSync. In addition to that, since I paid for the service, my wife (my referrer) and I will both get an extra 10GB just because I got a paid plan, which will help her store her photos on SugarSync without needing a paid plan herself. I&#8217;m not sure if this lasts forever or only while I have a paid account, but regardless, assume each paid plan is 10GB bigger than advertised (check SugarSync for details). Last but not least, after signing up for a free plan, I got e-mails for half off any yearly plan, which allowed me to get 60BG of storage for only $50.00 for a year.</p>
<p>The one category in which SugarSync did not win against DropBox was in the upload speed category.  SugarSync does appear slower, but I have not done enough tests to say that this is always the case, and it was still fast enough to satisfy my needs, so I&#8217;m going with the option that provides me the most free space, the cheapest paid space, and the most configuration options so that I can organize my files the way I want to rather than having to drop them all into a DropBox folder.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/w3programming.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/w3programming.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/w3programming.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/w3programming.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/w3programming.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/w3programming.wordpress.com/50/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/w3programming.wordpress.com/50/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/w3programming.wordpress.com/50/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=50&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://w3programming.wordpress.com/2011/08/28/sugarsync-vs-dropbox-in-2011/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c54c5f65a45e8984e47150a905ba7ea5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kevinknelson</media:title>
		</media:content>
	</item>
		<item>
		<title>A Reason to Stick with Subversion instead of Git</title>
		<link>http://w3programming.wordpress.com/2011/05/13/a-reason-to-stick-with-subversion-instead-of-git/</link>
		<comments>http://w3programming.wordpress.com/2011/05/13/a-reason-to-stick-with-subversion-instead-of-git/#comments</comments>
		<pubDate>Fri, 13 May 2011 18:14:41 +0000</pubDate>
		<dc:creator>Kevin K. Nelson</dc:creator>
				<category><![CDATA[Developer Tools]]></category>
		<category><![CDATA[developer tools]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[source control]]></category>
		<category><![CDATA[subversion]]></category>

		<guid isPermaLink="false">http://w3programming.wordpress.com/?p=44</guid>
		<description><![CDATA[So, all the hype seems to be why you should switch to Git instead of SVN, and there are a LOT of reasons to switch to Git: It&#8217;s Distributed, it&#8217;s reportedly up to 30x lighter weight, easier branching/merging, etc. However, today I came across a reason to stick with Subversion, and that is: Sub-directory branching. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=44&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, all the hype seems to be why you should switch to Git instead of SVN, and there are a LOT of reasons to switch to Git:  It&#8217;s Distributed, it&#8217;s reportedly up to 30x lighter weight, easier branching/merging, etc.   However, today I came across a reason to stick with Subversion, and that is: Sub-directory branching.</p>
<p>So, let&#8217;s say that you&#8217;re a small webshop and you have a custom CMS that you use for all your sites, but you also do some WordPress and BrochureWare sites that have some common files (e.g. CSS reset files, particular folder structure you want all your people to use, etc.).  To simplify your life, you want this all under a single source control repository so that you can &#8220;branch&#8221; your templates for every website, and your structure looks something like this:</p>
<p>/Templates/CustomCMS<br />
/Templates/WordPressTemplate<br />
/Templates/BrochureWareTemplate<br />
/Sites/WordPressImplementation<br />
/Sites/BrochureImplementation<br />
/Sites/CustomCMSImplementation</p>
<p>You can basically think of this as having 3 trunk/master folders in a single repository.  With subversion this is extremely easy because every folder is essentially it&#8217;s own little repository.  When you&#8217;re creating a new custom CMS site, you just branch the /Templates/CustomCMS/ to your Sites/SiteName folder and start working on it.  If you find a bug in the custom CMS and fix it, you can merge it back up into your /Templates/CustomCMS folder.  When you&#8217;re checking out code, you can also check out just a sub-directory rather than having to checkout the entire repository.  With Git, this isn&#8217;t so easy.  A Branch in Git is a branch of the ENTIRE repository.  There are some tools for bringing external repositories into a subtree of a Git repository, but still not for branching off of that directory only.  So, for similar functionality to the above folder layout, you&#8217;d have to have 3 separate repositories with Git.</p>
<p>For larger projects, where you only want a single repository for the entire project, Git seems to win out for me.  However, for these much smaller projects that can kind of all be lumped together easily in a single repository in Subversion, Subversion is the winner.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/w3programming.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/w3programming.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/w3programming.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/w3programming.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/w3programming.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/w3programming.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/w3programming.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/w3programming.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=44&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://w3programming.wordpress.com/2011/05/13/a-reason-to-stick-with-subversion-instead-of-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c54c5f65a45e8984e47150a905ba7ea5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kevinknelson</media:title>
		</media:content>
	</item>
		<item>
		<title>Lambda Expression Optimizations</title>
		<link>http://w3programming.wordpress.com/2010/10/21/lambda-expression-optimizations/</link>
		<comments>http://w3programming.wordpress.com/2010/10/21/lambda-expression-optimizations/#comments</comments>
		<pubDate>Thu, 21 Oct 2010 21:51:43 +0000</pubDate>
		<dc:creator>Kevin K. Nelson</dc:creator>
				<category><![CDATA[.NET Programming (C#)]]></category>
		<category><![CDATA[.NET Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Extension Methods]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">https://w3programming.wordpress.com/2010/10/21/lambda-expression-optimizations/</guid>
		<description><![CDATA[I really love .NET’s ability for extension methods, LINQ, and lambda syntax…I have found that using them can reduce many methods down to a single line, and often make them much clearer at the same time.&#160; As an example, have you ever had to loop through a list and create a delimited string?&#160; For an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=42&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I really love .NET’s ability for extension methods, LINQ, and lambda syntax…I have found that using them can reduce many methods down to a single line, and often make them much clearer at the same time.&#160; As an example, have you ever had to loop through a list and create a delimited string?&#160; For an array of string[], you can simply using String.Join.&#160; However, what if you are looping through an object and concatenating the result of a method call?&#160; E.g.</p>
</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d98b33ae-8527-456f-af5d-56b5c2703feb" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">var</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">myObjs</span><span style="color:#00ffff;">  </span><span style="color:#00ff00;">=</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">new</span><span style="color:#00ffff;"> </span><span style="color:#2b91af;">List</span><span style="color:#00ff00;">&lt;</span><span style="color:#2b91af;">MyObject</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;">();</span><br /> <span style="color:#ff00ff;">var</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ffff;"> </span><span style="color:#00ff00;">=</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">new</span><span style="color:#00ffff;"> </span><span style="color:#2b91af;">StringBuilder</span><span style="color:#00ffff;">();</span><br /> <span style="color:#ff00ff;">foreach</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">var</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">obj</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">in</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">myObjs</span><span style="color:#00ffff;"> )</span><br /> <span style="color:#00ffff;">{</span><br /> <span style="color:#00ffff;">    </span><span style="color:#ff00ff;">if</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Length</span><span style="color:#00ffff;"> </span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;"> </span><span style="color:#ffff00;">0</span><span style="color:#00ffff;"> ) </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Append</span><span style="color:#00ffff;">( </span><span style="color:#ffffff;">&quot;, &quot;</span><span style="color:#00ffff;"> );</span><br /> <span style="color:#00ffff;">    </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Append</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">Decrypt</span><span style="color:#00ffff;">(</span><span style="color:#a5d8b7;">obj</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">BankAccountNumber</span><span style="color:#00ffff;">) );</span><br /> <span style="color:#00ffff;">}</span><br /> <span style="color:#ff00ff;">return</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">ToString</span><span style="color:#00ffff;">();</span></div>
</p></div>
</p></div>
<p>This is some bogus code…the list would always be empty…but assume myObjs actually does contain a list of items in it.&#160; We could use an extension method that would allow us to build a delimited string from ANY enumerable list of objects or strings.</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9c7ad721-ec85-4ca3-840b-85d1793851f4" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#00ffff;"></span><span style="color:#ff00ff;">public</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">static</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">class</span><span style="color:#00ffff;"> </span><span style="color:#2b91af;">GenericExtensions</span><br /> <span style="color:#00ffff;">{</span><br />     <span style="color:#00ffff;"></span><span style="color:#ff00ff;">public</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">static</span><span style="color:#00ffff;"> </span><span style="color:#2b91af;">String</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">Implode</span><span style="color:#00ff00;">&lt;</span><span style="color:#a5d8b7;">T</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">this</span><span style="color:#00ffff;"> </span><span style="color:#ffff9f;">IEnumerable</span><span style="color:#00ff00;">&lt;</span><span style="color:#00ffff;">T</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">list</span><span style="color:#00ffff;">, </span><span style="color:#2b91af;">String</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">delimiter</span><span style="color:#00ffff;">, </span><span style="color:#00ff00;">Func&lt;</span><span style="color:#00ffff;">T,</span><span style="color:#2b91af;">String</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">func</span><span style="color:#00ffff;"> )</span><br />     <span style="color:#00ffff;">{</span><br />         <span style="color:#00ffff;"></span><span style="color:#ff00ff;">var</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ffff;"> </span><span style="color:#00ff00;">=</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">new</span><span style="color:#00ffff;"> </span><span style="color:#2b91af;">StringBuilder</span><span style="color:#00ffff;">();</span><br />         <span style="color:#00ffff;"></span><span style="color:#ff00ff;">foreach</span><span style="color:#00ffff;">( T </span><span style="color:#a5d8b7;">item</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">in</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">list</span><span style="color:#00ffff;"> )</span><br />         <span style="color:#00ffff;">{</span><br />             <span style="color:#00ffff;"></span><span style="color:#ff00ff;">if</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Length</span><span style="color:#00ffff;"> </span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;"> </span><span style="color:#ffff00;">0</span><span style="color:#00ffff;"> ) </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Append</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">delimiter</span><span style="color:#00ffff;"> );</span><br />             <span style="color:#00ffff;"></span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Append</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">func</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">item</span><span style="color:#00ffff;"> ) );</span><br />         <span style="color:#00ffff;">}</span><br />         <span style="color:#00ffff;"></span><span style="color:#ff00ff;">return</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">builder</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">ToString</span><span style="color:#00ffff;">();</span><br />     <span style="color:#00ffff;">}</span><br /> <span style="color:#00ffff;">}</span></div>
</p></div>
</p></div>
</p>
<p>The above extension method would allow us to change the first code example to the following:</p>
<div style="display:inline;float:none;margin:0;padding:0;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:e17dc3ee-8749-4b56-9563-edfe8cae6482" class="wlWriterEditableSmartContent">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">var</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">myObjs</span><span style="color:#00ffff;">  </span><span style="color:#00ff00;">=</span><span style="color:#00ffff;"> </span><span style="color:#ff00ff;">new</span><span style="color:#00ffff;"> </span><span style="color:#2b91af;">List</span><span style="color:#00ff00;">&lt;</span><span style="color:#2b91af;">MyObject</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;">();</span><br /> <span style="color:#ff00ff;">return</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">myObjs</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Implode</span><span style="color:#00ffff;">( </span><span style="color:#ffffff;">&quot;, &quot;</span><span style="color:#00ffff;">, </span><span style="color:#a5d8b7;">x</span><span style="color:#00ffff;"> </span><span style="color:#00ff00;">=&gt;</span><span style="color:#00ffff;"> </span><span style="color:#a5d8b7;">Decrypt</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">x</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">BankAccountNumber</span><span style="color:#00ffff;"> ) );</span></div>
</p></div>
</p></div>
<p>And the best thing, is this can be used with pretty much any enumerable list/array, so you only have to write it once.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/w3programming.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/w3programming.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/w3programming.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/w3programming.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/w3programming.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/w3programming.wordpress.com/42/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/w3programming.wordpress.com/42/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/w3programming.wordpress.com/42/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=42&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://w3programming.wordpress.com/2010/10/21/lambda-expression-optimizations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c54c5f65a45e8984e47150a905ba7ea5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kevinknelson</media:title>
		</media:content>
	</item>
		<item>
		<title>Refactoring: Leveraging Generics, Extensions, and LINQ to clean up</title>
		<link>http://w3programming.wordpress.com/2010/08/18/refactoring-leveraging-generics-extensions-and-linq/</link>
		<comments>http://w3programming.wordpress.com/2010/08/18/refactoring-leveraging-generics-extensions-and-linq/#comments</comments>
		<pubDate>Wed, 18 Aug 2010 17:06:33 +0000</pubDate>
		<dc:creator>Kevin K. Nelson</dc:creator>
				<category><![CDATA[.NET Programming (C#)]]></category>
		<category><![CDATA[.NET Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Generic Classes]]></category>
		<category><![CDATA[Generics]]></category>
		<category><![CDATA[Lambda]]></category>
		<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[ReSharper]]></category>

		<guid isPermaLink="false">http://w3programming.wordpress.com/?p=27</guid>
		<description><![CDATA[Browsing through my current project, I ran across some code similiar to this (but much longer): var myInt=3; if( someCondition &#38;&#38; someOtherCondition&#38;&#38; (myInt==1&#124;&#124;myInt==3&#124;&#124;myInt==5) ) { doSomething(); } I hate really long if()s. So, this lead me to think along the lines that there&#8217;s got to be a better way to do this. 3 separate statements [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=27&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Browsing through my current project, I ran across some code similiar to this (but much longer):</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:d13b7d94-631b-4cc5-899f-6c54d9baea20" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">var</span><span style="color:#a5d8b7;"> myInt</span><span style="color:#00ff00;">=</span><span style="color:#ffff00;">3</span><span style="color:#00ffff;">;</span><br />
<span style="color:#ff00ff;">if</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">someCondition</span><span style="color:#00ff00;"> &amp;&amp; </span><span style="color:#a5d8b7;">someOtherCondition</span><span style="color:#00ff00;">&amp;&amp;</span><span style="color:#00ffff;"> (</span><span style="color:#a5d8b7;">myInt</span><span style="color:#00ff00;">==</span><span style="color:#ffff00;">1</span><span style="color:#00ff00;">||</span><span style="color:#a5d8b7;">myInt</span><span style="color:#00ff00;">==</span><span style="color:#ffff00;">3</span><span style="color:#00ff00;">||</span><span style="color:#a5d8b7;">myInt</span><span style="color:#00ff00;">==</span><span style="color:#ffff00;">5</span><span style="color:#00ffff;">) )</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#a5d8b7;">doSomething</span><span style="color:#00ffff;">();</span><br />
<span style="color:#00ffff;">}</span></div>
</div>
</div>
<p>I hate really long if()s. So, this lead me to think along the lines that there&#8217;s got to be a better way to do this. 3 separate statements all checking the value of a single variable is excessive in my mind. I wanted the code to read like this to simplify the conditions and make them more readable:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:219176d6-b2da-4a3f-a45c-4d11cd293eb1" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">var </span><span style="color:#a5d8b7;">myInt</span><span style="color:#00ff00;">=</span><span style="color:#ffff00;">3</span><span style="color:#00ffff;">;</span><br />
<span style="color:#ff00ff;">if</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">someCondition</span><span style="color:#00ff00;"> &amp;&amp;</span><span style="color:#a5d8b7;"> someOtherCondition </span><span style="color:#00ff00;">&amp;&amp; </span><span style="color:#a5d8b7;">myInt</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">IsIn</span><span style="color:#00ffff;">(</span><span style="color:#ffff00;">1</span><span style="color:#00ffff;">,</span><span style="color:#ffff00;">3</span><span style="color:#00ffff;">,</span><span style="color:#ffff00;">5</span><span style="color:#00ffff;">) )</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#a5d8b7;">doSomething</span><span style="color:#00ffff;">();</span><br />
<span style="color:#00ffff;">}</span></div>
</div>
</div>
<p>In many other languages the above would be impossible, we&#8217;d have to write IsIn(myInt,1,3,5) which isn&#8217;t as intuitive to read. However, as of version 3 or 3.5, .NET allows us to write extension methods so that we can write the code exactly as I outline above. In order to write an extension method, you have to have 3 things: a static class, a static method, and the first parameter of the static method needs to have the &#8220;this&#8221; keyword before the parameter and be of the type that you wish to extend. So, to create a method that does exactly what&#8217;s shown above, we could do it like so:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:9798ce89-275a-45b3-afb8-b5ec9333dfb8" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">public </span><span style="color:#ff00ff;">static </span><span style="color:#ff00ff;">class </span><span style="color:#2b91af;">Int32Extensions</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">public</span><span style="color:#ff00ff;"> static </span><span style="color:#ff00ff;">bool </span><span style="color:#a5d8b7;">IsIn</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">this</span><span style="color:#2b91af;"> Int32 </span><span style="color:#a5d8b7;">number</span><span style="color:#00ffff;">, </span><span style="color:#ff00ff;">params</span><span style="color:#2b91af;"> Int32</span><span style="color:#00ffff;">[] </span><span style="color:#a5d8b7;">values</span><span style="color:#00ffff;"> )</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">foreach</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">var</span><span style="color:#a5d8b7;"> value </span><span style="color:#ff00ff;">in </span><span style="color:#a5d8b7;">values</span><span style="color:#00ffff;"> )</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">if</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">number</span><span style="color:#00ff00;">==</span><span style="color:#a5d8b7;">value</span><span style="color:#00ffff;"> ) </span><span style="color:#ff00ff;">return</span><span style="color:#ff00ff;"> true</span><span style="color:#00ffff;">;</span><br />
<span style="color:#00ffff;">}</span><br />
<span style="color:#ff00ff;">return</span><span style="color:#ff00ff;"> false</span><span style="color:#00ffff;">;</span><br />
<span style="color:#00ffff;">}</span><br />
<span style="color:#00ffff;">}</span></div>
</div>
</div>
<p>Using the &#8220;this&#8221; keyword in a static method and class allows you to use the method as-if it were part of the Int32 class. If you&#8217;re unfamiliar with it, the second parameter also has some magic with the &#8220;params&#8221; keyword. My co-workers told me about this while I was working on this method which saved me from writing overloads for 2, 3, and 4 parameters. The params keyword can be used as the last parameter of a method to allow an unspecified number of parameters to be sent in as an array of a specific type, which keeps you from having to do: myInt.IsIn( new[]{1,3,5} ). You can look into it further if you like by <a href="http://msdn.microsoft.com/en-us/library/w5zay9db%28VS.71%29.aspx" target="_blank">clicking here</a>.</p>
<p>So, this method leverages extension methods and will let you assign any number of parameters to check against, which is great. However, the problem with this is that it&#8217;s only going to be able to be used by the Int32 object. The result would be that if I wanted to do the same thing for other types, I would need to write an overload for them. So, I&#8217;d end up with overloaded methods for Int64, Decimal, String, and maybe a number of my Enums, etc. I could easily end up with 10 or more overloaded methods that all do exactly the same thing. On the other hand I could write the extension method so that it extends object instead of Int32, but then my code would no longer be strongly typed, and it could result in unforeseen runtime issues. So, this brings us to Generics. If we change this method as follows, it can be used by ANY object and still require all parameters to be of the same type as the object we are comparing against:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:feac1047-af2b-42aa-ba94-b4540bfabebe" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">public</span><span style="color:#ff00ff;"> static </span><span style="color:#ff00ff;">class</span><span style="color:#2b91af;"> GenericExtensions</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">public </span><span style="color:#ff00ff;">static </span><span style="color:#ff00ff;">bool</span><span style="color:#a5d8b7;"> IsIn</span><span style="color:#00ff00;">&lt;</span><span style="color:#a5d8b7;">T</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">this</span><span style="color:#00ffff;"> T </span><span style="color:#a5d8b7;">instance</span><span style="color:#00ffff;">, </span><span style="color:#ff00ff;">params</span><span style="color:#00ffff;"> T[] </span><span style="color:#a5d8b7;">values</span><span style="color:#00ffff;"> )</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">foreach</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">var</span><span style="color:#a5d8b7;"> value </span><span style="color:#ff00ff;">in</span><span style="color:#a5d8b7;"> values</span><span style="color:#00ffff;"> )</span></div>
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#00ffff;">     {</span><br />
<span style="color:#ff00ff;">if</span><span style="color:#00ffff;">( </span><span style="color:#a5d8b7;">instance</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Equals</span><span style="color:#00ffff;">(</span><span style="color:#a5d8b7;">value</span><span style="color:#00ffff;">) ) </span><span style="color:#ff00ff;">return</span><span style="color:#ff00ff;"> true</span><span style="color:#00ffff;">;</span><br />
<span style="color:#00ffff;">}</span><br />
<span style="color:#ff00ff;">return </span><span style="color:#ff00ff;">false</span><span style="color:#00ffff;">;</span><br />
<span style="color:#00ffff;">}</span><br />
<span style="color:#00ffff;">}</span></div>
</div>
</div>
<p>The &#8220;T&#8221; generic here: IsIn&lt;T&gt;( this T instance ) makes this extension method available to ALL objects. By using &#8220;params T[] values&#8221; we are requiring that the parameters passed into the method for comparison are of the same type as the object being compared against, keeping us from runtime issues where things would be equal but aren&#8217;t because they&#8217;re not the same type. We now have a very powerful method, and if you are working in the same namespace or use the namespace in your file, you&#8217;ll see the IsIn method show up in your Intellisense in Visual Studio. So, this method is now extremely re-usable and can make multiple conditional checks against the same variable much more readable.</p>
<p>However, there is one more thing that can make this code even cleaner. I was quite happy with the above method and would have stopped there. However, I have Resharper installed, and it was underlining the foreach. So, I hovered over it, and it was telling me to change it to a LINQ expression. So, having learned to trust ReSharper a bit, I decided to click the little lightbulb icon next to it and let it reformat my method, which changed my code to this:</p>
<div id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:8e64ebed-572f-4fb3-b62e-50c03d548bb1" class="wlWriterEditableSmartContent" style="display:inline;float:none;margin:0;padding:0;">
<div style="border:#000080 1px solid;color:#000;font-family:'Courier New', Courier, Monospace;font-size:10pt;">
<div style="background-color:#000000;max-height:300px;overflow:auto;white-space:nowrap;padding:2px 5px;"><span style="color:#ff00ff;">public </span><span style="color:#ff00ff;">static</span><span style="color:#ff00ff;"> class</span><span style="color:#2b91af;"> GenericExtensions</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">public</span><span style="color:#ff00ff;"> static </span><span style="color:#ff00ff;">bool </span><span style="color:#a5d8b7;">IsIn</span><span style="color:#00ff00;">&lt;</span><span style="color:#a5d8b7;">T</span><span style="color:#00ff00;">&gt;</span><span style="color:#00ffff;">( </span><span style="color:#ff00ff;">this</span><span style="color:#00ffff;"> T </span><span style="color:#a5d8b7;">instance</span><span style="color:#00ffff;">, </span><span style="color:#ff00ff;">params</span><span style="color:#00ffff;"> T[] </span><span style="color:#a5d8b7;">values</span><span style="color:#00ffff;"> )</span><br />
<span style="color:#00ffff;">{</span><br />
<span style="color:#ff00ff;">return</span><span style="color:#a5d8b7;"> values</span><span style="color:#00ff00;">.</span><span style="color:#a5d8b7;">Contains</span><span style="color:#00ffff;">(</span><span style="color:#a5d8b7;">instance</span><span style="color:#00ffff;">);</span><br />
<span style="color:#00ffff;">}</span><br />
<span style="color:#00ffff;">}</span></div>
</div>
</div>
<p>I love ReSharper&#8230;it&#8217;s the only application I&#8217;ve ever had that actually taught me programming tips &amp; tricks on the fly. As a result, I have an extension method that uses Generics so that it can be used by ANY object, using the params keyword so that I can pass in any number of parameters to compare against, and using LINQ so that my method is extremely short and readable.</p>
<p>Now, there are other ways to skin this cat that don&#8217;t involve coding an IsIn method, such as: &#8220;new[]{1,3,5}.Contains(myInt)&#8221;, but I think that the IsIn adds quite a bit to readability over doing that.</p>
<p>Anyway, hopefully this little tidbit will help someone.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/w3programming.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/w3programming.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/w3programming.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/w3programming.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/w3programming.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/w3programming.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/w3programming.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/w3programming.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=27&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://w3programming.wordpress.com/2010/08/18/refactoring-leveraging-generics-extensions-and-linq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c54c5f65a45e8984e47150a905ba7ea5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kevinknelson</media:title>
		</media:content>
	</item>
		<item>
		<title>Creating a Template-able Calendar with jQuery&#8217;s jBind Plugin</title>
		<link>http://w3programming.wordpress.com/2009/07/17/creating-a-template-able-calendar-with-jquerys-jbind-plugin/</link>
		<comments>http://w3programming.wordpress.com/2009/07/17/creating-a-template-able-calendar-with-jquerys-jbind-plugin/#comments</comments>
		<pubDate>Fri, 17 Jul 2009 18:37:06 +0000</pubDate>
		<dc:creator>Kevin K. Nelson</dc:creator>
				<category><![CDATA[JavaScript Programming]]></category>
		<category><![CDATA[Calendar]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jBind]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://w3programming.wordpress.com/?p=15</guid>
		<description><![CDATA[So, when we started talking about our JavaScript coding standards for the project I&#8217;m working on, I pushed to &#8220;find a template system that didn&#8217;t use string concatenation&#8221;. One of my pet-peeves about most JavaScript code is the constant use of string concatenation. Having a template that separates your coding from your HTML, and having [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=15&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, when we started talking about our JavaScript coding standards for the project I&#8217;m working on, I pushed to &#8220;find a template system that didn&#8217;t use string concatenation&#8221;.  One of my pet-peeves about most JavaScript code is the constant use of string concatenation.  Having a template that separates your coding from your HTML, and having your HTML &#8220;readable&#8221; is a major plus, especially if you have designers working on the project with you.  So, anyway, since we were using JQuery, one of the other guys found the jBind plugin, which looked exactly like what I was looking for.  So, I tried it out for our calendar system, and I have to say that jBind is pretty stinking cool.</p>
<p>jBind can work with objects and arrays to build out the template.  So, we needed a calendar object with properties, such as MonthName, and an array of Weeks.  Each Week, then, needed to be an object with an array of Days, which are in turn their own object with properties such as &#8220;DateNumber&#8221;, &#8220;DayOfWeek&#8221;, and other properties that might be used within the calendar HTML to display or help locate specific days.</p>
<p>I&#8217;ve stripped down the below code a little bit, but left in namespacing and the arrays for Days of Week and Months so that you can see more of the functionality working and understand it.  The below calendar code is technically not dependent on any JavaScript library, but it is optimal for use with jQuery&#8217;s jBind Templating plugin.</p>
<pre style="background-color:#CCCCCC;">var w3              = new Object();
w3.Calendar         = new Object();
w3.Calendar.Arrays  = new Object();

w3.Calendar.Arrays.Days = [
  {Abbr: "Sun", Name: "Sunday"},
  {Abbr: "Mon", Name: "Monday"},
  {Abbr: "Tue", Name: "Tuesday"},
  {Abbr: "Wed", Name: "Wednesday"},
  {Abbr: "Thu", Name: "Thursday"},
  {Abbr: "Fri", Name: "Friday"},
  {Abbr: "Sat", Name: "Saturday"}
];
w3.Calendar.Arrays.Months = [
  {Abbr: "Jan", Name:"January"},
  {Abbr: "Feb", Name:"February"},
  {Abbr: "Mar", Name:"March"},
  {Abbr: "Apr", Name:"April"},
  {Abbr: "May", Name:"May"},
  {Abbr: "Jun", Name:"June"},
  {Abbr: "Jul", Name:"July"},
  {Abbr: "Aug", Name:"August"},
  {Abbr: "Sep", Name:"September"},
  {Abbr: "Oct", Name:"October"},
  {Abbr: "Nov", Name:"November"},
  {Abbr: "Dec", Name:"December"}
];

w3.Calendar.Week = function( weekNumber ) {
  this.WeekNumber = weekNumber;
  this.Days       = new Array();
}
w3.Calendar.Day = function( cssClass, week, date ) {
  this.CssClass       = cssClass;
  this.DateNumber     = date == null ? "" : date.getDate();
  this.DayOfWeek      = date == null ? "" : date.getDay();
  this.DayOfWeekName  = date == null ? "" : w3.Calendar.Arrays.Days[this.DayOfWeek].Name;
  this.DayOfWeekAbbr  = date == null ? "" : w3.Calendar.Arrays.Days[this.DayOfWeek].Abbr;
  this.WeekNumber     = week == null ? "" : week.WeekNumber;
  // other properties you might want to stick in template such as IsWeekend, etc.
}
w3.Calendar.Builder = {
  getData: function(year, month) {
    this.jsMonth            = month-1; // JavaScript uses 0 for Jan, etc., so subtract 1
    this.Data               = new Object();
    this.Data.Weeks         = new Array();
    this.Data.Year          = year;
    this.Data.MonthNumber   = month;
    this.Data.MonthAbbr     = w3.Calendar.Arrays.Months[this.jsMonth].Abbr;
    this.Data.MonthName     = w3.Calendar.Arrays.Months[this.jsMonth].Name;

    var oCounter        = new Date( year, this.jsMonth, 1 );
    var iWeekCounter    = 1;
    var CurrentWeek     = new w3.Calendar.Week( iWeekCounter );

    // fill up week with empty days until day matches day for 1st of month
    for( var i=0; i != oCounter.getDay(); i++ ) {
      CurrentWeek.Days.push( new w3.Calendar.Day( "empty", null, null ) );
    }

    // fill up week with days.  Start new week on Sundays
    while( oCounter.getMonth() == this.jsMonth ) {
      CurrentWeek.Days.push( new w3.Calendar.Day( "date", CurrentWeek, oCounter ) );
      oCounter.setDate( oCounter.getDate() + 1 );

      if( oCounter.getDay() == 0 ) {
        this.Data.Weeks.push( CurrentWeek );
        CurrentWeek = new w3.Calendar.Week( ++iWeekCounter );
      }
    }

    // fill up last week with empty days until Saturday is filled
    while( oCounter.getDay() != 0 ) {
      CurrentWeek.Days.push( new w3.Calendar.Day( "empty", null, null ) );
      oCounter.setDate( oCounter.getDate() + 1 );
    }

    this.Data.Weeks.push( CurrentWeek );
    return this.Data;
  }
}</pre>
<p>These properties can then be used as needed in the template.  So, here is the beauty of jBind.  We put the following HTML at the bottom of our page inside a hidden div.  Notice how simple and clean the HTML is:</p>
<pre style="background-color:#CCCCCC;">&lt;div id='Template' style='display:none;'&gt;
&lt;!--data--&gt;
&lt;div class='header'&gt;{MonthName}, {Year}&lt;/div&gt;
&lt;table class='calendar'&gt;
   &lt;thead&gt;
     &lt;th class='week'&gt;&amp;nbsp;&lt;/th&gt;&lt;th&gt;S&lt;/th&gt;&lt;th&gt;M&lt;/th&gt;&lt;th&gt;T&lt;/th&gt;&lt;th&gt;W&lt;/th&gt;&lt;th&gt;Th&lt;/th&gt;&lt;th&gt;F&lt;/th&gt;&lt;th&gt;S&lt;/th&gt;
   &lt;/thead&gt;
   &lt;tbody&gt;
     &lt;!--Weeks--&gt;
       &lt;tr&gt;&lt;td class='week'&gt;{WeekNumber}&lt;/td&gt;
       &lt;!--Days--&gt;
         &lt;td class='{CssClass}' DayOfWeek='{DayOfWeekAbbr}'&gt;{DateNumber}&lt;/td&gt;
       &lt;!--Days--&gt;
       &lt;/tr&gt;
     &lt;!--Weeks--&gt;
   &lt;/tbody&gt;
&lt;/table&gt;
&lt;!--data--&gt;
&lt;/div&gt;</pre>
<p>So, now we have a template and a way to create a calendar object to populate it.  All we have to do now is combine the two, which can be done easily.  However, now, obviously our code becomes dependent on two JavaScript files, the jQuery core, and the jBind plugin.  Once you have those two files linked, you can plugin your calendar code to your template like so:</p>
<pre style="background-color:#CCCCCC;">$(document).ready( function() {
  var data        = w3.Calendar.Builder.getData( 2009, 5 );
  var template    = $('#Template').html();
  var formatted   = $(template).bindTo(data);
  $('#WhereToPlaceHTML').html( formatted );
} );</pre>
<p>Using this approach, you have an extremely flexible calendar system that can be built with any template.  Then, you just run your script to populate/manipulate the calendar as needed thereafter.</p>
<h3>Benchmarking?</h3>
<p>Now, I haven&#8217;t done any benchmarking to see if the above is any slower than traditional string-concatenated templates.  To build an entire year of calendars on a single page was taking about 6 seconds in FireFox and 10 seconds in IE, which is a bit slower than I&#8217;d like, but I&#8217;m not sure JavaScript would be any faster using string concatenation, and with the ease of use, and flexibility provided by the template engine, I consider it well worth it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/w3programming.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/w3programming.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/w3programming.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/w3programming.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/w3programming.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/w3programming.wordpress.com/15/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/w3programming.wordpress.com/15/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/w3programming.wordpress.com/15/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=15&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://w3programming.wordpress.com/2009/07/17/creating-a-template-able-calendar-with-jquerys-jbind-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c54c5f65a45e8984e47150a905ba7ea5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kevinknelson</media:title>
		</media:content>
	</item>
		<item>
		<title>Which JavaScript Framework to Use? (Dojo, JQuery, Prototype)</title>
		<link>http://w3programming.wordpress.com/2009/07/03/which-javascript-framework-to-use-dojo-jquery-prototype/</link>
		<comments>http://w3programming.wordpress.com/2009/07/03/which-javascript-framework-to-use-dojo-jquery-prototype/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 22:55:25 +0000</pubDate>
		<dc:creator>Kevin K. Nelson</dc:creator>
				<category><![CDATA[JavaScript Programming]]></category>
		<category><![CDATA[dojo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://w3programming.wordpress.com/?p=3</guid>
		<description><![CDATA[Okay, so I&#8217;ve had two projects in the last year, and in both cases, I&#8217;ve been largely responsible for the UI JavaScript development. In the first project, prototype was chosen before I joined the project, and in the second project, which is ongoing, it was opted to use the JQuery framework (even though I wanted [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=3&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Okay, so I&#8217;ve had two projects in the last year, and in both cases, I&#8217;ve been largely responsible for the UI JavaScript development.  In the first project, prototype was chosen before I joined the project, and in the second project, which is ongoing, it was opted to use the JQuery framework (even though I wanted Dojo <img src='http://s0.wp.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  ), because the designers liked JQuery and didn&#8217;t like that dojo added attributes into tags that don&#8217;t actually exist and thus throw warnings when running the code through an XHTML validator (turns out, we ended up adding attributes to tags anyway to handle a JQuery tree control&#8230;but oh well).  Finally, on my own personal projects, I&#8217;ve been working to use Dojo.</p>
<p>In any case, having gotten a modicum of experience in these 3 frameworks, I figured I&#8217;d throw out my two cents for anyone looking into JavaScript frameworks and trying to decide what to use.</p>
<h4>Prototype</h4>
<p>Prototype is a great object-oriented <strong>base-code</strong>, with features that are very useful for building your own code.  It has some really handy methods, at least one of which I can&#8217;t live without: Function.prototype.bind (look it up).  However, overall, even with script.aculo.us, it just seemed like we were always re-inventing the wheel.  That&#8217;s great, as I love the experience of creating all my own tools, but with deadlines, etc., you end up with a wooden wheel when you really want a high performance radial tire.  So, my opinion is that if you&#8217;re going to use prototype, use it in conjunction with another library that has more pre-built standard features.  Or just take the useful features of prototype and add just those parts to the other library.</p>
<h4>JQuery</h4>
<p>JQuery is a step up from prototype in terms of it&#8217;s pre-built features.  With the JQuery UI, you have access to a lot of common functionality features: Accordian, Dialog, ProgressBar, DatePicker.  You also have ways to easily implement things like drag/drop and making a list sortable.  There are also a lot of really nice plugins that you can use in conjunction with JQuery.  So, JQuery is a great library to work with.  If you want to use JQuery and like how they did things, then I don&#8217;t think you can really go wrong with it.</p>
<p>That said, I did end up adding an additional method to handle class inheritance, and I borrowed the Function.prototype.bind that Prototype uses and is extremely handy if you ever pass functions that are within a class to an event handler.  However, these things were easy to add and I don&#8217;t really consider them as a detraction from JQuery.  Really, about the only problem I have with JQuery is that I have a $(document).ready() with about 50 calls in it to get it to make conversions on the HTML, whereas, I would really like it if JQuery had a parser that would automatically convert HTML on the page based on tag attributes, which leads me to Dojo.</p>
<h4>Dojo</h4>
<p>I have to say that I really love the dojo framework.  It is the behemoth of JavaScript frameworks, with more extensions that come with it by default then you&#8217;ll probably ever need.  Additionally, since it only loads up the extensions that you need (on-demand) you have access to EVERYTHING without weighing down your users with the entire framework of code.  However, I love dojo for a completely different reason, and thats for its parseOnLoad ability.  You simply specify an attribute in a tag like so: &lt;tag dojoType=&#8221;namespace.to.type&#8221;&gt;, and add any other attributes applicable to that type, and dojo will automatically parse the page, load the needed JavaScript files for that type (again, on-demand), and convert the tag to that type using the attributes that you specified.  This allows your HTML and CSS to define the attributes of what is displayed instead of having to assign those values via JavaScript in an onload handler like you would with JQuery.  I consider this to be a much more natural way of defining things in a web page.</p>
<p>To try to explain this, though, an example is much better.  So, let&#8217;s say we want a tooltip that can display HTML formatted text rather than just the text tooltip we get with the title attribute.  Well, we can do this quite easily, and the greater part is that we can do it with <strong>ZERO</strong> Javascript coding, like so:</p>
<pre style="background-color:#FFFFFF;border:1px black solid;padding:10px;">&lt;a <span style="color:red;">id="<span style="color:blue;">phrase</span>"</span>&gt;Hello World&lt;/a&gt;
&lt;div <span style="color:red;">dojoType="dijit.Tooltip" connectId="<span style="color:blue;">phrase</span>"</span>&gt;
&lt;b&gt;a phrase that is apparently impossible to program without&lt;/b&gt;
&lt;/div&gt;</pre>
<p>If Dojo is set to parse automatically, it will parse the above, find the dojoType=&#8217;dijit.Tooltip&#8217; tag, convert it to a tooltip popup and hide it from the browser display.  Then, the connectId=&#8221;phrase&#8221; tells it to assign onmouseover and onmouseout event handlers to the tag with the id &#8220;phrase&#8221;&#8230;presto, no JavaScript in your HTML at all, no need to call anything onload&#8230;it&#8217;s non-programmer friendly because it&#8217;s just HTML, and it&#8217;s programmer friendly because there is a nice separation between the code and HTML.</p>
<p>Now, I was originally going to finish this block by talking about how big of a file size dojo has, and how it was the heaviest framework of the bunch to somewhat show it&#8217;s negatives.  However, then I took a closer look at JQuery.  Once you add JQuery-UI, which for my own use is a must&#8230;JQuery doesn&#8217;t really provide much (if any) bandwidth savings.  Combine that with Dojo&#8217;s ability for on-demand script, so that you&#8217;re only loading what you need, when you need it&#8230;and it just comes across as dojo being the all-around winner, at least in my book.  Additionally, if you do use particular extensions on a regular basis, you can compile these into a single file and gzip compress it for additional savings.</p>
<h4>Note on GZip Compression</h4>
<p>In the case of either JQuery or Dojo, make sure that you do take advantage of gzip compression.  If you use something like the Google CDN, then google takes care of this for you.  However, if you&#8217;re using a local copy, make sure to take a look into getting compressed files, or how to compress them using server-side script for custom solutions.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/w3programming.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/w3programming.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/w3programming.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/w3programming.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/w3programming.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/w3programming.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/w3programming.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/w3programming.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=w3programming.wordpress.com&amp;blog=8427206&amp;post=3&amp;subd=w3programming&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://w3programming.wordpress.com/2009/07/03/which-javascript-framework-to-use-dojo-jquery-prototype/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c54c5f65a45e8984e47150a905ba7ea5?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">kevinknelson</media:title>
		</media:content>
	</item>
	</channel>
</rss>
