<?xml version="1.0" encoding="UTF-8"?>
<rss 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:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Helephant.com</title>
	
	<link>http://helephant.com</link>
	<description />
	<lastBuildDate>Sat, 21 Jan 2012 22:46:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/helephant" /><feedburner:info uri="helephant" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Places to get good developer videos</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/yRRPOdPLj74/</link>
		<comments>http://helephant.com/2012/01/21/places-to-get-good-developer-videos/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 19:21:29 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[My life as a coder]]></category>
		<category><![CDATA[professional development]]></category>
		<category><![CDATA[totaljobs group]]></category>
		<category><![CDATA[videos]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2328</guid>
		<description><![CDATA[A list of places to find videos about being a better developer. These are mostly about all the stuff I care about for work: writing good code, .NET technology and web dev. ]]></description>
			<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2012/01/DPP_0106.jpg" class="alignright"/> Part of the awesome that is <a href="http://www.totaljobsgroup.com/">where I work</a> is an hour a week where developers can get together and chat about what we&#8217;ve been up to with the idea of spreading ideas around the different teams. One of the regular things we do is watch a video about a new technology, pattern or practice that we&#8217;d like to know more about. Right now I run the testing and automation stream and have found it a bit of a pain to always have something new to talk about, so I&#8217;ve put together a list of interesting places to find developer videos. </p>
<p>This is just a starting point, hopefully I&#8217;ll keep updating it as I actually try out the videos and find more places to get good content.</p>
<h2>Programming</h2>
<p><a href="http://www.cleancoders.com/">Clean coders</a> has videos about writing maintainable code that are all less than an hour, fast moving, well edited and full of funny. You do have to pay for the videos, but they&#8217;re pretty cheap and have clear information about showing them to groups (around $1US/person). I find it impossible not to like Uncle Bob. It&#8217;s like being taught how to code well by your slightly embarrassing dad. </p>
<p><a href="http://www.infoq.com/">infoq</a> has presentations about pretty much everything going on in mainstream development. </p>
<h2>.NET</h2>
<p><a href="http://tekpub.com/">Tekpub</a> have videos about a heap of different technologies, including quite a good selection on <a href="http://tekpub.com/channels/microsoft">.NET</a>. The videos tend to be under an hour and they get some pretty impressive experts (like Jon Skeet) to help present them. They&#8217;re kind of pricey ($18-$25) because you have to buy the videos as a series and they don&#8217;t have cheaper streaming prices for large groups, though they were willing to give us quite a generous discount. </p>
<p>I am a huge fan of the <a href="http://www.dotnetrocks.com/">.NET rocks</a> podcast but had never tried out their <a href="http://www.dnrtv.com/default.aspx">DNR TV</a> videos. They have videos on just about everything, though they tend to be an introduction rather than going into a lot of depth like the tekpub ones do. They&#8217;re free (hurrah!). </p>
<p>There&#8217;s a series of nhibernate videos called <a href="http://www.summerofnhibernate.com/">summer of nhibernate</a>. They&#8217;re free but over an hour each. I&#8217;ve watched the first one and it&#8217;s a pretty good introduction to nhibernate. </p>
<p><a href="http://dimecasts.net/">Dimecasts</a> has 10 minute videos about almost anything you can think about in .NET. It seems like a nice way to start a discussion about something. </p>
<p><a href="http://channel9.msdn.com/">Channel 9</a> on the MSDN have a vast library of videos which are mostly about Microsoft technology. There are hundreds of videos about .NET. </p>
<p><a href="http://skillsmatter.com/go/open-source-dot-net">Skills Matter</a> is a London based company that runs a lot of interesting sessions about all sorts of different technologies (including lots of open source stuff). They have recorded quite a lot of them and put them on their site to watch for free.  </p>
<h2>Web dev</h2>
<p><a href="http://yuilibrary.com/theater/">YUI theatre</a> has lots of videos about using YUI and some generally interesting web development ones as well. </p>
<p><a href="http://www.stubbornella.org/content/category/general/geek/css/">Nicole Sullivan</a> has some recordings of her conference talks. She talks about how to write maintainable CSS and we have found that using her ideas have made our CSS way better. </p>
<p>Videos from the <a href="http://channel9.msdn.com/Events/MIX">MIX conference</a> on some pretty neat new web technology. The 2011 lot have a lot of stuff about HTML5. They tend to be pretty good quality presentations since they&#8217;re for a conference. </p>
<h2>Technology and inspiration</h2>
<p>I like the <a href="http://www.ted.com/">TED</a> videos as an excuse to dream. ASP.NET developers probably don&#8217;t need to know about <a href="http://www.ted.com/talks/bilal_bomani_plant_fuels_that_could_power_a_jet.html">bio-fuels</a>, but it&#8217;s nice to feel inspired. :) </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/yRRPOdPLj74" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2012/01/21/places-to-get-good-developer-videos/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://helephant.com/2012/01/21/places-to-get-good-developer-videos/</feedburner:origLink></item>
		<item>
		<title>The HTML5 audio tag</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/YJf2YY8VnHg/</link>
		<comments>http://helephant.com/2011/12/29/the-html5-audio-tag/#comments</comments>
		<pubDate>Thu, 29 Dec 2011 17:00:43 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[html5]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=2160</guid>
		<description><![CDATA[The new HTML5 audio element now has pretty decent support across all browsers (even IE9) so is starting to be a pretty compelling alternative to using Flash. This article explains how to use the audio element, talks about which audio formats are supported by which browsers and how to control it using javascript. ]]></description>
			<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2012/01/audio-tag.jpg" class="alignright" /><br />
The new HTML5 &lt;audio&gt; tag provides a pretty easy way to embed audio into a webpage without needing to use flash:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio controls&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;source src=&quot;/my-podcast.mp3&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;source src=&quot;/my-podcast.ogg&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/audio&gt;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#browser-support">Browser support</a> for the tag itself is pretty decent, but you&#8217;ll need to <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">create a mp3 and ogg version of your audio</a> if you want it to play in all browsers. You can also provide a <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#fallback">fallback</a> for older browsers. </p>
<p>The <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#built-in-controls">built-in browser UI</a> is pretty consistent and looks decent enough, but if you need something special it&#8217;s very easy to <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#controlling-audio-with-javascript">use javascript to control the &lt;audio&gt; element</a>.</p>
<h2 id="audio-tag">The audio tag</h2>
<p>A simple &lt;audio&gt; tag (<a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">that doesn&#8217;t worry about cross browser compatibility</a>) looks like this:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio src=&quot;/my-podcast.mp3&quot; controls preload=&quot;none&quot; /&gt;</div>
</li>
</ol>
</div>
<p><strong>src</strong> &#8211; the url of the audio to play. In reality, if you want your audio to work in as <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">many browsers as possible</a>, you will need to set the media files in the &lt;source&gt; tags to provide both .mpg and .ogg versions of the content. </p>
<p><strong>controls</strong> &#8211; if this attribute is present (even if it is set to false), the browser will render an <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#built-in-controls">element to control your audio</a>. If you set this to false, no element will be rendered and you will need to <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#controlling-audio-with-javascript">use javascript to control your video</a>.</p>
<p>Here are the default controls in Chrome:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-chrome.png"/></p>
<p><strong>preload</strong> (none, metadata, auto) &#8211; whether the browser should start downloading the audio as soon as the page loads. If the audio is the whole point of the page it&#8217;s on, it might make sense to do it. If not, you can tell the browser to save the bandwidth. Of course having preload turned on will affect your bandwidth costs as much as it will affect your users. </p>
<p>Setting preload to none tells the browser not to preload at all. Metadata suggest that the browser just download enough of the file to find out things like dimensions, running length and size. Auto lets the browser know that it can do whatever it thinks will be best for the user, which might include preloading the whole file. </p>
<p>Sadly if you use this right now, setting preload=&#8221;none&#8221; causes issues in IE9. It will add the audio element to the page, but won&#8217;t display any controls for it. </p>
<p>For more information checked out the <a href="https://developer.mozilla.org/en/HTML/Element/audio">Mozilla</a> or <a href="http://msdn.microsoft.com/en-us/library/ff975061(v=vs.85).aspx">MSDN</a> references. There are a heap of extra properties that are useful for <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#controlling-audio-with-javascript">interacting with audio element through javascript</a>. </p>
<h2 id="supporting-different-browsers">Different browsers need different formats</h2>
<p>While <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#browser-support">support for the tag itself is pretty solid across browsers</a>, there (predictably) isn&#8217;t one audio format that all browsers support: </p>
<table class="compatibility-table">
<tr>
<th></th>
<td>IE</td>
<td>Firefox</td>
<td>Chrome</td>
<td>Safari</td>
<td>Opera</td>
</tr>
<tr>
<th>mp3</th>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
</tr>
<tr>
<th>ogg</th>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
</tr>
<tr>
<th>wav</th>
<td>No</td>
<td>Yes</td>
<td>No</td>
<td>Yes</td>
<td>Yes</td>
</tr>
</table>
<p>So to make an &lt;audio&gt; element that will work in all browsers, you&#8217;ll need to provide your file in at least two formats. I&#8217;ve found .ogg and .mp3 work pretty well. You can use the &lt;sources&gt; tag to provide a link to the audio file in both formats. The browsers will just look through all the sources provided and choose the one it thinks is best:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio controls&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.mp3&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.ogg&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/audio&gt;</div>
</li>
</ol>
</div>
<p>This might be a good reason to keep using flash for developers who are less concerned about supporting open standards and don&#8217;t need to support mobile browsers. Encoding the audio in two formats definitely adds a little overhead to my podcast workflow. </p>
<h2 id="fallback">Providing a fall back for older browsers</h2>
<p>Older browsers don&#8217;t understand the &lt;audio&gt; tag so you can provide a fallback just by adding extra HTML inside the &lt;audio&gt; tag. Browsers that support &lt;audio&gt; will just ignore the fallback content, while browsers that don&#8217;t support &lt;audio&gt; will ignore the audio tag. </p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio controls&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.mp3&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;source src=&quot;/my-podcast.ogg&quot; /&gt;
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;&lt;a href=&quot;/my-podcast.mp3&quot;&gt;download my podcast&lt;/a&gt;
</div>
</li>
<li class="li1">
<div class="de1">&lt;/audio&gt;</div>
</li>
</ol>
</div>
<p>One option is to use a Flash player as a fallback. Since Flash will play on pretty much any browsers except the iPhone, the only advantage of using the &lt;audio&gt; tag as with a Flash player fallback (apart from the warm glow of supporting open standards) is your audio will also play in iPhone Safari. </p>
<h2 id="built-in-controls">Audio controls in the different browsers</h2>
<p>If you decide to use the built in browser controls, the UI between browsers is pretty similar and fine for just including a simple audio file in your site.</p>
<p>Firefox:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-firefox.png"/></p>
<p>Chrome:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-chrome.png"/></p>
<p>Safari:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-safari.png"/></p>
<p>Internet explorer:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-ie.png"/></p>
<p>iPhone Safari:<br />
<img src="http://helephant.com/wp-content/uploads/2011/12/audio-iphone.png" /></p>
<p>To use the built in browser controls, just add the controls attribute to the &lt;audio&gt; tag:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;audio src=&quot;/my-podcast.mp3&quot; controls /&gt;</div>
</li>
</ol>
</div>
<h2 id="controlling-audio-with-javascript">Building custom controls using javascript</h2>
<p>If you don&#8217;t fancy the built in browser controls, it&#8217;s easy enough to control the <a href="https://developer.mozilla.org/en/DOM/HTMLAudioElement">audio tag using javascript</a>:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> audio = <span class="kw2">new</span> Audio<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span><span class="br0">&#40;</span>audio.<span class="me1">canPlayType</span><span class="br0">&#40;</span><span class="st0">&quot;audio/mp3&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;audio.<span class="me1">src</span> = <span class="st0">&quot;/my-podcast.mp3&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>audio.<span class="me1">canPlayType</span><span class="br0">&#40;</span><span class="st0">&quot;audio/ogg&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;audio.<span class="me1">src</span> = <span class="st0">&quot;/my-podcast.ogg&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">audio.<span class="me1">play</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2011/01/audio-javascript.html">Complete example</a></p>
<p>For more advanced audio manipulation, check out the experimental <a href="https://wiki.mozilla.org/Audio_Data_API">Audio data API</a>. </p>
<h2 id="browser-support">Browser support</h2>
<p>Once you get the <a href="http://helephant.com/2011/12/29/the-html5-audio-tag/#supporting-different-browsers">audio formats right</a>, desktop browsers have <a href="http://caniuse.com/#feat=audio">pretty good support</a> for the audio tag. Even IE 9+ supports it! </p>
<table class="compatibility-table">
<tr>
<th>Browser</th>
<th>Supported since version</th>
<th>Formats</th>
<th>Details</th>
</tr>
<tr>
<td>IE</td>
<td>9.0</td>
<td>AAC or .mp3</td>
<td><a href="http://msdn.microsoft.com/en-us/library/ff975061(v=vs.85).aspx">MSDN</a></td>
</tr>
<tr>
<td>Firefox</td>
<td>3.5</td>
<td>.ogg, .wav</td>
<td><a href="https://developer.mozilla.org/En/HTML/Element/Audio#Compatibility">MDN</a></tr>
<tr>
<td>Chrome</td>
<td>3</td>
<td>.mp3, .ogg</td>
<td></td>
</tr>
<tr>
<td>Safari</td>
<td>4</td>
<td>Any audio supported by Quicktime<br/> (m4a, .m4b, .m4p, .mp3, .aiff, .au, .sd2, .wav, .snd, .amr)</td>
<td><a href="http://developer.apple.com/library/safari/#documentation/AppleApplications/Reference/SafariHTMLRef/Articles/HTMLTags.html#//apple_ref/doc/uid/30001262-audio">Safari docs</td>
</tr>
<tr>
<td>Opera</td>
<td>9.5</td>
<td>.ogg, .wav</td>
<td></td>
</tr>
</table>
<p>Mobile browser have pretty good support too: </p>
<table class="compatibility-table">
<tr>
<th>Browser</th>
<th>Supported since version</th>
</tr>
<tr>
<td>iOS Safari</td>
<td>4</td>
</tr>
<tr>
<td>Opera mobile</td>
<td>10</td>
</tr>
<tr>
<td>Opera mini</td>
<td>no support (Dec 2011)</td>
</tr>
<tr>
<td>Android</td>
<td>2.3</td>
</tr>
<tr>
<td>Blackberry</td>
<td><a href="http://devblog.blackberry.com/2010/08/blackberry-html5/">6</a></td>
</tr>
</table>
<img src="http://feeds.feedburner.com/~r/helephant/~4/YJf2YY8VnHg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/12/29/the-html5-audio-tag/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://helephant.com/2011/12/29/the-html5-audio-tag/</feedburner:origLink></item>
		<item>
		<title>The developer book club</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/kG-HxilYw8Q/</link>
		<comments>http://helephant.com/2011/04/24/the-developer-book-club/#comments</comments>
		<pubDate>Sun, 24 Apr 2011 19:13:45 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[My life as a coder]]></category>
		<category><![CDATA[feature]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1971</guid>
		<description><![CDATA[I've started a new podcast called the developer book club where I interview someone interesting about what books have influenced and inspired them. ]]></description>
			<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2011/04/development-books-300x225.jpg" alt="" title="development books" width="300" height="225" class="alignright size-medium wp-image-2017" />I&#8217;ve just started a new website called <a href="http://developerbookclub.net/">the developer book club</a>. </p>
<p>It&#8217;s the same sort of setup as <a href="http://www.bbc.co.uk/programmes/b006qnmr">desert island discs</a>: I find someone interesting to interview and they tell me about three books that have influenced them as a developer. </p>
<p>I&#8217;ve just posted my first podcast where I interview a very nice developer called <a href="http://developerbookclub.net/dan-wagner-hall/">Dan Wagner-Hall</a> who agreed to be my first victim. </p>
<p>(book picture taken by <a href="http://www.flickr.com/photos/anantablamichhane/2091903760/">Ananta Bhadra Lamichhane</a>)</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/kG-HxilYw8Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/04/24/the-developer-book-club/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2011/04/24/the-developer-book-club/</feedburner:origLink></item>
		<item>
		<title>Come work for TotalJobs</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/4qWdJxrox3g/</link>
		<comments>http://helephant.com/2011/02/21/come-work-for-totaljobs/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 13:35:52 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[My life as a coder]]></category>
		<category><![CDATA[Scrum]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1938</guid>
		<description><![CDATA[We need some new mid level ASP.NET developers at Total Jobs Group to join our team based in central London. Be part of one of our seven small scrum teams and work on everything from CSS and HTML through to the database, from idea through to release. TJG runs seven job boards. Total Jobs is [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2011/02/tjg-logo.png" alt="" title="tjg-logo" width="110" height="100" class="alignright size-full wp-image-2032" />We need some <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=49810373">new mid level ASP.NET developers</a> at <a href="http://www.totaljobsgroup.com/">Total Jobs Group</a> to join our team based in central London. Be part of one of our seven small scrum teams and work on everything from CSS and HTML through to the database, from idea through to release. </p>
<p>TJG runs seven job boards. <a href="http://www.totaljobs.com">Total Jobs</a> is the most popular one and the other five are all industry boards like <a href="http://www.cwjobs.co.uk/">CW Jobs</a> for IT. Pretty much all development is for either the websites or the web based tools that support them.</p>
<p>For more detailed information about the job and the exact skills we&#8217;re after, check out the <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=49810373">job spec</a>. </p>
<h2>Why would you want to work with us?</h2>
<p>Our department is serious about continuous improvement so we’re constantly looking for new ways to do development better. In the past six months the development team have been going on TDD training and teams are starting to do it as part of their every day work. Some of the teams have been trying MVP patterns on areas of the code that already use web forms. New areas of the code have been using the MVC framework. We keep improving the way we use clientside technologies, particularly CSS and javascript. Lots of teams choose to pair program. Last year there was a big project to automate more of our release process.</p>
<p>Each team gets flexibility to try new things. Our team has tried experimenting with different sprint lengths, kanban style work in progress limits, tracking stories through TFS, <a href="http://helephant.com/2010/10/lego-scrum-board-avatars/">lego people on our scrum board</a> and tracking technical debt on the ceiling. Other teams are automating their acceptance testing with Selenium and trying TDD. Each team is encouraged to figure out what works for them.</p>
<p>We’re encouraged to share ideas around the department. We have our own internal user group where a couple of times a month someone talks about something they&#8217;re passionate about. Today&#8217;s session was about how one guy hooked up RFID readers to the scrum board to track story status and to automatically kick off builds. The really cool thing is the department supports it by giving us a lunch budget. We also do community of practice sessions where we all bring some code and talk about something neat we&#8217;ve been doing. Some of the groups have been reading books like Working Effectively with Legacy Code and Clean Code.</p>
<p>The office has a really nice atmosphere. The people are friendly. We have a casual dress code. People put effort into making work a fun place to be. Last week we had a build it in a day Friday where the whole team (not just developers) had a day to work on anything company related that interested them. We have team outings a couple of times a year. The development team are going bowling on Friday. People go out for team lunches and Friday drinks. People bring cakes and donuts in to celebrate things a couple of times a week. Our scrum master is a great cook and brought in homemade lemon drizzle cake today.</p>
<p>People notice when you do a good job and its recognised. Every other week there&#8217;s a presentation where the management tell everyone about something great that someone has done. Last year there were toys and lego for teams that did something special. You can see Star Wars lego all over the office now. Before that we competed for a silver cup full of sweets. They also awarded a scrum team of the year award where one of the teams got a prize to spend on a meal out together.</p>
<p>TotalJobs is part of a bigger company called Reed Elsevier so the benefits are pretty good. My absolute favourite is that we get 29 days holiday a year with the option to buy or sell three during the year. We also get two charity days. Last year our team spent the day doing gardening for some lovely elderly people in Sutton. The year before we did gardening and painting for a kids playground.</p>
<h2>Joel test</h2>
<p>Do you use source control? &#8211; TFS<br />
Can you make a build in one step? &#8211; Yes<br />
Do you make daily builds? &#8211; Yes, we build when we check in. Working towards continuous integration.<br />
Do you have a bug database? &#8211; Our scrum team track bugs on the board on red cards.<br />
Do you fix bugs before writing new code? &#8211; yes<br />
Do you have an up-to-date schedule? &#8211; yes<br />
Do you have a spec? &#8211; We write user stories with acceptance criteria.<br />
Do programmers have quiet working conditions? &#8211; No we work open plan and everyone sits with the people they&#8217;re working on<br />
Do you use the best tools money can buy? &#8211; We use VS2010 (mostly), Resharper, nUnit, computers with dual monitors, MSDN licenses<br />
Do you have testers? &#8211; yup. Vinny is a bug finding machine.<br />
Do new candidates write code during their interview? &#8211; depends who interviews you<br />
Do you do hallway usability testing? &#8211; we do weekly demos to get feedback from the people we build the software for. We have designers and usability people who come up with the best way to implement user interfaces. </p>
<h2>Your job isn&#8217;t as great as this?</h2>
<p>Interested? Then <a href="mailto:helen@helephant.com">email me your CV</a> and I&#8217;ll pass it on or <a href="http://www.totaljobs.com/JobSearch/JobDetails.aspx?JobId=49810373">apply through the website</a>. </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/4qWdJxrox3g" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/02/21/come-work-for-totaljobs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2011/02/21/come-work-for-totaljobs/</feedburner:origLink></item>
		<item>
		<title>Maintainable CSS presentation slides</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/mwIcALlqWBE/</link>
		<comments>http://helephant.com/2011/01/31/ddd9-slides/#comments</comments>
		<pubDate>Mon, 31 Jan 2011 21:06:00 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[My presentations]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1934</guid>
		<description><![CDATA[A talk that I gave at the Developer, Developer, Developer day in Reading in 2011 about my experiences trying to make CSS easier to maintain. Contains slides and sample downloads. ]]></description>
			<content:encoded><![CDATA[<p><img src="http://helephant.com/wp-content/uploads/2011/01/cement-lion-300x200.jpg" alt="" title="code tends to set like cement" class="alignright size-medium wp-image-2028" />I gave a talk at <a href="http://www.developerdeveloperdeveloper.com/ddd9/">developer, developer, developer day</a> on Saturday about maintainable CSS so here are my <a href="http://helephant.com/wp-content/uploads/2011/01/css-is-code.zip">slides</a>. :)</p>
<p>Feel free to use these slides if you&#8217;d like to give a similar presentation. Feel free to give it as is, as a starting point or ideas for your own presentation. I&#8217;d love it if you could link back to me, but this is all about getting people talking about writing maintainable CSS rather than anything else. </p>
<p>Am planning to write up most the stuff I thought about for the presentation, so hopefully more will come soon. :) </p>
<p>(Cement lion from <a href="http://www.flickr.com/photos/eusebius/3491751790/">Flickr creative commons</a>)</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/mwIcALlqWBE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2011/01/31/ddd9-slides/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://helephant.com/2011/01/31/ddd9-slides/</feedburner:origLink></item>
		<item>
		<title>Lego scrum board avatars</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/2Rrks3Cm27s/</link>
		<comments>http://helephant.com/2010/10/09/lego-scrum-board-avatars/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 21:16:36 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[Scrum]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1885</guid>
		<description><![CDATA[How we made our scrum board a little more fun by combining the geek loves of Lego and magnets. ]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re having a bit of a Lego theme in our office at the moment with teams being given lego sets as prizes for doing good work. With all this Lego in the office, when I was chatting to another another developer about the scrum board we almost inevitably came up with the idea of using magnetic Lego people as team avatars. </p>
<p>Once we&#8217;d come up with the idea, I had to do it. So I shopped around on the internet for all the bits I needed, came into work with a creepy bag of Lego heads and we swapped our <a href="http://www.simpsonsmovie.com/main.html">Simpsons</a> avatars with new ones made out of lego. </p>
<p>Here are the avatars we came up with:<br />
<img src="http://helephant.com/wp-content/uploads/2010/10/helen.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/mike.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/justin.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/dave.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/vinny.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/lauren.png"> <img src="http://helephant.com/wp-content/uploads/2010/10/jen.png"></p>
<h2>What you need to make your own scrum board Lego peeps</h2>
<ul>
<li>You can get a big bag of Lego magnets from <a href="http://www.amazon.com/gp/product/B002U2YG7E?ie=UTF8&#038;tag=helephantcom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B002U2YG7E">Amazon.com</a> or <a href="http://www.amazon.co.uk/gp/product/B0039YZ6TO?ie=UTF8&#038;tag=helensadvenin-21&#038;linkCode=as2&#038;camp=1634&#038;creative=19450&#038;creativeASIN=B0039YZ6TO">Amazon.co.uk</a> for a couple of pounds.</li>
<li>You can buy lego heads, bodies, hair and accessories on <a href="http://www.bricklink.com/browseTree.asp?itemType=M">bricklink</a>. You don&#8217;t have to buy whole people, you can just buy the bits that you think your team might like. I got enough for my team for about £30. You can find female lego people if you hunt around.</li>
<li>A team of developers who aren&#8217;t too grown up to play Lego.</li>
</ul>
<img src="http://feeds.feedburner.com/~r/helephant/~4/2Rrks3Cm27s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2010/10/09/lego-scrum-board-avatars/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://helephant.com/2010/10/09/lego-scrum-board-avatars/</feedburner:origLink></item>
		<item>
		<title>Javascript method context</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/ekAGlsR0xcM/</link>
		<comments>http://helephant.com/2009/11/29/javascript-method-context/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 18:26:59 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[closures]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[firstclassfunctions]]></category>
		<category><![CDATA[javascriptobjects]]></category>
		<category><![CDATA[oo]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1646</guid>
		<description><![CDATA[In languages like C# and Java you never really need to give a thought to the <code>this</code> operator. In javascript things are a little more complicated due to functions being first class objects. ]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://helephant.com/2008/09/constructor-functions/">previous examples</a> you might have noticed that we use <code><a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Operators/Special_Operators/this_Operator">this</a></code> to get a reference to the object that a function belongs to while we&#8217;re inside the function. The value of the <code>this</code> operator is the context of the method:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="st0">&quot;Rufus&quot;</span>, <span class="st0">&quot;cat&quot;</span>, <span class="st0">&quot;miaow&quot;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If you&#8217;re familiar with languages like C# or Java, chances are you&#8217;ve never really thought too much about <code>this</code> because its value always references the object that the method belongs to (the rufus object in the previous example). This is usually the case in javascript too but there are some situations where it won&#8217;t refer back to the object that you&#8217;re expecting. </p>
<h2>Functions are first class objects</h2>
<p>The difference between way the <code>this</code> operator works in C# and javascript is a side effect of <a href="http://helephant.com/2008/08/functions-are-first-class-objects-in-javascript/">functions being first class objects</a> in javascript. Functions are just another type of variable that can be passed around the application.</p>
<p>The methods in a javascript object are only methods because you chose to store a function inside one of the object&#8217;s properties. There is nothing in the language that always binds the method to the object. If you wanted to, you could use the same function in a number of different objects:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sayHello = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span>: <span class="st0">&quot;Rufus&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span> = sayHello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sabby = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span>: <span class="st0">&quot;Sabby&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">sabby.<span class="me1">sayHello</span> = sayHello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// invoke sayHello from the objects</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sabby.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-object.html">Complete example</a></p>
<p>Notice that the context of the sayHello() function (the thing that <code>this</code> references) is different depending on which object invoked it. In this example the two different objects were pretty much the same but the sayHello() function could be used by completely different objects as long as they provide the right information. </p>
<p>This design decouples the function from the context that uses it. You can plug any context into the function and it will still work. This is one of the reasons that having functions as first class objects is such a powerful feature. </p>
<h2>Default context</h2>
<p>Every time you call a function it has a context even if it is not explicitly provided. If no context is explicitly provided when the function is called, the default context will be used instead. In the browser the default context is the window object. This means that if you call a function without invoking it through an object, <code>this</code> will be set to the window. </p>
<p>To see this in action lets try calling sayHello() without invoking it from an object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sayHello = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">if</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">else</span> &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span> + <span class="st0">&quot; can&#39;t say hello because name property was not set&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// invoke sayHello from the global context</span></div>
</li>
<li class="li1">
<div class="de1">sayHello<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-default.html">Complete example</a></p>
<p>Javascript is happy to run the function without calling it through an object. It just sets the context to the default context, the window object. The window object doesn&#8217;t have a name property so instead of alerting &#8220;someone says hello&#8221;, instead it alerts the error message about the object not having a name property. </p>
<p>The way I imagine it is calling sayHello() is really calling window.sayHello(). You just don&#8217;t need to explicitly use the window object to invoke it because the window object is the default context. The same thing happens if you set a variable without declaring it first using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Statements/var">var statement</a>. Instead of creating a new variable that&#8217;s only available in the current scope, it actually creates a new property on the window object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">flibble = <span class="st0">&quot;xyz&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>window.<span class="me1">flibble</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/11/context-default-context-property.html">Complete example</a></p>
<p>Check out <a href="http://www.jibbering.com/faq/faq_notes/closures.html#clExCon">this article</a> if you want to find out more about what happens when a Javascript function is called. It&#8217;s a really interesting write up that goes into lots of detail. </p>
<h2 id="objects-context-and-event-handlers">Objects, context and event handlers</h2>
<p>In the previous examples, we have explicitly called the sayHello() method ourselves. This doesn&#8217;t happen for functions that are used for event handlers. We wire them up and then they are invoked automatically when the event occurs. </p>
<p>This can be a problem for functions that actually are methods of objects. The logic that invokes the event handler doesn&#8217;t know anything about the object the method belongs to so it can&#8217;t be invoked in the right context. </p>
<p>Instead the context of the method is set to the element that caused the event. If it was a button click event, it will be set to the HTML button element that was clicked. It it is an onload event, it will be set to the element that was loaded. The exception to this rule is IE where the context will always be set to the default window context. </p>
<p>Here&#8217;s an example where the hello function of a rufus object is used for the onclick event of our button:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span> : <span class="st0">&quot;Rufus&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; species: <span class="st0">&quot;cat&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; hello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says miaow&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;button&quot;</span><span class="br0">&#41;</span>.<span class="me1">onclick</span> = rufus.<span class="me1">hello</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-event-handler.html">Complete example</a></p>
<p>If you&#8217;d never tried this before, you&#8217;d probably expect the <code>this</code> operator to still be set to the rufus object when the button is clicked so the output would be &#8220;Rufus says miaow&#8221;. Instead the <code>this</code> operator is set to the button that triggered the event. The button&#8217;s name property is set to &#8220;button&#8221; so the output is &#8220;button says miaow&#8221; (which is just silly, buttons don&#8217;t miaow).</p>
<h2>Changing the context using Function.apply() and Function.call()</h2>
<p>In cases like the event handler problem, you might want to invoke a method in an explicit context. Javascript functions support two methods that you can use to do this called <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/apply">Function.apply</a> and <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/call">Function.call</a>. </p>
<p>Both methods are pretty much the same. You can use them both to invoke a method, supply the context and a list of parameters. The only difference between the two are the way the parameters are passed in. Function.apply() accepts the parameters for the function as an array while Function.call() accepts them as individual parameters:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> sayHello = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says hello&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span> + <span class="st0">&quot; can&#39;t say hello because name property was not set&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">name</span>: <span class="st0">&quot;Rufus&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">sayHello.<span class="me1">call</span><span class="br0">&#40;</span>rufus<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">sayHello.<span class="me1">apply</span><span class="br0">&#40;</span>rufus<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/10/context-call-apply.html">Complete example</a></p>
<h2>Using Function.call() to solve the event handler problem</h2>
<p>Remember the problem with <a href="#objects-context-and-event-handlers">using a method from an object as an event handler</a>? When the event is fired, the context of the event handler is set to the HTML element that triggered the event. Then when you access the <code>this</code> operator you get a reference to the HTML element rather than the object that you might have expected. </p>
<p>It&#8217;s possible to use Function.call() (or Function.apply() if you want) to invoke the event handler in the right context. The plan: create a custom function that wires up the event handler and knows what the context of the function should be when the event is run:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> addEvent<span class="br0">&#40;</span>element, eventName, handler, context<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">var</span> wrapper = handler;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>context<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// create an anonymous function </span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// that uses a closure to access the context parameter</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// and then uses Function.call() to invoke the real event handler</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; wrapper = <span class="kw2">function</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handler.<span class="me1">call</span><span class="br0">&#40;</span>context, e<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>element.<span class="me1">addEventListener</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; element.<span class="me1">addEventListener</span><span class="br0">&#40;</span>eventName, wrapper, <span class="kw2">false</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">else</span> <span class="kw1">if</span><span class="br0">&#40;</span>element.<span class="me1">attachEvent</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; element.<span class="me1">attachEvent</span><span class="br0">&#40;</span><span class="st0">&quot;on&quot;</span> + eventName, wrapper<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw3">name</span> : <span class="st0">&quot;Rufus&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;species: <span class="st0">&quot;cat&quot;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;hello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot; says miaow&quot;</span><span class="br0">&#41;</span>; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">addEvent<span class="br0">&#40;</span>document.<span class="me1">getElementById</span><span class="br0">&#40;</span><span class="st0">&quot;button&quot;</span><span class="br0">&#41;</span>, <span class="st0">&quot;click&quot;</span>, rufus.<span class="me1">hello</span>, rufus<span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/11/context-event-handler-apply.html">Complete example</a></p>
<p>This works because javascript has a feature called <a href="http://helephant.com/2008/08/javascript-anonymous-functions/">anonymous functions</a> that you can use to create a new function at runtime. The addEvent function uses this to create a new wrapper function that calls the event handler using Function.call(). The wrapper function is passed to addEventListener() instead of the event handler that was passed in as a parameter. </p>
<p>The wrapper function can access the context object when the event fires because of another javascript language feature called <a href="http://helephant.com/2008/10/javascript-closures/">closures</a>. When you create a function inside another function, closures mean that the inner function automatically has access to the local variables of the outer function (addEvent) when the inner function (wrapper) is called. This works even if the inner function is called after the outer function has finished running. </p>
<p>This is how the wrapper function can get hold of addEvent&#8217;s context and handler parameters when the anonymous function is run. </p>
<p>Mostly if you&#8217;re using a javascript framework, you don&#8217;t need to worry too much about this. The framework will look after it for you, usually in a way similar to this. For example, if you&#8217;re an ASP.NET ajax programmer, this is exactly what happens when you use Function.createDelegate() to register an event handler inside an component. </p>
<h2>What&#8217;s next?</h2>
<p>Sometimes you need to find out things about an object&#8217;s capabilities. The next article talks about finding out what type of object you have and what it can do. </p>
<p>This article is part of a set of related posts about <a href="/2008/08/how-javascript-objects-work/">How javascript objects work</a>.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/ekAGlsR0xcM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/11/29/javascript-method-context/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/11/29/javascript-method-context/</feedburner:origLink></item>
		<item>
		<title>CSS3 Multiple background images</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/bBnm3yA_tTw/</link>
		<comments>http://helephant.com/2009/11/23/css3-multiple-background-images/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:11:13 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[bleedingedgeofweb]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[multiplebackgrounds]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1694</guid>
		<description><![CDATA[Firefox 3.6 supports multiple background images so I thought it was time to give them a go and figure out how they work. May contain small rant about beautiful markup. ]]></description>
			<content:encoded><![CDATA[<p><a href="http://developer.mozilla.org/En/Firefox_3.6_for_developers">Firefox 3.6</a> is in beta and I was overjoyed (ie: opening presents on Christmas day) to <a href="http://www.quirksmode.org/css/multiple_backgrounds.html">discover</a> that Mozilla have finally implemented my favourite part of the <a href="http://dev.w3.org/csswg/css3-background/">CSS3 borders and background spec</a>: multiple background images on a single element. </p>
<p>One of the (many) points of controversy in our team when we last updated the HTML standards doc was the best way to provide enough html structure in our document to accommodate what our designers create. We want small, slick and semantic markup but have to add extra structural divs so we have enough places to stick the background images we use to decorate the boxes. </p>
<p>Firefox 3.6 gives me a little hope, even if it is distant hope, that one day the extra divs will no longer be needed! </p>
<h2>How multiple background images are declared</h2>
<p>Just put a list of background declarations instead of a single one when you use the background property:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bottom.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">repeat-x</span> <span class="kw1">bottom</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-image.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">bottom</span> <span class="kw1">right</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/11/multiple-background-images.html">Complete example</a></p>
<p>You don&#8217;t have to use the background property. You can also list out each of the background attributes separately: </p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bottom.png&quot;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-image.png&quot;</span><span class="br0">&#41;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background-repeat</span><span class="sy0">:</span> <span class="kw2">repeat-x</span>, <span class="kw2">no-repeat</span>, <span class="kw2">repeat</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background-position</span><span class="sy0">:</span> <span class="kw1">bottom</span>, <span class="kw1">bottom</span> <span class="kw1">right</span>, <span class="kw1">top</span> <span class="kw1">right</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>The browser applies the images top to bottom, so the first one you declare will overlap any of the others. It supports all the background attributes you can usually use. </p>
<p>Here&#8217;s how the example looks in Firefox 3.6 (sorry for my lack of graphic design skills!):<br />
<img src="http://helephant.com/wp-content/uploads/2009/11/multiple-background-example.png" alt=""></p>
<h2>Backwards compatibility</h2>
<p>Multiple background images degrade quite nicely in older browsers. You can supply a single background image before you declare the multiple background images and the browsers with support will show the multiple background images while the other browsers will just show the single one: </p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="coMULTI">/* you can put in a single background for browsers that don&#39;t support it */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/* example using background short hand property */</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">background</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bottom.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">repeat-x</span> <span class="kw1">bottom</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-image.png&quot;</span><span class="br0">&#41;</span> <span class="kw2">no-repeat</span> <span class="kw1">bottom</span> <span class="kw1">right</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">url</span><span class="br0">&#40;</span><span class="st0">&quot;multiple-background-bg.png&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>Here&#8217;s how my example looks in Firefox 3.5:<br />
<img src="http://helephant.com/wp-content/uploads/2009/11/multiple-background-backwards-compat.png" alt="" /></p>
<p>I tested the same example in IE8 and Opera 10.10 and it looked the same as in Firefox. </p>
<h2>Why is this so great?</h2>
<p>The biggest reason is it goes further in separate presentation from markup. We&#8217;re a little closer to being able to mark up a document according to it&#8217;s meaning rather than how we want to present it. That&#8217;s a really good things because it means we can change the presentation without having to change the document. </p>
<p>I am of the opinion that fewer tags in a HTML document is a good thing. It&#8217;s fewer tags to read and understand when you have to change the document. It&#8217;s fewer tags to debug when something goes wrong with the page. It is also fewer tags to send down to the client on each request. </p>
<p>I think it&#8217;s going to empower designers to be a bit more daring with their designs. They won&#8217;t have to worry about dirty looks from whoever does the HTML markup (or a sigh from themselves) when they design something with rounded corners and drop shadows. I look at designers like that when I see a mockup with rounded corners! They shouldn&#8217;t have to feel bad about it! Making great looking designs is just their job. </p>
<p>It&#8217;ll also make it much easier to make design elements that are stretchy. You can change the dimensions of stretchy elements easily just by changing the width and height properties. You can reuse the same styles in different containers without having to have a whole different set of styles and images (or a heap of structural divs). </p>
<h2>Who supports it?</h2>
<table class="compatibility">
<tr class="compatible">
<th>Firefox</th>
<td>Firefox 3.6+</td>
<td><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=322475">bugzilla entry</a>, <a href="https://developer.mozilla.org/en/CSS/background-image">announcement</a></td>
</tr>
<tr class="compatible">
<th>Webkit</th>
<td>Safari 1.3+, all Chrome versions</td>
<td><a href="http://webkit.org/blog/15/multiple-backgrounds/">announcement</a></td>
</tr>
<tr class="compatible">
<th>IE</th>
<td>IE 9+</td>
<td><a href="http://ie.microsoft.com/testdrive/">IE9 technology preview</a></td>
</tr>
<tr class="compatible">
<th>Opera</th>
<td>IE 10.60+</td>
<td></td>
</tr>
</table>
<h2>But Helen it&#8217;s going to be years before we can use this stuff!</h2>
<p>It&#8217;s true we don&#8217;t know how long it will take for the old versions of IE to fade into market share obscurity. It might be three or four more years until this has enough browser support to be used widely across the web. </p>
<p>That&#8217;s ok, it&#8217;s how the web works. Way back in 2000 it seemed impossible that there could be a document object model that worked across all the browsers but sooner or later the stars all aligned to unleash the ajax revolution. I am excited because it&#8217;s a step in the right direction for a better web for web developers. I am happy with that for now. </p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/bBnm3yA_tTw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/11/23/css3-multiple-background-images/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/11/23/css3-multiple-background-images/</feedburner:origLink></item>
		<item>
		<title>IE6 absolute positioning in parent with odd width</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/rkmntiAUMI0/</link>
		<comments>http://helephant.com/2009/09/07/ie6-absolute-positioning-in-parent-with-odd-width/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 06:00:52 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[Browser quirks]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[absolute positioning]]></category>
		<category><![CDATA[ie6]]></category>
		<category><![CDATA[positioning]]></category>
		<category><![CDATA[right]]></category>
		<category><![CDATA[workaround]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1666</guid>
		<description><![CDATA[A small browser quirk for IE6 where absolute positioning with the CSS right property is one pixel out when the parent container has an odd number of pixels.]]></description>
			<content:encoded><![CDATA[<p>One of the guys I work with found an interesting browser issue this week. He was using absolute positioning to position an element to the right of a box which was an odd number of pixels across. He noticed that in IE6 the child element was one pixel away from where it was in other browsers.</p>
<p><strong>In IE6</strong><strong><br />
<img src="http://www.helephant.com/wp-content/uploads/2009/09/relative-position-ie61.png" alt=""/></p>
<p></strong><strong>In IE7</strong><br />
<img src="http://www.helephant.com/wp-content/uploads/2009/09/relative-position-ie71.png" alt=""/></p>
<h2>Simple test case</h2>
<p>Here&#8217;s a simple example of the HTML:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div id=&quot;container&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;div id=&quot;inside&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>Here&#8217;s a simple example of the CSS:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re0">#container</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">relative</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">301px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">200px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> pink<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re0">#inside</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">absolute</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">right</span><span class="sy0">:</span> <span class="re3">0px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _right<span class="sy0">:</span> -<span class="re3">1px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="kw2">yellow</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/09/relative-position1.html">Complete example</a></p>
<h2>Workaround</h2>
<p>If you can&#8217;t use an even number of pixels for the width of the parent box, just to use the underscore IE6 hack to provide an adjusted right value just for IE6 that all the other browsers will ignore:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re0">#inside</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">position</span><span class="sy0">:</span> <span class="kw2">absolute</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">right</span><span class="sy0">:</span> <span class="re3">0px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; _right<span class="sy0">:</span> -<span class="re3">1px</span><span class="sy0">;</span> <span class="coMULTI">/* for IE6 */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="kw2">yellow</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<img src="http://feeds.feedburner.com/~r/helephant/~4/rkmntiAUMI0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/09/07/ie6-absolute-positioning-in-parent-with-odd-width/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/09/07/ie6-absolute-positioning-in-parent-with-odd-width/</feedburner:origLink></item>
		<item>
		<title>Building javascript minification into MSBuild scripts</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/_2iV_9sWvTc/</link>
		<comments>http://helephant.com/2009/08/29/building-minification-into-msbuild-scripts/#comments</comments>
		<pubDate>Sat, 29 Aug 2009 12:51:43 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[jsmin]]></category>
		<category><![CDATA[minification]]></category>
		<category><![CDATA[msbuild]]></category>
		<category><![CDATA[packer]]></category>
		<category><![CDATA[yui]]></category>
		<category><![CDATA[yui compressor]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1586</guid>
		<description><![CDATA[How to use a tool called Packer.NET to build javascript minification into a MSBuild script.]]></description>
			<content:encoded><![CDATA[<p>A while back when I had a play with javascript minification to speed up the download of a site I was working on I found a tool called <a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/">Packer.NET</a> that&#8217;s a ready made to work with MSBuild.</p>
<h2>Which algorithm to use?</h2>
<p>The minification tool supports <a href="http://www.crockford.com/javascript/jsmin.html">JSMin</a> and <a href="http://dean.edwards.name/packer/">Packer</a>.</p>
<p>JSMin just strips out the parts of the file that the browser won&#8217;t need like extra whitespace and comments. You can run JSMin over CSS and javascript.</p>
<p>Packer does the same sort of minification as JSMin but also has options to reduce variable names to single characters and to <a href="http://en.wikipedia.org/wiki/Base_62">base-62 encode</a> everything. Packer tends to give very small file sizes when you use the base-62 option but there&#8217;s a performance hit in the browser when it gets unpacked.  Packer will only run on javascript.</p>
<p>One thing is keep in mind is whether or not you&#8217;re using gzip compression. JSMin with gzip compression tends to give files that are almost the same as Packer but without the clientside performance hit of unpacking them. Gzip tends not to make as much of a difference to files minified with the base-62 encoding option.</p>
<p>A good way to find out which will be best is to run your particular script through the <a href="http://compressorrater.thruhere.net/">compressor comparison tool</a>.</p>
<h2>Using the tool</h2>
<p>Packer.NET comes as a single dll so you don&#8217;t need to install any command line programs to use it. I put the assembly into source control on our system so anyone who wanted to run the build script wouldn&#8217;t need to install it manually.</p>
<p>Here&#8217;s an example target that uses JSMin to minify all CSS files and all javascript files (except library files that are already minified). This example simply replaces the existing files:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;import</span> <span class="re0">Project</span>=<span class="st0">&quot;$(MSBuildExtensionsPath)\SmallSharpTools.Packer\MSBuild.Packer.Targets&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;target</span> <span class="re0">Name</span>=<span class="st0">&quot;Minify&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; minify javascript and CSS &#8211;&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;itemgroup<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;javascript</span> <span class="re0">Include</span>=<span class="st0">&quot;$(SolutionRoot)\**\*.js&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Exclude</span>=<span class="st0">&quot;$(SolutionRoot)\**\*pack.js;&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;stylesheet</span> <span class="re0">Include</span>=<span class="st0">&quot;$(SolutionRoot)\**\*.css&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/itemgroup<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="coMULTI">&lt;!&#8211; http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki &nbsp;&#8211;&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;message</span> <span class="re0">Text</span>=<span class="st0">&#39;Minifying javascript: %(Javascript.FullPath) &#8230; &#39;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;packer</span> <span class="re0">OutputFileName</span>=<span class="st0">&quot;%(Javascript.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Mode</span>=<span class="st0">&quot;JSMin&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">InputFiles</span>=<span class="st0">&quot;%(Javascript.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Verbose</span>=<span class="st0">&quot;true&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Condition</span>=<span class="st0">&quot;Exists(%(Javascript.FullPath))&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;message</span> <span class="re0">Text</span>=<span class="st0">&#39;Minifying css: %(Stylesheet.FullPath) &#8230; &#39;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;packer</span> <span class="re0">OutputFileName</span>=<span class="st0">&quot;%(Stylesheet.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Mode</span>=<span class="st0">&quot;CSSMin&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">InputFiles</span>=<span class="st0">&quot;%(Stylesheet.FullPath)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Verbose</span>=<span class="st0">&quot;true&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="re0">Condition</span>=<span class="st0">&quot;Exists(%(Stylesheet.FullPath))&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/target<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p>There&#8217;s <a href="http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki">documentation</a> with more examples and details on the different options that the task supports.</p>
<h2>What about YUI compressor?</h2>
<p><a href="http://developer.yahoo.com/yui/compressor/">YUI compressor</a> is another good option for minifying javascript and CSS. There&#8217;s also <a href="http://www.coderjournal.com/2008/05/how-to-create-a-yui-compressor-msbuild-task/">an example MSBuild task</a> for that.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/_2iV_9sWvTc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/29/building-minification-into-msbuild-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/29/building-minification-into-msbuild-scripts/</feedburner:origLink></item>
		<item>
		<title>Why I don't like reset stylesheets</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/xTuu3XAE14s/</link>
		<comments>http://helephant.com/2009/08/23/why-i-dont-like-reset-stylesheet/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 17:37:25 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[reset stylesheet]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1598</guid>
		<description><![CDATA[I don't much like reset stylesheets. They make extra work when creating CSS and are an extra request for the browser to make to build a page.]]></description>
			<content:encoded><![CDATA[<p>Sometimes it&#8217;s hard to tell the difference between an idea that&#8217;s bad an idea that&#8217;s just different. Reset stylesheets have been one of those ideas for me but after working on a couple of different sites that use them I&#8217;ve decided I personally don&#8217;t like them.</p>
<p>The idea of a reset stylesheet is to strip the default style out of a webpage before you start to apply your design. This gives a predictable base for you to start with and removes browser inconsistencies with the default styles. There are a number of different reset stylesheet options. The most popular ones are from <a href="http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/">Eric Myer</a> and <a href="http://developer.yahoo.com/yui/reset/">YUI</a>.</p>
<p>Sounds like a great idea in theory. Slight browser inconsistencies (particularly with <a href="http://www.clagnut.com/blog/1287/">margins and padding</a>) are a pain to remember and can really mess up a design if you don&#8217;t test in multiple browsers.</p>
<h2>Why set the styles and then set them again?</h2>
<p>The big problem I have with it is how redundant it can be. The way I&#8217;ve seen reset stylesheets implemented is you include a reset stylesheet to reset everything to empty (including things like removing bold text from the &lt;strong&gt; tag) and then you create another stylesheet where you set all the styles that you want in the page.</p>
<p>It feels pretty redundant to have to set styles like bold text on the &lt;strong&gt; tag or numbered bullets on the ordered list. Most of the defaults make a lot of sense and most of them are pretty consistent between browsers.</p>
<p>It also feels kind of redundant to have the browser have to download and apply the reset styles and then download and apply the real styles. I haven&#8217;t actually ever seen a reset hurt the rendering time of a webpage but I have worked on a few sites where the number of requests that the browser was making became a problem and having the reset stylesheet as a separate request didn&#8217;t help.</p>
<h2>Why make me learn what the base styles are again?</h2>
<p>The other thing I don&#8217;t like about it is that the browser no longer acts the way I&#8217;d expect. I&#8217;ve got years of experience with how browsers render things and usually can picture in my head what a style should do to a page. Adding a reset stylesheet means that it&#8217;s not as intuitive any more.</p>
<h2>A better solution?</h2>
<p>I think a better solution would be using a stylesheet like <a href="http://developer.yahoo.com/yui/base/">YUI base</a> that makes browser defaults the same across different browsers as a starting point for your own stylesheet and then adding your own styles for the particular site. I don&#8217;t think I&#8217;d even bother setting a default style and then overriding, I think I&#8217;d prefer to just set the style once.</p>
<p>I think using something like the YUI base as a starting point is a great idea, but I think if I was going down this path I&#8217;d want to customize it as a I worked to make my own version to use on other sites.</p>
<h2>A tool I don&#8217;t like, but something worth thinking about</h2>
<p><a href="http://meyerweb.com/eric/thoughts/2008/04/17/crafting-ourselves/">Eric Myer&#8217;s response</a> to <a href="http://snook.ca/archives/html_and_css/no_css_reset/">people</a> <a href="http://meiert.com/en/blog/20080419/reset-style-sheets-are-bad/">questioning</a> whether reset stylesheets were a good idea or not was pretty much, use them if you find them useful and or don&#8217;t otherwise. I just wanted to put my hand up as not personally liking them (since they seem to be every at the moment) in the hope of making other people question them too.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/xTuu3XAE14s" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/23/why-i-dont-like-reset-stylesheet/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/23/why-i-dont-like-reset-stylesheet/</feedburner:origLink></item>
		<item>
		<title>Javascript prototype chaining</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/jNcXpjHif74/</link>
		<comments>http://helephant.com/2009/08/17/javascript-prototype-chaining/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 09:28:59 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[objects]]></category>
		<category><![CDATA[oo]]></category>
		<category><![CDATA[prototype]]></category>
		<category><![CDATA[prototypechain]]></category>
		<category><![CDATA[prototypechaining]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1252</guid>
		<description><![CDATA[Prototype chaining is used to build new types of objects based on existing ones. It has a very similar job to inheritance in a class based language.]]></description>
			<content:encoded><![CDATA[<p>Prototype chaining is used to build new types of objects based on existing ones. It has a very similar job to inheritance in a class based language.</p>
<p><a href="http://helephant.com/2008/09/constructor-functions/">Constructor functions</a> have a property called <a href="http://helephant.com/2009/01/javascript-object-prototype/">prototype</a>. Adding properties and methods to the prototype property will automatically add the method or property to all objects created by the constructor function.</p>
<p>Prototype chaining is an extension of this idea. The prototype property is just a regular javascript object so it&#8217;s possible to create a function&#8217;s prototype using another constructor function. When you do this, all of the properties and methods from the constructor function&#8217;s prototype are automatically added to new the prototype object. This makes it easy to create a constructor function that builds objects that are an extended version of an existing one.</p>
<p>For a simple example, imagine that you have a Pet constructor to make pet objects. Now you want to make Cat that is pretty much like a Pet but has a few differences.</p>
<p>Here&#8217;s the Pet constructor function from the <a href="/2009/01/javascript-object-prototype/">prototype example</a>:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span> = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sayHello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>We can give the cat all the properties of the Pet by setting it&#8217;s prototype to be a new pet object:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Cat<span class="br0">&#40;</span><span class="kw3">name</span>, hello, breed, whiskerLength<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">breed</span> = breed;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">whiskerLength</span> = whiskerLength;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span> = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>This is not really any different to creating the prototype using object literal syntax. The only big difference is that instead of manually adding the methods to the object literal, the Pet&#8217;s prototype does most that work for us.</p>
<p>We can still extend the Cat objects by adding extra methods to the prototype. Any methods added to the cat prototype will only be available to objects created by the Cat constructor. Objects created by the Pet constructor will still only have the methods added directly to Pet:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span>.<span class="me1">catNap</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot;: zzzzz&#8230;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">catNap</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>We can override any methods that came from the Pet constructor just by creating a new version of the function and assigning it to the Cat prototype. This will give cats different behaviour to the other pets:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span> + <span class="st0">&quot; from a cat..&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining1.html">Complete example</a></p>
<h2>Function resolution</h2>
<p>The most important thing to understand when using prototype chaining is how the method resolution works. Method resolution is what happens when you call a method or property on an object. It&#8217;s how javascript figures out what method or property should really be called.</p>
<p>First javascript checks the object itself for the method. This is important because it means you can override any method from the prototype on any object. If we call rufus.avoidPhoto() in the following example, javascript will call the avoidPhoto() function that has been assigned directly to rufus:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">avoidPhoto</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;Talk to my agent. &quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">avoidPhoto</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If the object doesn&#8217;t have the method set directly on it, javascript then looks for a Constructor function that created the object. Javascript checks the constructor&#8217;s prototype property for the method. If we call rufus.catNap(), javascript will find the method on Cat.prototype and use it:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span>.<span class="me1">catNap</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="kw3">name</span> + <span class="st0">&quot;: zzzzz&#8230;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">catNap</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>If the constructor function&#8217;s prototype doesn&#8217;t have the method defined, javascript looks at what constructor function was used to create the prototype property and does the same thing again. It will keep walking the prototype chain until it finds a function that matches. If rufus.eat() is called in the following example, javascript will walk up the prototype chain until it gets to the Pet constructor&#8217;s prototype object and then use Pet&#8217;s eat() method:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span> = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="me1">eat</span> : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="st0">&quot;nom! nom! nom!&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span> = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">..</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;Maine Coon&quot;</span>, <span class="nu0">7</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">eat</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p>All objects ultimately have the Object constructor at the end of their prototype chain. This means any methods or properties added to the Object property are automatically available to all objects. Javascript libraries often use this to extend the javascript API.</p>
<p>In the previous example, if we called rufus.toString(), javascript would check the rufus object, then the Cat object, then the Pet object. The Pet object&#8217;s prototype was created with the Object constructor (using the object literal shortcut) so javascript would then find the toString() method  on the Object&#8217;s prototype.</p>
<h2>Walking the prototype chain</h2>
<p>In theory it&#8217;s possible to walk the prototype chain using an object&#8217;s constructor property. Each object has a property called constructor that holds a reference to the constructor method that created it. The constructor&#8217;s prototype property is just a regular object, so it also has a constructor property that points to the next constructor function in the chain:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Cat<span class="br0">&#40;</span><span class="st0">&quot;Rufus&quot;</span>, <span class="st0">&quot;miaow&quot;</span>, <span class="st0">&quot;maine coon&quot;</span>, <span class="nu0">12</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.<span class="me1">constructor</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.<span class="me1">constructor</span>.<span class="me1">prototype</span>.<span class="me1">constructor</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining-constructor-broken1.html">Complete example</a></p>
<p>In theory the first alert statement will show the Cat constructor and the second will show the Pet constructor. In practise they both show the Pet constructor. This makes sense when you think about the prototype chaining behaviour. When you create the Cat&#8217;s prototype object, it&#8217;s constructor property will get set to Pet because it was created by the Pet constructor. When you look at the constructor property of the rufus object, rufus doesn&#8217;t have a value set explicitly on it so it looks for it on the Cat&#8217;s prototype object where it is set to Pet.</p>
<p>To fix the problem, you just need to set the constructor property explicitly on the  object itself when you create it:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Cat<span class="br0">&#40;</span><span class="kw3">name</span>, hello, breed, whiskerLength<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Pet.<span class="me1">call</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw3">name</span>, <span class="st0">&quot;cat&quot;</span>, hello<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">breed</span> = breed;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">whiskerLength</span> = whiskerLength;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// needed because otherwise it will inherit the constructor</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// from pet</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">constructor</span> = Cat;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining-constructor1.html">Complete example</a></p>
<p>In mozilla based browsers each object exposes another property called <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object/proto">__proto__</a> that gives you access to the way that the browser tracks the prototype chaining. The __proto__ property is a reference to the prototype property of an object&#8217;s constructor from the object itself:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.__proto__ == Cat.<span class="me1">prototype</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>rufus.__proto__.__proto__ == Pet.<span class="me1">prototype</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/prototype-chaining-proto1.html">Complete example</a></p>
<p>This property is not supported across all browsers, so it&#8217;s not very useful when writing code but it can be very useful when debugging because it lets you take a peak at what the browser is actually doing.</p>
<p>If you come from a class based language you might be tempted to use the prototype chain to figure out what type an object is. The properties and methods of a javascript object can be modified after the object is created, so knowing about the constructor is no guarantee that the object will conform to a particular interface. You may choose to make your code work this way by convention but it&#8217;s important to remember that it is not enforced by the language itself.</p>
<p>I think it&#8217;s also worth considering that this is not really the javascript way of doing things. In javascript you don&#8217;t get static types, instead you use duck typing to ask an object what it can do. It&#8217;s important to use javascript&#8217;s strengths as a dynamic language with features like <a href="http://helephant.com/2008/08/functions-are-first-class-objects-in-javascript/">first class functions</a>, <a href="http://helephant.com/2008/10/javascript-closures/">closures</a> and <a href="http://helephant.com/2008/08/javascript-anonymous-functions/">anonymous functions</a> to write concise and modular code rather than trying to make it act like a different type of language.</p>
<h2>What&#8217;s next?</h2>
<p>In languages like C# and Java you never really need to give a thought to the this operator. In javascript things are a little more complicated due to functions being first class objects. The next article talks about <a href="http://helephant.com/2009/11/javascript-method-context/">javascript method context</a>.</p>
<p>This article is part of a set of related posts about <a href="/2008/08/how-javascript-objects-work/">How javascript objects work</a>.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/jNcXpjHif74" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/17/javascript-prototype-chaining/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/17/javascript-prototype-chaining/</feedburner:origLink></item>
		<item>
		<title>SVG images as CSS backgrounds</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/9ibtjblNdrA/</link>
		<comments>http://helephant.com/2009/08/12/svg-images-as-css-backgrounds/#comments</comments>
		<pubDate>Wed, 12 Aug 2009 12:00:28 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[background-image]]></category>
		<category><![CDATA[background-size]]></category>
		<category><![CDATA[bleedingedgeofweb]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[rounded corners]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1506</guid>
		<description><![CDATA[Experimenting with using an SVG image as a CSS background image.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a lucky lady. I&#8217;m sitting here on the couch while my new husband cooks dinner (my turn tomorrow) which gives me the time to play with some new technology that&#8217;s caught my eye: <a href="http://my.opera.com/dstorey/blog/2007/02/01/using-svg-through-css-to-spice-up-your-d">using SVG images in CSS</a>.</p>
<h2>Creating the SVG background</h2>
<p>To try it out I decided to make me some tabs with rounded corners because they&#8217;re always a pain to do without creating heaps of extra markup and they never seem to go out of fashion.</p>
<p>SVG images are just text so you can create them in any text editor. There are also heaps of <a href="http://en.wikipedia.org/wiki/Svg#Software_and_support_in_applications">tools to that create SVG images</a>. I thought <a href="http://www.inkscape.org/">Inkscape</a> looked interesting.</p>
<p>My image is very simple, just two rectangles. One rectangle with rounded corners to make the top of the tab and one without to make the bottom:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;rect</span> <span class="re0">class</span>=<span class="st0">&quot;tab&quot;</span> <span class="re0">x</span>=<span class="st0">&quot;0&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;0&quot;</span> <span class="re0">rx</span>=<span class="st0">&quot;15&quot;</span> <span class="re0">ry</span>=<span class="st0">&quot;15&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">fill</span>=<span class="st0">&quot;url(#tab)&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;100%&quot;</span> <span class="re0">height</span>=<span class="st0">&quot;100%&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;rect</span> <span class="re0">class</span>=<span class="st0">&quot;highlight&quot;</span> <span class="re0">x</span>=<span class="st0">&quot;0&quot;</span> <span class="re0">y</span>=<span class="st0">&quot;50%&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">fill</span>=<span class="st0">&quot;url(#highlight)&quot;</span> <span class="re0">width</span>=<span class="st0">&quot;100%&quot;</span> <span class="re0">height</span>=<span class="st0">&quot;50%&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
</ol>
</div>
<p>I gave it a glassy looking gradient (colors of which I pinched from the buttons in Opera):</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;defs<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;lineargradient</span> <span class="re0">id</span>=<span class="st0">&quot;tab&quot;</span> x1=<span class="st0">&quot;0%&quot;</span> y1=<span class="st0">&quot;50%&quot;</span> x2=<span class="st0">&quot;0%&quot;</span> y2=<span class="st0">&quot;0%&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;stop</span> <span class="re0">offset</span>=<span class="st0">&quot;0%&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;tabHighlight&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;stop</span> <span class="re0">offset</span>=<span class="st0">&quot;100%&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;tabFill&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/lineargradient<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;lineargradient</span> <span class="re0">id</span>=<span class="st0">&quot;highlight&quot;</span> x1=<span class="st0">&quot;0%&quot;</span> y1=<span class="st0">&quot;100%&quot;</span> x2=<span class="st0">&quot;0%&quot;</span> y2=<span class="st0">&quot;0%&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;stop</span> <span class="re0">offset</span>=<span class="st0">&quot;0%&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;highlightLight&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;stop</span> <span class="re0">offset</span>=<span class="st0">&quot;100%&quot;</span> <span class="re0">class</span>=<span class="st0">&quot;highlightFill&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/lineargradient<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/defs<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p><a href="http://helephant.com/wp-content/uploads/2009/08/test.svg">Complete example</a></p>
<h2>Using it as a CSS background</h2>
<p>Using an SVG image as a CSS background isn&#8217;t any different to using a png or jpg. The only difference is you might want to use the new <a href="http://www.css3.info/preview/background-size/">CSS3 background-sizing</a> css property to make it scale across the whole element:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">background-image</span><span class="sy0">:</span> <span class="kw2">url</span><span class="br0">&#40;</span><span class="re4">test<span class="re1">.svg</span></span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">-o-background-<span class="kw1">size</span><span class="sy0">:</span> <span class="re3"><span class="nu0">100</span>%</span> <span class="re3"><span class="nu0">100</span>%</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">-webkit-background-<span class="kw1">size</span><span class="sy0">:</span> <span class="re3"><span class="nu0">100</span>%</span> <span class="re3"><span class="nu0">100</span>%</span><span class="sy0">;</span></div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/svg1.html">Complete example</a></p>
<p>Here&#8217;s how it looks in Safari and Opera:<br />
<img src="http://www.helephant.com/wp-content/uploads/2009/08/svg-tabs1.png" alt="tabs with SVG as background image"/></p>
<h2>What&#8217;s neat about using SVG</h2>
<p>It&#8217;s really neat being able to use a vector image in a webpage. It&#8217;s easy to make an image that looks great when you zoom in and can expand into a container of any width or height.</p>
<p>It&#8217;s easy to change the styling of the images because it&#8217;s all done through CSS. The SVG styling can live in the same CSS file as the rest of your webpage&#8217;s style. Different SVG images can share the same CSS file.</p>
<p>The SVG files are just text so you can generate them dynamically with a server side language.</p>
<p>It also means that the file tends to be pretty small. A bitmap image gets larger as the image gets bigger. A vector image like SVG only gets larger as it gets more complicated. You don&#8217;t get a lot of pixels for 200kb but you get a lot of SVG instructions. The file that I created was around 2kb.</p>
<p>It&#8217;s can be a nice solution for rounded corners and gradients (for things that are a bit too complicated for the <a href="http://www.css3.info/preview/rounded-border/">CSS3 border-radius</a> property). It doesn&#8217;t require multiple images, so you don&#8217;t need to worry about cutting the images up or the browser having to make a heap of requests.</p>
<h2>Limitations</h2>
<p>I was kind of hoping that I&#8217;d be able to put script in my SVG file so I could have some logic run when the image loaded. This works for SVG images included using the object tag but not for ones that are used as background images.</p>
<h2>Browser support</h2>
<p>In mid-2009 this technology is still pretty experimental.</p>
<p><strong>IE</strong> &#8211; no SVG support without using a <a href="http://wiki.svg.org/Adobe_SVG_Viewer">plugin</a>.</p>
<p><strong>Firefox</strong> &#8211; supports SVG images in the object tag, it doesn&#8217;t support <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=231179">using it in CSS</a> yet.</p>
<p><strong>Safari/Chrome</strong> &#8211; Safari 4.02 and Chrome 2.0 both support using SVG as CSS background images but I found the support a bit flaky. For example I had trouble when my SVG images had an external stylesheet or had the width and height of the SVG image set in percentages rather than absolute pixels. In both these cases the image just didn&#8217;t render as a background image but worked fine when included in the page through an object tag.</p>
<p><strong>Opera</strong> &#8211; has supported SVG as CSS background images since <a href="http://my.opera.com/dstorey/blog/2007/02/01/using-svg-through-css-to-spice-up-your-d">2007</a> and the version I have installed (9.63) didn&#8217;t have any problems with my simple example.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/9ibtjblNdrA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/12/svg-images-as-css-backgrounds/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/12/svg-images-as-css-backgrounds/</feedburner:origLink></item>
		<item>
		<title>A great big welcome to inline-block!</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/RUqOkBmP-Io/</link>
		<comments>http://helephant.com/2009/08/09/a-great-big-welcome-to-inline-block/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 18:33:04 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[block]]></category>
		<category><![CDATA[display]]></category>
		<category><![CDATA[formlayout]]></category>
		<category><![CDATA[inline]]></category>
		<category><![CDATA[inline-block]]></category>
		<category><![CDATA[layout]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1117</guid>
		<description><![CDATA[Inline-block is a halfway point between setting an element's display to inline or to block. It keeps the element in the inline flow of the document like display:inline does, but you can manipulate the element's box attributes (width, height and vertical margins) like you can with display:block.]]></description>
			<content:encoded><![CDATA[<p>One of the really great things about Firefox 3 is that it <a href="https://developer.mozilla.org/en/CSS_improvements_in_Firefox_3">includes support</a> for the CSS display:inline-block attribute! This means we actually can start using the attribute because that all <a href="#browserSupport">modern browsers (IE7 included) have support for it</a>.</p>
<p>Inline-block is a halfway point between setting an element&#8217;s display to inline or to block. It keeps the element in the inline flow of the document like display:inline does, but you can manipulate the element&#8217;s box attributes (width, height and vertical margins) like you can with display:block.</p>
<p>Here&#8217;s a <a href="http://www.helephant.com/wp-content/uploads/2009/08/inline-block-simple1.html">simple example</a> that shows the difference between an element with it&#8217;s display set to inline and one set to inline-block:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1"><span class="re1">.inline-block</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">display</span><span class="sy0">:</span> inline-<span class="kw2">block</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="kw2">yellow</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span> <span class="re3">1px</span> <span class="kw1">black</span> <span class="kw2">solid</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">35px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">margin-top</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">margin-bottom</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re1">.inline</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">display</span><span class="sy0">:</span> <span class="kw2">inline</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">background-color</span><span class="sy0">:</span> <span class="kw2">lime</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">border</span><span class="sy0">:</span> <span class="re3">1px</span> <span class="kw1">black</span> <span class="kw2">solid</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">height</span><span class="sy0">:</span> <span class="re3">35px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">margin-top</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">margin-bottom</span><span class="sy0">:</span> <span class="re3">20px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The green inline span ignores the height and vertical margins set on it. The yellow inline-block span obeys them which affects the size of the box and the line height but doesn&#8217;t stop the span being in the inline flow of the document:<br />
<img src="http://www.helephant.com/wp-content/uploads/2009/08/inline-block11.png" alt="you can set width and height on an inline-block element but not on an inline one" class="border"/></p>
<h2>So why is this a big deal?</h2>
<p>The biggest reason this is exciting is it means you can now do some simple page layout without needing to  use floats or absolute positioning.</p>
<h3>Use inline-block to line things up without using floats</h3>
<p>Using inline-block we can <a href="http://www.mindfly.com/blog/post/2008/12/The-Curious-Case-of-Inline-Block.aspx">line items up next to each other without using floats</a>. My favourite example of this is the astoundingly frustrating task of creating a tabular form. Imagine you have a stupidly simple form where you have one label next to one input item (here&#8217;s another <a href="http://helephant.com/2008/07/form-layout-using-negative-margins/">approach for more realistic forms</a>):</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;fieldset&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;legend&gt;Comment form&lt;/legend&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;label for=&quot;name&quot;&gt;Name:&lt;/label&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input type=&quot;text&quot; id=&quot;name&quot;/&gt;&lt;br /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;label for=&quot;email&quot;&gt;Email:&lt;/label&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input type=&quot;text&quot; id=&quot;email&quot;/&gt;&lt;br /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;label for=&quot;comment&quot;&gt;Comment:&lt;/label&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;textarea id=&quot;comment&quot;&gt;&lt;/textarea&gt;&lt;br /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/fieldset&gt;</div>
</li>
</ol>
</div>
<p>To make the form elements line up you just need to set a width on the label. No floats are needed so you don&#8217;t need to worry about clearing or overflow:auto or any of the issues that make floats a bit of a pain to use:</p>
<div class="geshi no css">
<ol>
<li class="li1">
<div class="de1">label</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">display</span><span class="sy0">:</span> inline-<span class="kw2">block</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">width</span><span class="sy0">:</span> <span class="re3">100px</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">vertical-align</span><span class="sy0">:</span> <span class="kw1">top</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="http://www.helephant.com/wp-content/uploads/2009/08/inline-block-form1.html">Complete example</a></p>
<p><img src="http://www.helephant.com/wp-content/uploads/2009/08/inline-block-form1.png" alt="tabular form"/></p>
<h3>Align elements using text-align and vertical-align</h3>
<p>Elements using inline-block can be horizontally and vertically aligned using the text-align and vertical-align attributes.</p>
<p>This is a big advantage of using inline-block instead of floats. With floats you can only really vertically align a box to the top of the other boxes it is next to. With inline-block, you can use any of the <a href="https://developer.mozilla.org/en/CSS/vertical-align">vertical align</a> attributes:<br />
<img src="http://www.helephant.com/wp-content/uploads/2009/08/inline-block-vertical1.png"/><br />
<a href="http://www.helephant.com/wp-content/uploads/2009/08/inline-block-alignment1.html">Complete example</a></p>
<p>There&#8217;s a really <a href="http://blog.mozilla.com/webdev/2009/02/20/cross-browser-inline-block/">nice example</a> of using this to create a grid of images.</p>
<h2>A small gotcha &#8211; spaces between the elements</h2>
<p>If you&#8217;re used to the way block elements line up next to each other, there&#8217;s one thing about inline-block elements that might surprise you. Inline-block elements are still part of the inline flow of the document so if there is a space between the items, there will be a space between the boxes.</p>
<p>So markup like <a href="/wp-content/uploads/2009/08/inline-block-spacing.html">this</a>:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;div id=&quot;nav&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;a href=&quot;/&quot;&gt;Home&lt;/a&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;a href=&quot;/&quot;&gt;Swizzlesticks&lt;/a&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;a href=&quot;/&quot;&gt;Widgets&lt;/a&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;a href=&quot;/&quot;&gt;Acme products&lt;/a&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;a href=&quot;/&quot;&gt;Specials&lt;/a&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;a href=&quot;/&quot;&gt;Contact us&lt;/a&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
</ol>
</div>
<p>Would produce elements that look like this:<br />
<img src="/wp-content/uploads/2009/08/inline-block-spacing.png" alt="a space between each element" /></p>
<p>There&#8217;s a kind of <a href="http://www.mindfly.com/blog/post/2009/07/10/Making-Inline-Blocks-Play-Nice-With-Webkit.aspx">nasty hack</a> to get around this. You can set the parent container&#8217;s font-size to 0 and then reset it to whatever you need for the child elements. I think if you need to do that, you should probably just use block elements and floats.</p>
<h2 id="browserSupport">Who supports it</h2>
<p>Now that Firefox 3 supports inline-block, it has pretty good browser support.</p>
<p><strong>IE</strong> &#8211; it&#8217;s supported completely in IE8. IE7 only support inline-block on elements that are usually inline (like spans and anchor tags). IE6&#8242;s implementation is pretty flaky.</p>
<p><strong>Firefox</strong> &#8211; it&#8217;s supported  in Firefox 3 and above.</p>
<p><strong>Webkit</strong> &#8211; it&#8217;s supported in Safari 3 and above. It&#8217;s supported in all versions of Chrome.</p>
<p><strong>Opera</strong> &#8211; it&#8217;s supported in Opera9 and above (I&#8217;m not sure about earlier versions).</p>
<p>Check out the <a href="http://www.quirksmode.org/css/display.html">quirks mode compatibility charts</a> for more information. There&#8217;s also a great article about <a href="http://foohack.com/2007/11/cross-browser-support-for-inline-block-styling/">gotchas getting it working across browsers</a>.</p>
<h3>Workarounds for IE6 and IE7</h3>
<p>In IE6 and IE7 you can only apply inline-block to inline elements. You can&#8217;t apply it to block elements.</p>
<p>Fortunately this is pretty easy to work around because in IE6 and IE7 the display:inline actually acts like inline-block. It supports applying attributes like width and height on both inline and block elements, not just block elements like in other browsers.</p>
<p>I wouldn&#8217;t really recommend using inline-block at all in IE6 because it seems generally flaky. The inline-block elements don&#8217;t seem to sit in the right place in the line. Here&#8217;s how my earlier example looks in IE6:<br />
<img src="/wp-content/uploads/2009/08/inline-block-simple-ie6.png" alt="inline-block elements don't sit in the right place on the line" class="border"/></p>
<h3>Workarounds for Firefox 2</h3>
<p>There are a few similar <a href="https://developer.mozilla.org/en/CSS/display#section_4">display values</a> that might be useful if you need to support earlier versions of Firefox, but none of them do exactly what inline-block does.</p>
<ul>
<li><strong>-moz-inline-block</strong> &#8211; this seems to be an experiemental version of inline-block. It&#8217;s now obsolete. I always found it to be buggy.</li>
<li><strong>-moz-inline-box</strong> &#8211; doesn&#8217;t wrap to a second line.</li>
<li><strong><a href="http://blog.hedgerwow.com/2007/11/14/item-list-grid-real-world-practice-with-displayinline-block-across-browsers/">-moz-inline-stack</a></strong> &#8211; this is supposed to be used for XUL rather than pages. It doesn&#8217;t have the wrapping problem that -moz-inline-box has but <a href="http://blogs.telerik.com/petjavassileva/posts/07-09-16/the_-moz-inline-stack_traps.aspx">has other issues of its own</a>.</li>
</ul>
<img src="http://feeds.feedburner.com/~r/helephant/~4/RUqOkBmP-Io" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/09/a-great-big-welcome-to-inline-block/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/09/a-great-big-welcome-to-inline-block/</feedburner:origLink></item>
		<item>
		<title>Restarting an IIS6 app pools using .NET</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/tiyT73QkEJw/</link>
		<comments>http://helephant.com/2009/08/09/restarting-an-iis6-app-pools-using-wmi/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 16:26:45 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[active directory]]></category>
		<category><![CDATA[app-pool]]></category>
		<category><![CDATA[iis]]></category>
		<category><![CDATA[iis6]]></category>
		<category><![CDATA[wmi]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1445</guid>
		<description><![CDATA[Two little code snippets for recycling IIS6 application pools in through .NET code.]]></description>
			<content:encoded><![CDATA[<p>This week I was writing an admin tool that needed to recycle some IIS6 application pools. I found two ways to do it, one using Window Management Instrumentation (WMI) and the other using the DirectoryEntry class (part of the active directory classes).</p>
<p>Here&#8217;s a little code sample for the <a href="http://blogs.iis.net/chrisad/archive/2006/08/30/Recycling-Application-Pools-using-WMI-in-IIS-6.0.aspx">WMI way</a>:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1">ManagementScope scope <span class="sy0">=</span> <span class="kw3">new</span> ManagementScope<span class="br0">&#40;</span><span class="st0">@&#8221;\\localhost\root\MicrosoftIISv2&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">WqlObjectQuery query <span class="sy0">=</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw3">new</span> WqlObjectQuery<span class="br0">&#40;</span><span class="st0">@&#8221;SELECT * FROM IIsApplicationPool &nbsp;WHERE Name LIKE &#39;% .NET2&#39;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">ManagementObjectSearcher searcher <span class="sy0">=</span> <span class="kw3">new</span> ManagementObjectSearcher<span class="br0">&#40;</span>scope, query<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span> <span class="br0">&#40;</span>ManagementObject appPool <span class="kw1">in</span> searcher.<span class="me1">Get</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; appPool.<span class="me1">InvokeMethod</span><span class="br0">&#40;</span><span class="st0">&quot;Recycle&quot;</span>, <span class="kw1">null</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Here&#8217;s a code sample for the <a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.directoryentry.aspx">DirectoryEntry</a> way:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1">DirectoryEntry appPools <span class="sy0">=</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">new</span> DirectoryEntry<span class="br0">&#40;</span><span class="st0">&quot;IIS://localHost/w3svc/AppPools&quot;</span>, <span class="st0">&quot;&quot;</span>, <span class="st0">&quot;&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">foreach</span> <span class="br0">&#40;</span>DirectoryEntry child <span class="kw1">in</span> appPools.<span class="me1">Children</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>child.<span class="me1">Name</span>.<span class="me1">EndsWith</span><span class="br0">&#40;</span><span class="st0">&quot;.NET2&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; child.<span class="me1">Invoke</span><span class="br0">&#40;</span><span class="st0">&quot;Recycle&quot;</span>, <span class="kw1">null</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>There are some <a href="http://stackoverflow.com/questions/249927/application-pool-from-c">more great examples</a> of <a href="http://stackoverflow.com/questions/662879/how-can-i-look-up-iis-site-id-in-c">how to do these types of things</a> on stack overflow.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/tiyT73QkEJw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/09/restarting-an-iis6-app-pools-using-wmi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/09/restarting-an-iis6-app-pools-using-wmi/</feedburner:origLink></item>
		<item>
		<title>Our web 2.0 wedding</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/L4Jmb8QicNc/</link>
		<comments>http://helephant.com/2009/08/01/our-web-20-wedding/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 18:38:12 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[My life as a coder]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[Web development]]></category>
		<category><![CDATA[basecamp]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[flickr]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[googledocs]]></category>
		<category><![CDATA[helen]]></category>
		<category><![CDATA[nerd]]></category>
		<category><![CDATA[reallife]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[wedding]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1340</guid>
		<description><![CDATA[The story of how Joe and I used our favourite web tools to organise our wedding and share the experience with the people who couldn't be there.]]></description>
			<content:encoded><![CDATA[<p>In November 2008 <a href="http://www.otakunews.com">Joe</a> asked me to marry him. We decided to set a date for July 2009 and so started our journey organising an international wedding.</p>
<p>But web developers in love are still web developers. In between trying on wedding clothes and freaking out about becoming grown ups, the funny thing we noticed was we started applying some of the tools that we found useful in our work to the logistics of planning our wedding. This is the story of how <a href="#basecamp">Basecamp</a>, <a href="#googledocs">Google docs</a>, <a href="#googlelocalsearch">Google local search</a>, <a href="#delicious">delicious</a>, <a href="#flickrfacebook">Flickr and Facebook</a> and <a href="#twitter">twitter</a> helped us organise everything, share the experience with the people who couldn&#8217;t be there and keep us sane.</p>
<p><img src="/wp-content/uploads/2009/08/helenjoe178.jpg" alt="Helen and Joe - we scrub up well"/></p>
<h2 id="basecamp">Basecamp to project manage the wedding</h2>
<p>After spending the last six months thinking of almost nothing else, I think a wedding is some sort of a relationship test before you commit to each other for eternity. It&#8217;s stressful! Everyone has a different idea of how the wedding should be, there&#8217;s a heap of things to do by a certain date and things rarely go as planned. It&#8217;s spookily like a software project.</p>
<p>When we started talking about what we needed to organise, I&#8217;d rattle off a big list of things, and Joe would start to look freaked out. Then he (being a software developer, too) got the brilliant idea of using <a href="http://www.basecamphq.com/">Basecamp</a> as a project management tool to keep track of everything that we needed to do! Suddenly everything we needed to do was in one place and we didn&#8217;t need to freak out about forgetting things. We could see what was done and what we had to do.</p>
<p>It also gave us a sense of progress as we worked through the list. Being the big nerd that I am, I got a real sense of accomplishment every time I could log on to Basecamp and tick another item off the list (much like moving an item on the board in scrum). After a while it did start to feel like I was having a wedding to tick things off the list rather than the other way around.</p>
<p><img src="/wp-content/uploads/2009/06/todolists.png" alt="todo lists helped us keep track of progress" /></p>
<p>We also originally gave our parents accounts so they could feel part of the planning process. The great thing is it gave them a place to throw around ideas, which were recorded against the relevant To Do items. The problem was that getting more people involved made it harder to keep things as simple as we wanted them. In practise, we found they only logged in for the first month or two and then forgot about it. :)</p>
<p><img src="/wp-content/uploads/2009/06/comments.png" alt="The comments on the todo items were handy for discussion" /></p>
<h2 id="googledocs">Google docs to keep track of people, presents and budgets</h2>
<p>We used Google docs to create some shared spreadsheets to keep track of who was coming, who we needed to send thank you letters to and how much we had spent.</p>
<p>The budget spreadsheet was particularly good at reminding us how much of our housing deposit we had spent. We used colour coding to keep track of who we&#8217;d paid and who we hadn&#8217;t and always had a good idea of what bills were coming up. The fact the spreadsheets were online and shared made it really easy to keep them up to date. The support for simple formulas made it easy to keep running totals of guests and expenses.</p>
<p><img src="/wp-content/uploads/2009/06/google-docs.png" alt="shared spreadsheets" /></p>
<p>We also learnt a lesson from the engagement party about thankyou cards. On the way home the presents and cards got all mixed up so we ended up sending a thankyou note to someone for a clock they&#8217;d never heard of (oops!). So after our wedding while we were waiting for the taxi to come take us to the airport, we just fired up Google docs and started going through our presents logging what everyone gave us so this time we can give everyone thankyou notes for things they actually gave us.</p>
<h2 id="googlelocalsearch">Google local search to find hairdressers, florists and makeup artists</h2>
<p>I&#8217;ve only lived in London for five years and don&#8217;t really know anyone else in the area who has gotten married so I found <a href="http://maps.google.co.uk/maps?q=bridal%20makeup&amp;oe=utf-8&amp;rls=org.mozilla:en-GB:official&amp;client=firefox-a&amp;um=1&amp;ie=UTF-8&amp;sa=N&amp;hl=en&amp;tab=wl">Google&#8217;s local search</a> a real help for finding local suppliers. The best thing about it is definitely the map feature, which let me browse for people who were close to where we live or easy to get to by car, without having to confine the search to a really specific area.</p>
<p><img src="/wp-content/uploads/2009/06/google-maps.png" alt="Bridal makeup in London" /></p>
<p>Between Google local search and <a href="http://www.yell.com">yell.com</a> I was able to get a really good idea of what my options were and find a photographer, a makeup artist, a florist and every bridal shop in a 10 mile radius. The people we found were amazingly good too! Their websites helped us narrow which ones had nice looking work and which ones were in our price range. We then met up with the ones we liked and booked them up for the day.</p>
<h2 id="delicious">Delicious to remember my research</h2>
<p>Once I&#8217;d gone to the trouble of tracking down every florist in North London, delicious gave me a good place to catalogue them so I wouldn&#8217;t need to do it again later.</p>
<p>The tagging is a great feature because it made it easy to separate wedding from webdev (important for both work and home life). I also liked the privacy feature so I could save a list of wedding dresses without my technical friends knowing that I had gone wedding mad. :)</p>
<p><img src="/wp-content/uploads/2009/06/delicious.png" alt="my secret wedding dress collection" /></p>
<h2 id="flickrfacebook">Facebook and Flickr to share the special moments</h2>
<p>The hardest thing about an international wedding is the people who couldn&#8217;t be there. I used my iPhone and Flickr to document every step so even if my Mum couldn&#8217;t be there when I was looking for the dress, I could still get her (and my virtual bridemaids&#8217;) feedback before making the important decisions.</p>
<p>The privacy option and guest pass were fantastic because I could create a set that even people who didn&#8217;t have a flickr account could see while making sure Joe was the only person who I had contact with who hadn&#8217;t seen my dress.</p>
<p><img src="/wp-content/uploads/2009/06/flickr.png" alt="Flickr helped me get feedback from my virtual bridesmaids" /></p>
<p>After the wedding we put the best of the photos up on both Flickr and Facebook. Again we used the Flickr guest pass to share the day with people who were not social-networked and Facebook to share with those who were. Having tools to share our wedding with friends and family in Australia and America was truly magic. It didn&#8217;t change the fact that I missed them on the day but it made it bearable that they weren&#8217;t and meant they could still be a little part of it even halfway across the world.</p>
<h2 id="twitter">Wedding tweets &#8211; to be web 2.0 trendy</h2>
<p>Just kidding! :D (Nowhere to put a phone in the dress anyway) ;)</p>
<h2>The wedding</h2>
<p>We got married! We had a really great day. It went amazingly smoothly, but I think that was as much luck as planning. We didn&#8217;t end up insane or up to our ears in debt. Wedding success!</p>
<p><img src="/wp-content/uploads/2009/08/helenjoe158.jpg" alt="signing the wedding register"/></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/L4Jmb8QicNc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/08/01/our-web-20-wedding/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/08/01/our-web-20-wedding/</feedburner:origLink></item>
		<item>
		<title>Ada Lovelace day – Molly Holzschlag, Kathy Hassinger and my mum</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/r7nWh0m2ZPY/</link>
		<comments>http://helephant.com/2009/03/24/ada-lovelace-day/#comments</comments>
		<pubDate>Tue, 24 Mar 2009 22:58:47 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[My life as a coder]]></category>
		<category><![CDATA[AdaLovelaceDay09]]></category>
		<category><![CDATA[geek]]></category>
		<category><![CDATA[girly geeks]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1302</guid>
		<description><![CDATA[Stories about three geek women who I admire to help celebrate Ada Lovelace day.]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve been really enjoying all <a href="http://ada.pint.org.uk/map.html">the stories</a> posted for <a href="http://findingada.com/">Ada Lovelace day</a>, a day where we&#8217;re encouraged to blog about remarkable women in IT. I thought it was a nice idea when my friend emailed me about it so I thought I&#8217;d pitch in and write about three geek women who inspire me.</p>
<h2>Web development hero &#8211; Molly Holzschlag</h2>
<p>I&#8217;m a web developer. It was the internet that got me interested in computers beyond being a game machine. It was web development (and <a href="http://creatures.wikia.com/wiki/Creatures_Wiki_Homepage">Creatures</a>) that really made me want to be a programmer. I&#8217;ve been doing this for over ten years now and one woman who&#8217;s been a real hero of mine in the web development community is <a href="http://www.molly.com/">Molly Holzschlag</a>.</p>
<p>Molly has been part of the campaign to make the web a more open and interoperable place. She has <a href="http://www.molly.com/books.php">written books</a>, taught classes and given <a href="http://www.molly.com/2007/12/05/conversation-with-bill-gates-about-ie8-and-microsoft-transparency/">Bill Gates shit about the IE team going off the radar</a>. She has helped educate developers and been part of making web developers care about web standards, something that seemed like an impossible dream back in the late nineties browser wars. Now even Microsoft brags about <a href="http://blogs.msdn.com/ie/archive/2007/12/19/internet-explorer-8-and-acid2-a-milestone.aspx">improvements to standards compatibility</a> in their latest browser. Because of the work that she&#8217;s been part of, the web doesn&#8217;t belong to hyperglobal megacorp or the government (or Google &#8211; yet). It still belongs to us, anyone who hooks a box onto the network and spends some time communing with a text editor.</p>
<h2>A personal favourite geek girl &#8211; Kathy Hassinger</h2>
<p><a href="http://kathyhassinger.com/">Kathy&#8217;s</a> friend of mine who is a technical writer. Until recently she was working with developers to document software for scientists. How cool is that?</p>
<p>I wish I could write as engagingly and as amusingly as Kathy. Go read her <a href="http://rathersillyblog.blogspot.com/2009/03/ada-lovelace-day.html">Ada Lovelace</a> post. She managed to capture the essence of what&#8217;s important about the whole subject of women in IT with a story about Colonel Samantha Carter from StarGate and the one observation that she&#8217;s a powerful role model because the people on her team don&#8217;t treat her any differently because she&#8217;s a woman.</p>
<p>Geekdom needs people who can communicate and make people think about things as much as we need people who build things. Code isn&#8217;t enough by itself to make a product great, you also need to be able to connect with the people who use it, get them to trust you and then help them <a href="http://headrush.typepad.com/creating_passionate_users/2005/01/keeping_users_e.html">kick arse</a> with it.</p>
<p>Kathy&#8217;s not just a great writer. She&#8217;s a sweet, funny and vibrant person as well. She&#8217;s passing her geek heritage on to the next generation through her neice (who she dotes on, encourages and regularly takes to the local science centre). She&#8217;s one of those people who has always got something interesting to say about any topic. She is also unashamedly and openly a geek, something that inspires me to not try to hide who I am when I meet people who might not understand.</p>
<h2>Someone who made it possible for me &#8211; my Mum</h2>
<p>My mum&#8217;s an English language geek rather than a computer geek but it was her influence that made it possible for me to become a programmer. In our house there was never the idea that my sister and I had to be a certain way because we were girls. We were encouraged to read and to be imaginative and to build things. We played with lego as well as dolls, climbed trees, dug holes, made cubby houses. We were wrote stories and had a big box full of stuff to make things from. We were taught to question things (which drove my parents a little mad as we got older) and to think for ourselves. I was real lucky to get geek parents. :)</p>
<p>My mum loves to learn things and has three masters degrees in English. I can remember being about five or six and going with her to the University of Queensland when she was dropping in an assignment. I remember seeing the beautiful lawns and the huge sandstone buildings and telling myself that I was going to go there one day. I still had that image in my head when I was slogging through year 12. The story I told myself of the place created just so people could try new ideas and learn things was what made all that hard work seem worthwhile.</p>
<p>The biggest thing that I got from my mum that&#8217;s helped me be a programmer is my writing. Being able to communicate clearly and effectively is such a huge advantage to getting your ideas heard. Good ideas can&#8217;t change things if you can&#8217;t share them with other people.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/r7nWh0m2ZPY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/03/24/ada-lovelace-day/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/03/24/ada-lovelace-day/</feedburner:origLink></item>
		<item>
		<title>To(): a handy way to convert strings to other types</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/keSrTnBWQL0/</link>
		<comments>http://helephant.com/2009/02/23/to-a-handy-way-to-convert-strings-to-other-types/#comments</comments>
		<pubDate>Mon, 23 Feb 2009 17:01:16 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[extensionmethods]]></category>
		<category><![CDATA[generics]]></category>
		<category><![CDATA[reflection]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1285</guid>
		<description><![CDATA[The int.parse() method is one I use a lot in ASP.NET so I wrote a handy extension method called To using generic return types and a little reflection that makes converting all these string values to another type incredibly simple.]]></description>
			<content:encoded><![CDATA[<p>A webpage is just a giant string. As fancy that the server side abstractions can get (particularly in the .NET world) all we&#8217;re ultimately doing is reading the string given to us by the browser request so we can build the right new string for it to display to the user.</p>
<p>.NET is a strongly typed world so this involves lots of parsing values from the strings. We need to parse strongly typed values from query strings, server controls, configuration files and a hundred other places where .NET meets the outside world.</p>
<p>So since I use int.parse() so much in ASP.NET so I wrote a <a href="http://msdn.microsoft.com/en-us/library/bb383977.aspx">handy extension method</a> called To (perfect naming thanks Dan) using <a href="/2008/05/generic-method-return-types/">generic return types</a> and a little reflection that makes converting all these string values to another type incredibly simple:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">class</span> StringUtils</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// This method will parse a value from a string.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// If the string is null or not the right format to parse a valid value,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// it will return the default value provided.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> T To<span class="sy0">&lt;</span>t<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw1">this</span> <span class="kw4">string</span> value, T defaultValue<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; where T<span class="sy0">:</span> <span class="kw4">struct</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var type <span class="sy0">=</span> <span class="kw3">typeof</span><span class="br0">&#40;</span>T<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>value <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var parse <span class="sy0">=</span> type.<span class="me1">GetMethod</span><span class="br0">&#40;</span><span class="st0">&quot;TryParse&quot;</span>, <span class="kw3">new</span> Type<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> <span class="kw3">typeof</span><span class="br0">&#40;</span><span class="kw4">string</span><span class="br0">&#41;</span>, type.<span class="me1">MakeByRefType</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var parameters <span class="sy0">=</span> <span class="kw3">new</span> <span class="kw4">object</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> value, <span class="kw1">default</span><span class="br0">&#40;</span>T<span class="br0">&#41;</span> <span class="br0">&#125;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span><span class="br0">&#40;</span><span class="kw4">bool</span><span class="br0">&#41;</span>parse.<span class="me1">Invoke</span><span class="br0">&#40;</span><span class="kw1">null</span>, parameters<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="br0">&#40;</span>T<span class="br0">&#41;</span>parameters<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> defaultValue;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// This method will parse a value from a string.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// If the string is null or not the right format to parse a valid value,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// it will return the default value for the type.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">/// &lt;/summary&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">static</span> T To<span class="sy0">&lt;/</span>t<span class="sy0">&gt;&lt;</span>t<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw1">this</span> <span class="kw4">string</span> value<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; where T <span class="sy0">:</span> <span class="kw4">struct</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> value.<span class="me1">To</span><span class="sy0">&lt;/</span>t<span class="sy0">&gt;&lt;</span>t<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="kw1">default</span><span class="br0">&#40;</span>T<span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>t<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Now getting an int from the query string is only 10 extra characters to type:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1">var value <span class="sy0">=</span> Request.<span class="me1">QueryString</span><span class="br0">&#91;</span><span class="st0">&quot;value&quot;</span><span class="br0">&#93;</span>.<span class="me1">To</span><span class="sy0">&lt;</span><span class="kw4">int</span><span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span><span class="kw4">int</span><span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/toextensionmethod.zip">Complete example</a></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/keSrTnBWQL0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/23/to-a-handy-way-to-convert-strings-to-other-types/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/02/23/to-a-handy-way-to-convert-strings-to-other-types/</feedburner:origLink></item>
		<item>
		<title>Improving the way ASP.NET handles 404 requests</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/50LuI_SI4jw/</link>
		<comments>http://helephant.com/2009/02/11/improving-the-way-aspnet-handles-404-requests/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:51:43 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[404]]></category>
		<category><![CDATA[errorhandling]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[statuscodes]]></category>
		<category><![CDATA[userexperience]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1213</guid>
		<description><![CDATA[How (and why) to make your ASP.NET site's error handling better by returning the right response codes and redirecting to the error page without changing the url.]]></description>
			<content:encoded><![CDATA[<p>Sometimes things go wrong, information goes out of date, pages go missing. When these things happen it&#8217;s up to the humble 404 error page to let your users and the search engines know that things have changed. ASP.NET has a built in <a href="http://www.codeproject.com/KB/aspnet/customerrorsinaspnet.aspx">custom error pages</a> feature to make it easy to set up your 404 page but here are a couple of tips to make the 404 experience a little better.</p>
<h2>Return the right status code</h2>
<p>By default the page handling a 404 error page <a href="http://searchengineland.com/url-rewriting-custom-error-pages-in-aspnet-20-12234">doesn&#8217;t return a 404 status code to the browser</a>. It displays the error message that you provided to the user but doesn&#8217;t have any extra information to flag the page as an error page.</p>
<p>This is called a <a href="http://googlewebmastercentral.blogspot.com/2008/08/farewell-to-soft-404s.html">soft 404</a>. Soft 404 pages aren&#8217;t as good as ones that return the 404 status code because returning the 404 status code lets anything accessing your file that the page is an error page rather than a real page of you site. This is mostly useful for search engines because then they know they should remove dead pages from their index so users won&#8217;t follow dead links into your site from results pages.</p>
<p>Pages that return 404 status codes are also useful for error detection because they&#8217;ll be recorded in your server logs so if you have unexpected 404 errors, they&#8217;ll be easy to find. Here&#8217;s an example of the 404 error report in <a href="https://www.google.com/webmasters/tools/">Google Webmaster tools</a>:<br />
<img src="/wp-content/uploads/2009/02/googlewebmaster.png" alt="Google webmaster tools has a nice report of any 404 links it found"/></p>
<p>Here&#8217;s how it looks if we use <a href="">Firebug</a> to spy on what&#8217;s happening when we load an invalid url into an ASP.NET application. It first shows a 302 redirect as the ASP.NET custom error handling code redirects from the original page to the custom 404 error handler. Then it shows a 200 ok code because the page is just a regular page and doesn&#8217;t know it should do any different:<br />
<img src="/wp-content/uploads/2009/02/soft404.png" alt="firebug shows a 302 redirect and then a 200 ok status code"/></p>
<p>This is very easy to fix. You just need to explicitly set the Response.StatusCode property to 404 in the 404 error page:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">void</span> Page_Load<span class="br0">&#40;</span><span class="kw4">object</span> sender, EventArgs e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Response.<span class="me1">StatusCode</span> <span class="sy0">=</span> <span class="nu0">404</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Once this is done, we still get the 302 redirect and then the 404 error code that should be returned:<br />
<img src="/wp-content/uploads/2009/02/hard404.png" alt="now firebug reports a correct 404 status code when we hit a url that doesn't exist"/></p>
<h2>Redirecting to the error page</h2>
<p>The ASP.NET custom error handling logic automatically redirects the user to your 404 error page. The only bad thing is they do a browser redirect rather than a server redirect so the url of the page changes for the user from the url that they typed in, to the url of your error page.</p>
<p>So if a user entered in a url like http://yoursite.com/fake.aspx they&#8217;d be redirected to http://yoursite.com/404.aspx?aspxerrorpath=/ErrorCodes/Fake.aspx.</p>
<p>It doesn&#8217;t seem very slick to me. If the user typed in the url manually they will probably get quite confused (and probably a little annoyed) when the url they typed in has suddenly changed. If they simply made a mistake they&#8217;ll need to type in the whole url again. The physical location of the error page just doesn&#8217;t seem like information that will be important to the user while the url of the page they were trying to access is.</p>
<p>The good news is that it&#8217;s quite easy to create a <a href="http://msdn.microsoft.com/en-us/library/ms227673.aspx">HttpHandler</a> that can listen for 404 errors and show the error page that is set up in the web.config without changing the url.</p>
<p>Here&#8217;s an example of what the code would look like. Notice that if you&#8217;re using a HttpModule to handle the 404 error pages, you can set the status code to the right thing in the module and don&#8217;t need to do it in the page:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">public</span> <span class="kw4">class</span> ErrorModule <span class="sy0">:</span> IHttpModule</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw1">void</span> Init<span class="br0">&#40;</span>HttpApplication context<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// Listen for errors</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; context.<span class="me1">Error</span> <span class="sy0">+=</span> context_Error;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">void</span> context_Error<span class="br0">&#40;</span><span class="kw4">object</span> sender, EventArgs e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var context <span class="sy0">=</span> HttpContext.<span class="me1">Current</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// This example only handle 404 errors</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// You could also add some similar logic for 500 internal server</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// errors (logic errors) and do some logging</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; var error <span class="sy0">=</span> context.<span class="me1">Server</span>.<span class="me1">GetLastError</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw1">as</span> HttpException;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>error.<span class="me1">GetHttpCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">==</span> <span class="nu0">404</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// we can still use the web.config custom errors information to</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// decide whether to redirect</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; var config <span class="sy0">=</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>CustomErrorsSection<span class="br0">&#41;</span>WebConfigurationManager.<span class="me1">GetSection</span><span class="br0">&#40;</span><span class="st0">&quot;system.web/customErrors&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span><span class="br0">&#40;</span>config.<span class="me1">Mode</span> <span class="sy0">==</span> CustomErrorsMode.<span class="me1">On</span> <span class="sy0">||</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#40;</span>config.<span class="me1">Mode</span> <span class="sy0">==</span> CustomErrorsMode.<span class="me1">RemoteOnly</span> <span class="sy0">&amp;&amp;</span> context.<span class="me1">Request</span>.<span class="me1">Url</span>.<span class="me1">Host</span> <span class="sy0">!=</span> <span class="st0">&quot;localhost&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// set the response status code &#8211; if we set it here we don&#39;t need</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// to also set it in the page itself</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context.<span class="me1">Response</span>.<span class="me1">StatusCode</span> <span class="sy0">=</span> <span class="nu0">404</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// redirect to the 404 error page from the web.config</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>config.<span class="me1">Errors</span><span class="br0">&#91;</span><span class="st0">&quot;404&quot;</span><span class="br0">&#93;</span> <span class="sy0">!=</span> <span class="kw1">null</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext.<span class="me1">Current</span>.<span class="me1">Server</span>.<span class="me1">Transfer</span><span class="br0">&#40;</span>config.<span class="me1">Errors</span><span class="br0">&#91;</span><span class="st0">&quot;404&quot;</span><span class="br0">&#93;</span>.<span class="me1">Redirect</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpContext.<span class="me1">Current</span>.<span class="me1">Server</span>.<span class="me1">Transfer</span><span class="br0">&#40;</span>config.<span class="me1">DefaultRedirect</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>After the module is created it just needs to be registered in the httpModules section of the web.config file:</p>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;httpmodules<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">name</span>=<span class="st0">&quot;ErrorModule&quot;</span> <span class="re0">type</span>=<span class="st0">&quot;ErrorModule, App_Code&quot;</span><span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/httpmodules<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/error-codes.zip">Complete example</a></p>
<h2>Creating a good 404 experience</h2>
<p>Noone likes 404 errors but they&#8217;re a part of being online. To finish up, here are some ideas about what you can do to make the 404 pages on your site as useful as possible to the people who end up seeing them:</p>
<ul>
<li><a href="http://www.alistapart.com/articles/perfect404/">Ideas on how to turn a 404 into a good experience</a> from <a href="http://www.alistapart.com">A List Apart</a></li>
<li><a href="http://www.google.com/support/webmasters/bin/answer.py?answer=93641&#038;hl=en">Google guidelines</a> on how to make your 404 pages useful to visitors, search engines and developers</li>
<li><a href="https://www.google.com/webmasters/tools/">Google webmaster tools</a> has a 404 page widget you can add to your site that suggests what the user might actually have been looking for.
</li>
</ul>
<img src="http://feeds.feedburner.com/~r/helephant/~4/50LuI_SI4jw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/11/improving-the-way-aspnet-handles-404-requests/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/02/11/improving-the-way-aspnet-handles-404-requests/</feedburner:origLink></item>
		<item>
		<title>Svelte asp.net: avoiding &lt;form runat="server"&gt;</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/c-ibeav7lVw/</link>
		<comments>http://helephant.com/2009/02/08/svelte-aspnet-avoiding-form-runat-server/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 15:00:08 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[controls]]></category>
		<category><![CDATA[markup]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[plainoldhtml]]></category>
		<category><![CDATA[postback]]></category>
		<category><![CDATA[viewstate]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1138</guid>
		<description><![CDATA[postbacks add a lot of weight to your page and you don't always need them. Find out when you can do without them and how to use ASP.NET without paying the postback price.]]></description>
			<content:encoded><![CDATA[<p>Postbacks in ASP.NET have a pretty heavy cost in terms of page size. Add a &lt;form runat=&#8221;server&#8221;> tag and now you have a big ugly viewstate tag to lug around each time you load a new page. Put in a control that triggers postback (like a linkbutton) and suddenly there&#8217;s a big chunk of script and hidden fields where your nice simple form tag used to be:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;Default.aspx&quot; id=&quot;form1&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__EVENTTARGET&quot; id=&quot;__EVENTTARGET&quot; value=&quot;&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__EVENTARGUMENT&quot; id=&quot;__EVENTARGUMENT&quot; value=&quot;&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;value=&quot;/wEPDwUKLTkzNjc3NzczOWRk3iDWotjQ89h26Tx79TM3SRLPJlg=&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;script type=&quot;text/javascript&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">//&lt; ![CDATA[</div>
</li>
<li class="li1">
<div class="de1">var theForm = document.forms[&#39;form1&#39;];</div>
</li>
<li class="li1">
<div class="de1">if (!theForm) {</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; theForm = document.form1;</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
<li class="li1">
<div class="de1">function __doPostBack(eventTarget, eventArgument) {</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; if (!theForm.onsubmit || (theForm.onsubmit() != false)) {</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; theForm.__EVENTTARGET.value = eventTarget;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; theForm.__EVENTARGUMENT.value = eventArgument;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; theForm.submit();</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; }</div>
</li>
<li class="li1">
<div class="de1">}</div>
</li>
<li class="li1">
<div class="de1">//]]&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/script&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input type=&quot;hidden&quot; name=&quot;__EVENTVALIDATION&quot; id=&quot;__EVENTVALIDATION&quot;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; value=&quot;/wEWAgLAqu2HBQKfwImNC6GfmgtYoNIWKohd9XTK5tBa39eY&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&#8230;</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<p>This is fine for a page that actually takes advantage of ASP.NET&#8217;s page lifecycle and controls, but can often be overkill for simple content driven applications that just need a little bit of server side logic. The good news is that in these cases you can have your serverside logic and eat it too just by using a simple html form tag with a regular GET request</p>
<h2>Before &#8211; markup only a mother could love</h2>
<p>The place I first thought of this was the search box on my old ASP.NET blog. Most of the pages on my blog were just straight content pages that didn&#8217;t need any of the postback logic. It seemed a real shame to add all this weight and complexity to the page just for a simple search form.</p>
<p>My search form was originally an ASP.NET form element with a button and textbox control that I could extract the search information from:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form id=&quot;form2&quot; runat=&quot;server&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;asp :TextBox id=&quot;KeywordsField&quot; runat=&quot;server&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;asp :Button ID=&quot;SearchButton&quot; Text=&quot;Search&quot; runat=&quot;server&quot;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; onclick=&quot;SearchButton_Click&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<p>The logic of redirecting to the search results page was a button click event with a Response.Redirect() call:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">void</span> SearchButton_Click<span class="br0">&#40;</span><span class="kw4">object</span> sender, EventArgs e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;Response.<span class="me1">Redirect</span><span class="br0">&#40;</span><span class="st0">&quot;search.aspx?keyword=&quot;</span> <span class="sy0">+</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;Server.<span class="me1">UrlEncode</span><span class="br0">&#40;</span>KeywordsField.<span class="me1">Text</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The form HTML generated by ASP.NET looked like this:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form name=&quot;form2&quot; method=&quot;post&quot; action=&quot;Before.aspx&quot; id=&quot;form2&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; value=&quot;/wEPDwULLTE0MDM4MzYxMjNkZB1GP1nffovgibqQWwhMKnQYMzMu&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&lt;div&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;input type=&quot;hidden&quot; name=&quot;__EVENTVALIDATION&quot; id=&quot;__EVENTVALIDATION&quot;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value=&quot;/wEWAwLtu4u/AQLfh7nDDALR1viaCYZVWJZuOfJe5p1cdkVMqJHz7Q3T&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/div&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;input name=&quot;KeywordsField&quot; type=&quot;text&quot; id=&quot;KeywordsField&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;&lt;input type=&quot;submit&quot; name=&quot;SearchButton&quot; value=&quot;Search&quot; id=&quot;SearchButton&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<h2>After &#8211; no server side code needed at all</h2>
<p>All the markup seemed like overkill to me so I switched the form with a regular HTML form element (minus the runat=&#8221;server&#8221; attribute). Then I replaced the textbox and button controls with their HTML equivalents:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;form action=&quot;Search.aspx&quot; method=&quot;get&quot;&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input name=&quot;keywords&quot; type=&quot;text&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &lt;input type=&quot;submit&quot; value=&quot;Search&quot; /&gt;</div>
</li>
<li class="li1">
<div class="de1">&lt;/form&gt;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/forms-without-postbacks.zip">Complete example</a></p>
<p>Now my search form doesn&#8217;t need code behind logic at all! The action=&#8221;search.aspx&#8221; attribute of the form tag tells the browser exactly where the information should be redirected to. The method=&#8221;get&#8221; part tells it to send it on the query string. The name of the form fields are used as the query string key. In my case the search page was expecting a query string parameter called keywords so the text field&#8217;s name also had to be set to &#8220;keywords&#8221;.</p>
<p>So when the search button was clicked, the browser would try to load the following url (exactly what my old redirect was loading):</p>
<p>http://mysite.com/search.aspx?keywords=hello+world</p>
<p>The html generated now is still the same svelte markup I started with:</p>
<pre>
&lt;form action="Search.aspx" method="get">
    &lt;input name="keywords" type="text" />
    &lt;input type="submit" value="Search" />
&lt;/form>
</pre>
<p><strong>Note</strong>: it&#8217;s important not to put a runat=&#8221;server&#8221; attribute on the form fields because ASP.NET will change the name of the fields to something that&#8217;s guaranteed to be unique on the page. This is fine when you are using the fields in a postback but may mean that the values passed to the next page won&#8217;t have the right names.</p>
<h2>For <a href="http://sqldev.wordpress.com/">Barry</a> :)</h2>
<p>Q: why not just use <a href="http://www.asp.net/mvc/">Microsoft&#8217;s MVC framework</a> so you never have to use postbacks?<br />
A: You don&#8217;t always get to choose what you&#8217;re going to develop in and there&#8217;s an awful lot of WebForms code out there already that sometimes you just have to work with. :)</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/c-ibeav7lVw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/08/svelte-aspnet-avoiding-form-runat-server/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/02/08/svelte-aspnet-avoiding-form-runat-server/</feedburner:origLink></item>
		<item>
		<title>Opening resx files in the xml editor</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/mS5Op1-Mg5k/</link>
		<comments>http://helephant.com/2009/02/04/opening-resx-files-in-the-xml-editor/#comments</comments>
		<pubDate>Wed, 04 Feb 2009 16:39:20 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[customization]]></category>
		<category><![CDATA[resx]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[visualstudio]]></category>
		<category><![CDATA[vs2008]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1172</guid>
		<description><![CDATA[Defaults can never please everyone. There&#8217;s always someone whose workflow is a little different. That one developer who likes to use SeaMonkey to test their pages or that weirdo who prefers to edit resx files as a text file. I am that weirdo who likes to edit resx files as text files and rather than [...]]]></description>
			<content:encoded><![CDATA[<p>Defaults can never please everyone. There&#8217;s always someone whose workflow is a little different. That one developer who likes to use <a href="http://www.seamonkey-project.org/">SeaMonkey</a> to test their pages or that weirdo who prefers to edit resx files as a text file.</p>
<p>I am that weirdo who likes to edit resx files as text files and rather than argue with me about the merits of their GUI tool, they have given me a very nice dialog where I can choose what editor I&#8217;d like any type of Visual Studio project file to open with by default.</p>
<p>If you are another person who shuns the built in editor and wonders where the &#8220;switch to xml button&#8221; went in VS2008, fear not because here are instructions on how to change the very nature of VS2008 and make it do your unnatural resx text editing bidding:</p>
<ol>
<li>Right flick on a resx file</li>
<li>Choose open with</li>
<li>Select <strong>Xml Editor</strong></li>
</ol>
<p><img src="/wp-content/uploads/2009/02/openwith.png" alt="the open with dialog"/></p>
<p>Also works on any other type of file in visual studio. It&#8217;s also very handy for opening .skin files with intellisense support. For any SeaMonkey developers, Check out right click->browse with to change what browser different file types will be browsed with.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/mS5Op1-Mg5k" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/04/opening-resx-files-in-the-xml-editor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/02/04/opening-resx-files-in-the-xml-editor/</feedburner:origLink></item>
		<item>
		<title>Snowy London Underground sign</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/Zn-PBTlKulw/</link>
		<comments>http://helephant.com/2009/02/02/snowy-london-underground/#comments</comments>
		<pubDate>Mon, 02 Feb 2009 14:49:04 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[My life as a coder]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1254</guid>
		<description><![CDATA[It&#8217;s a snowy day in London today. Apparently the most snow London&#8217;s seen in 20 years. It&#8217;s definitely the most snow I&#8217;ve ever seen. I was covered in snow and looking like a big white yeti by the time I got to the station this morning. I&#8217;ve been keeping an eye on the Transport for [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a snowy day in London today. Apparently the <a href="http://news.bbc.co.uk/1/hi/uk/7864395.stm">most snow London&#8217;s seen in 20 years</a>. It&#8217;s definitely the most snow I&#8217;ve ever seen. I was covered in snow and looking like a big white yeti by the time I got to the station this morning.</p>
<p>I&#8217;ve been keeping an eye on the <a href="http://www.tfl.gov.uk/">Transport for London</a> website all day (hoping Joe doesn&#8217;t get stuck in town) and loved the picture they had on the homepage:</p>
<p><img src="/wp-content/uploads/2009/02/snowy-tfl.png" alt="Snowy underground sign"/></p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/Zn-PBTlKulw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/02/snowy-london-underground/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/02/02/snowy-london-underground/</feedburner:origLink></item>
		<item>
		<title>Reducing viewstate on custom controls</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/kl9rK9VCNUc/</link>
		<comments>http://helephant.com/2009/02/01/reducing-viewstate-on-custom-controls/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 11:32:13 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Server controls]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[controls]]></category>
		<category><![CDATA[customccontrols]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[pagesize]]></category>
		<category><![CDATA[viewstate]]></category>

		<guid isPermaLink="false">http://helephant.com/?p=1118</guid>
		<description><![CDATA[One of the biggest waste I see in using viewstate is that it persists values that are already set in the aspx. These get set every time that the page runs and don&#8217;t need to be round tripped to the browser so that they will be persisted. I did a little experiment a while back [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest waste I see in using viewstate is that it persists values that are already set in the aspx. These get set every time that the page runs and don&#8217;t need to be round tripped to the browser so that they will be persisted.</p>
<p>I did a little experiment a while back where I tried <a href="/2008/08/saving-server-control-properties-to-viewstate-with-custom-attributes/">using custom attributes to save viewstate</a> on controls. I found that while it was very handy being able to save properties in  viewstate without having to write repetitive code, a much bigger advantage was I now had one place where I could optimize exactly what went into it.</p>
<p>The problem with persisting values in viewstate that are already saved in the aspx is pretty easy to solve. The code just needs to keep track of what the values of the properties were after the controls in aspx page are initialized:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">override</span> <span class="kw1">void</span> OnInit<span class="br0">&#40;</span><span class="kw5">System</span>.<span class="me1">EventArgs</span> e<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">base</span>.<span class="me1">OnInit</span><span class="br0">&#40;</span>e<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;List<span class="sy0">&lt;</span>propertyinfo<span class="sy0">&gt;</span> viewstateProperties <span class="sy0">=</span> GetViewStateProperties<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">foreach</span> <span class="br0">&#40;</span>PropertyInfo property <span class="kw1">in</span> viewstateProperties<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; _initialValues<span class="br0">&#91;</span>property.<span class="me1">Name</span><span class="br0">&#93;</span> <span class="sy0">=</span> property.<span class="me1">GetValue</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw1">null</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">private</span> List<span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;&lt;</span>propertyinfo<span class="sy0">&gt;</span> GetViewStateProperties<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;List<span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;&lt;</span>propertyinfo<span class="sy0">&gt;</span> properties <span class="sy0">=</span> <span class="kw3">new</span> List<span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;&lt;</span>propertyinfo<span class="sy0">&gt;</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">foreach</span> <span class="br0">&#40;</span>PropertyInfo property <span class="kw1">in</span> <span class="kw1">this</span>.<span class="me1">GetType</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">GetProperties</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">object</span><span class="br0">&#91;</span><span class="br0">&#93;</span> attributes <span class="sy0">=</span> property.<span class="me1">GetCustomAttributes</span><span class="br0">&#40;</span><span class="kw3">typeof</span><span class="br0">&#40;</span>PersistToViewState<span class="br0">&#41;</span>, <span class="kw1">true</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>attributes.<span class="me1">Length</span> <span class="sy0">&gt;</span> <span class="nu0">0</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;properties.<span class="me1">Add</span><span class="br0">&#40;</span>property<span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">return</span> properties;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>propertyinfo<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Then when it&#8217;s time to save the viewstate, check whether the value has actually changed:</p>
<div class="geshi no csharp">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">protected</span> <span class="kw1">override</span> <span class="kw4">object</span> SaveViewState<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="co1">// Save automatic viewstate properties</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;List<span class="sy0">&lt;</span>propertyinfo<span class="sy0">&gt;</span> viewstateProperties <span class="sy0">=</span> GetViewStateProperties<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw4">int</span> x <span class="sy0">=</span> <span class="nu0">0</span>; x <span class="sy0">&lt;</span> viewstateProperties.<span class="me1">Count</span>; x<span class="sy0">++</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; PropertyInfo property <span class="sy0">=</span> viewstateProperties<span class="br0">&#91;</span>x<span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw4">object</span> value <span class="sy0">=</span> property.<span class="me1">GetValue</span><span class="br0">&#40;</span><span class="kw1">this</span>, <span class="kw3">new</span> <span class="kw4">object</span><span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="br0">&#123;</span> <span class="br0">&#125;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>_initialValues.<span class="me1">ContainsKey</span><span class="br0">&#40;</span>property.<span class="me1">Name</span><span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// Only save the property to viewstate if it has changed since viewstate</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// was loaded. If it hasn&#39;t been changed, we don&#39;t need to store it because</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="co1">// it will be loaded from the aspx on the next page load</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw4">object</span> initialValue <span class="sy0">=</span> _initialValues<span class="br0">&#91;</span>property.<span class="me1">Name</span><span class="br0">&#93;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="kw4">object</span>.<span class="me1">Equals</span><span class="br0">&#40;</span>initialValue, value<span class="br0">&#41;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; ViewState<span class="br0">&#91;</span>x.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;ViewState<span class="br0">&#91;</span>x.<span class="me1">ToString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#93;</span> <span class="sy0">=</span> value;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="kw1">return</span> <span class="kw1">base</span>.<span class="me1">SaveViewState</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/02/reduce-viewstate.zip">Complete example</a></p>
<p>It makes a big difference to how much viewstate is saved. Here&#8217;s the viewstate of a single example Pie control before this simple bit of optimization:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;</div>
</li>
<li class="li1">
<div class="de1">value=&quot;/wEPDwUJMzUzODE3ODMxD2QWAgIDD2QWAgIBDxYEHgEwBQlhcHBsZSBwaWUe</div>
</li>
<li class="li1">
<div class="de1">ATECA2Rk/V7Nc8+xuVAMsS4R9hLs1SHD4Js=&quot; /&gt;</div>
</li>
</ol>
</div>
<p>Here&#8217;s the viewstate after:</p>
<div class="geshi no html">
<ol>
<li class="li1">
<div class="de1">&lt;input type=&quot;hidden&quot; name=&quot;__VIEWSTATE&quot; id=&quot;__VIEWSTATE&quot;</div>
</li>
<li class="li1">
<div class="de1">value=&quot;/wEPDwUJMzUzODE3ODMxZGTnlfN1SaJSDVcRTDQPIBVe1fK+Gw==&quot; /&gt;</div>
</li>
</ol>
</div>
<p>Everything else still works as expected. Controls created entirely in code will still work perfectly well, the only difference will be that all properties that are set will need to be persisted so you won&#8217;t see any reduction in the amount of viewstate used there. The properties set in code of controls created in the aspx will also be saved to viewstate so they will be persisted after the next postback. </propertyinfo></pre>
<img src="http://feeds.feedburner.com/~r/helephant/~4/kl9rK9VCNUc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/02/01/reducing-viewstate-on-custom-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/02/01/reducing-viewstate-on-custom-controls/</feedburner:origLink></item>
		<item>
		<title>Goodbye 2008. Hello 2009</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/4EJw-_bRJSA/</link>
		<comments>http://helephant.com/2009/01/18/goodbye-2008-and-hello-2009/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 16:48:51 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[My life as a coder]]></category>
		<category><![CDATA[2008]]></category>
		<category><![CDATA[2009]]></category>
		<category><![CDATA[goals]]></category>
		<category><![CDATA[newyears]]></category>
		<category><![CDATA[newyearsresolution]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=1017</guid>
		<description><![CDATA[Wow, it&#8217;s January 18th already. I feel like I&#8217;ve really hit the ground running. Everyone else who did their new years post did them two weeks ago but I really wanted to write down what I&#8217;d achieved in 2008 and what I wanted to achieve in 2009 to give myself something to look at in [...]]]></description>
			<content:encoded><![CDATA[<p>Wow, it&#8217;s January 18th already. I feel like I&#8217;ve really hit the ground running. Everyone else who did their new years post did them two weeks ago but I really wanted to write down what I&#8217;d achieved in 2008 and what I wanted to achieve in 2009 to give myself something to look at in a year.</p>
<h2>What I did in 2008</h2>
<p>Participated in the UK ASP.NET community &#8211; I talked at <a href="http://idunno.org">Barry&#8217;s</a> <a href="http://www.nxtgenug.net/Profile.aspx?UserID=e8b4e892-68a6-4445-b4e3-e01f201f357f">user group</a>, <a href="http://www.vbug.co.uk/">VBUG</a> and <a href="http://www.developerday.co.uk/ddd/agendaddd7lineup.asp">DDD7</a>. It was exhausting but great fun. The feedback I got from DDD7 was particularly useful and I think at some point I&#8217;ll be able to get hold of a video to see how my talk actually goes from the audience&#8217;s perspective.</p>
<p>Learnt heaps about <a href="/2008/08/building-objects-with-javascript/">javascript objects</a> &#8211; I&#8217;m embarrassed to admit that I didn&#8217;t even know what <a href="/2008/10/javascript-closures/">closures</a> were at the beginning of 2008. I think learning more about javascript has made me a better programmer in general. It&#8217;s really made this C# dev very keen to have a go at a more dynamic language like ruby or python.</p>
<p>Move my site to <a href="http://www.wordpress.org">wordpress</a> &#8211; I had great fun writing my own blog script. It&#8217;s practically a web developer rite of passage. After seeing all the cool stuff other people were able to do on their blogs, <a href="http://updatepanel.net/">Ting</a> convinced me it was time to retire the old ASP.NET script and use my tiny bit of home dev time to work on something more important.</p>
<p>Started a new job &#8211; been working at my current job for almost a year now. I&#8217;m still working as an ASP.NET developer (which I pretty much love). I got lucky *again* to find a friendly place with dedicated and interesting people. Got to learn about LINQ, JQuery, some neat clientside bugs and how to fit German words into layouts.</p>
<p><a href="http://www.flickr.com/photos/helephant/sets/72157607462892965/">Went to Tokyo</a> &#8211; the land of robots, <a href="http://www.flickr.com/photos/helephant/2884376396/in/set-72157607462892965/">hello kitty</a> and amazing tasting chicken. <a href="http://www.flickr.com/photos/nekojoe/2883973279/in/set-72157607478297478/">Akihabara</a> is where good geeks go when they die.</p>
<p>Lost 50 pounds &#8211; I am still a little surprised I actually managed to do this. I followed <a href="http://www.weightwatchers.co.uk/">weight watchers</a> all year and found it really helpful. There were times when it was hard and I didn&#8217;t make much progress in the last three months of the year but I&#8217;m pretty proud I&#8217;ve managed to do so well. Slightly embarrassed my weight got to the point where I needed to lose 50 pounds, but pretty relieved I was able to do it.</p>
<p><a href="/2008/11/big-non-technical-helen-news/">Got engaged</a> to <a href="http://www.otakunews.com">Joe</a> &#8211; can&#8217;t really take credit for that. It was his idea. :D</p>
<h2>Goals for 2009</h2>
<p>Seems like I always want to do way more than I have time for so I&#8217;ve decided just to pick a couple of extra-circular things to concentrate on in 2009. To be honest, I&#8217;ll be happy to complete any of these things.</p>
<p>Write some more interesting clientside samples &#8211; every year for the last 11 years I&#8217;ve been lucky enough to expand my clientside web development skills without really trying to. This year I want to consciously push the boundaries of the web app a little bit. I have a few things in mind. :)</p>
<p>Launch a new site &#8211; I&#8217;ve got a few ideas about what I&#8217;d like to do this year. I don&#8217;t want to actually announce anything yet but I started something last year that I hope will be ready for version 1.0 in a month or two.</p>
<p>Post at least twice a month &#8211; Attwood says <a href="http://www.codinghorror.com/blog/archives/000983.html">pick a schedule and stick to it</a>. I know it&#8217;s not going to always be possible but I&#8217;m going to try for twice a month. Then my plan is to use my wee bit of spare time to do something else for the rest of the month.</p>
<p>Organise our wedding &#8211; oh my goodness that&#8217;s turning out to be a lot of work already. I&#8217;ve spent every lunch time since I got back to work on the 5th sorting something out and I don&#8217;t seem to be able to have a conversation with my mum or his that doesn&#8217;t involve wedding favours, invitation lists or dresses. It&#8217;s really good fun though and I think we&#8217;re going to have a great day. :)</p>
<p>Finish the last bit of weight loss &#8211; I&#8217;m still not down to my ideal weight. My BMI is still at the top end of the healthy range. I&#8217;d like to get it to a little below the middle (really, I just want to lose the flab around my tummy). I&#8217;m not far away now. I think it should take about three months to lose the last little bit. Then I&#8217;ve just got to get used to the idea of healthy living for the rest of my life. :)</p>
<h2>Things I&#8217;d like to do but won&#8217;t have time for</h2>
<p>Get involved in an open source project &#8211; preferably something to do with javascript. The more web development I do the more I&#8217;m discovering how much I like front end development.</p>
<p>Learn hiragana &#8211; managed to learn all the characters by studying a book on the train. Would like to be able to read a little (and understand the japanese language a little) when Joe and I go on our honeymoon.</p>
<p>Read some more &#8211; read all of Jane Austen&#8217;s book in 2007. Read a heap of great sci-fi (and all of Harry Potter) in 2008. Hope I get some time to do some great fiction reading in 2009 as well. Commuting to work isn&#8217;t all bad. :)</p>
<p>World domination through army of killer robots &#8211; you lot are just lucky I&#8217;m too busy for this. :)</p>
<p>Get to the end of the year without being exhausted. :)</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/4EJw-_bRJSA" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/01/18/goodbye-2008-and-hello-2009/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/01/18/goodbye-2008-and-hello-2009/</feedburner:origLink></item>
		<item>
		<title>Javascript object prototype</title>
		<link>http://feedproxy.google.com/~r/helephant/~3/rfDUevQqAOU/</link>
		<comments>http://helephant.com/2009/01/18/javascript-object-prototype/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 16:08:11 +0000</pubDate>
		<dc:creator>Helen Emerson</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[inheritance]]></category>
		<category><![CDATA[javascriptobjects]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://helephant.net/?p=410</guid>
		<description><![CDATA[The javascript object prototype is javascript&#8217;s way of sharing implementation across similar objects, much like the way classes are used to do this in many other languages. Although constructor functions look a lot like classes, javascript does not have a class based object system like C# or Java. Instead it has a prototype based object [...]]]></description>
			<content:encoded><![CDATA[<p>The javascript object prototype is javascript&#8217;s way of sharing implementation across similar objects, much like the way classes are used to do this in many other languages. Although <a href="/2008/09/constructor-functions/">constructor functions</a> look a lot like classes, <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Class-Based_vs._Prototype-Based_Languages">javascript does not have a class based object</a> system like C# or Java. Instead it has a <a href="http://en.wikipedia.org/wiki/Prototype-based_programming">prototype based</a> object system.</p>
<p>The main difference between the two types of languages is all about objects and classes. In a class based language there is a clear distinction between the ideas of a class and an object. A class is a template for creating an object and an object is a specific instance of a class. In C# you cannot create an object without instantiating it from a class. Even the most basic object of type Object is instantiated from a class. Once the object is created you cannot make it into a different type of object by adding different properties.</p>
<p>In a prototype based systems there are no classes. All objects are created by adding properties and methods to an empty object or by cloning an existing one. Although a constructor function may look like a class (probably so people from more traditional class based languages would be able to use it), it’s really just a function that knows how to add the right properties and methods to create a particular type of object.</p>
<p>This approach is called prototype-based inheritance because an existing object is used as a template (or a <a href="http://www.askoxford.com/concise_oed/prototype?view=uk">prototype &#8211; a typical example</a>) to build other objects. The existing object will be used as a starting point to build the new object but the new object does not have to be exactly the same.</p>
<h2>How it works in javascript</h2>
<p>Prototypes are implemented in javascript using the <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Function/prototype">prototype property</a> of constructor functions. Any property or method that&#8217;s added to the constructor&#8217;s prototype automatically becomes part of every object created by that function.</p>
<p>The prototype property is basically a template for the objects created by the constructor. It contains the things that should be the same among all objects created by the constructor. Individual objects can override and change the things they inherit from the constructor&#8217;s prototype but they will all start out the same.</p>
<p>The aim of the prototype is to share implementation between similar objects, to make things more convenient for programmers. It is not designed to be a type system. Javascript objects are dynamic so they can be changed after they are created. Knowing that an object was created by a particular constructor function does not guarantee anything about the methods or properties that an object will have.</p>
<h3>A simple example</h3>
<p>The easiest way to understand this is to look at an example, so let&#8217;s take a look at the <a href="/2008/09/constructor-functions/">Pet example</a> again.</p>
<p>All the pets created by the pet constructor function have a sayHello() method. When we created our pet using the constructor function, we created a separate sayHello() function for each pet by creating the function and adding it to the new object we were creating:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Wouldn&#8217;t it be better if there would be  just one sayHello() function that all the pet objects will automatically share? To do this we could remove the sayHello() method from the constructor function and add it to the function&#8217;s prototype property instead:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Pet<span class="br0">&#40;</span><span class="kw3">name</span>, species, hello<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="kw3">name</span> = <span class="kw3">name</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">species</span> = species;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">hello</span> = hello;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span>.<span class="me1">sayHello</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> rufus = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="st0">&quot;Rufus&quot;</span>, <span class="st0">&quot;cat&quot;</span>, <span class="st0">&quot;miaow&quot;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">rufus.<span class="me1">sayHello</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/01/prototype-simple.html">Complete example</a></p>
<p>When we created the Pet function, its prototype property was automatically set to an empty object. Every function is set up this way when it&#8217;s created because there&#8217;s no way for javascript to know whether any particular function will be used as a constructor function or not.</p>
<p>We wanted all our pets to have a sayHello method, so we added a sayHello() method to the Pet&#8217;s prototype property. The prototype property contains a <a href="/2008/08/building-simple-objects/">regular javascript object</a> so this is just the same as assigning a new method or property to any other object. In this case we have created a new <a href="/2008/08/javascript-anonymous-functions/">anonymous function</a> and assigned it to a property called sayHello.</p>
<p>When we created the rufus object, it automatically maintained an invisible link back to the Pet function that created it. Then when we tried to access the sayHello() method, javascript first looked for a sayHello() method set directly on the rufus object. When it couldn&#8217;t find one, it then looked at the Pet constructor&#8217;s prototype, found sayHello() and called that instead.</p>
<p>Because the property resolution happens when the property is called, any changes made to the prototype property will be reflected in all of the objects already created by the constructor. Properties can be dynamically added or removed or the prototype could even be replaced with an entirely new object.</p>
<p>This all happens transparently. The code that is using the rufus object doesn&#8217;t need to care whether rufus&#8217; sayHello() method was set directly on rufus or if it belongs to the Pet constructor.</p>
<h2>The prototype property is just an object</h2>
<p>The prototype property is just an object. There&#8217;s nothing particularly special or magic about it. Anything you can do to a normal object you can also do to a function&#8217;s prototype property. This includes adding and removing properties, accessing the properties through substring (Pet.prototype["property"]) or dot (Pet.prototype.property) notation and iterating through the properties using a for loop.</p>
<p>When a new function is created the prototype property is set to an empty object, exactly the same if we said Pet.prototype = new Object() when we created the function. Javascript does this by default whenever you create a new function to make sure that any objects created by calling the function will automatically get all of the methods and properties that are belong to every <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Object</a> (like toString()).</p>
<p>In the previous example we just added another property to object that was automatically created. Instead we could have overriden the default empty object with a new one instead:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">Pet.<span class="me1">prototype</span> = <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sayHello : <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw3">alert</span><span class="br0">&#40;</span><span class="kw1">this</span>.<span class="me1">hello</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span>;</div>
</li>
</ol>
</div>
<p>You can even set the prototype to an be a new object created by another constructor. This is called <a href="/2009/08/javascript-prototype-chaining/">prototype chaining</a> and is the way related javascript objects can share implementation much like inheritance in a class based language:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">function</span> Cat<span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &#8230;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">Cat.<span class="me1">prototype</span> = <span class="kw2">new</span> Pet<span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<h2>Every constructor has a prototype property</h2>
<p>Even built in constructors like String or Array. Libraries like <a href="http://www.prototypejs.org/">prototype</a> and <a href="http://ajax.asp.net">ASP.NET ajax</a> use this to add functions to the built in types like <a href="http://www.prototypejs.org/api/array/reverse">Array.reverse()</a> or <a href="http://www.asp.net/AJAX/Documentation/Live/ClientReference/Global/JavascriptTypeExtensions/StringTypeExt/StringTrimFunc.aspx">String.trim()</a>.</p>
<p>Here&#8217;s a simple example that adds a sheep function to all javascript string objects:</p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">String.<span class="me1">prototype</span>.<span class="me1">sheep</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;baaah &quot;</span> + <span class="kw1">this</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">var</span> hello = <span class="st0">&quot;hello world&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alert</span><span class="br0">&#40;</span>hello.<span class="me1">sheep</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;</div>
</li>
</ol>
</div>
<p><a href="/wp-content/uploads/2009/01/prototype-extending-built-in-constructors.html">Complete example</a>.</p>
<h2>Why is this important?</h2>
<p>The practical reason why this is important is sharing single a method between all objects uses less memory than having a separate copy for each object. This can be a big advantage when working on a complicated web application with lots of objects.</p>
<p>The javascript object prototype also enables you use some interesting coding patterns like inheritance and object cloning to more easily share implementation between similar objects in a similar way to how you would use classes to do this in a class based language.</p>
<h2>What&#8217;s next?</h2>
<p><a href="/2009/08/javascript-prototype-chaining/">Prototype chaining</a> is used to build new types of objects based on existing ones. It has a very similar job to inheritance in a class based language.</p>
<p>This article is part of a set of related posts about <a href="/2008/08/how-javascript-objects-work/">How javascript objects work</a>.</p>
<img src="http://feeds.feedburner.com/~r/helephant/~4/rfDUevQqAOU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://helephant.com/2009/01/18/javascript-object-prototype/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		<feedburner:origLink>http://helephant.com/2009/01/18/javascript-object-prototype/</feedburner:origLink></item>
	</channel>
</rss>

