<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Uncle Billy</title>
	<atom:link href="http://billyreisinger.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://billyreisinger.com/blog</link>
	<description>poops on his keyboard</description>
	<lastBuildDate>Wed, 28 Jan 2009 04:16:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Real-world example of why global variables are bad</title>
		<link>http://billyreisinger.com/blog/2009/01/real-world-example-of-why-global-variables-are-bad/</link>
		<comments>http://billyreisinger.com/blog/2009/01/real-world-example-of-why-global-variables-are-bad/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 04:15:08 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=23</guid>
		<description><![CDATA[<p>We all know that global variables are bad.  Sooner or later, someone is going to pick the same name for a variable as you do, and when that happens, *poof!* your code doesn't work anymore. </p>]]></description>
			<content:encoded><![CDATA[<p>We all know that global variables are bad.  Sooner or later, someone is going to pick the same name for a variable as you do, and when that happens, *poof!* your code doesn&#8217;t work anymore. </p>
<p>Unfortunately, not every programmer understands why globals are bad. This is a write-up of a rather spectacular bug that I was asked to look into during my glory days at <a href="http://www.ibsys.com">InternetBroadcasting</a>.  It involved tracking down a conflict between an advertisement on the same page as a Microsoft VirtualEarth map control.  Needless to say, when we contacted Microsoft to make them aware of the problem, they were less than responsive&#8230; it was easier to talk to the small ad serving company to get them to fix their part, and that was ultimately the route that the project manager decided to take to fix the problem.</p>
<h2>What the problem was</h2>
<p>	A bug was reported wherein a Microsoft VirtualEarth map would not display on certain web pages that contained a certain advertisement.</p>
<h2>How it happened</h2>
<p>	In summary, the problem occurred because two third-party JavaScript files were included on the same web page, and both scripts contained code which did not follow the extremely important best practice of <b>limiting the use of global variables</b>.</p>
<p>	JavaScript code included from Microsoft&#8217;s VirtualEarth library defined a global variable named &#8220;g.&#8221; JavaScript code from ContextWeb sourced in for an advertisement also defined a global variable named &#8220;g.&#8221;	</p>
<p><b>There can only be one global variable named &#8220;g&#8221; on any given web page.</b> In JavaScript, the last value assigned to a variable is always the current value. Here is the order of events as they happened on the websites that experienced this problem: </p>
<ol>
<li>A script tag loads Microsoft&#8217;s VirtualEarth library, wherein a global &#8220;g&#8221; is defined.
<pre>
/* This runs in the global space, i.e. outside of any function or object */
function g(a){
        return new Gimme.object(Gimme.query(a))
}
</pre>
<p><i>(as found in http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.2)</i></li>
<li>A script tag loads in ContextWeb ad code, wherein the global &#8220;g&#8221; is overwritten to a new value.
<pre>
/* This runs in the global space, i.e. outside of any function or object */
var g=''; /* Here is the initial overwrite... many follow below... */
var k='';
var j='';
var tw=w;
try {
	k=d.location;
	if(k==top.location){
		g=k;
	} else {
		while(true){
			g=tw.document.location;
			.............
</pre>
<p><i>(as found in http://tag.contextweb.com/TagPublish/getjs.aspx?action=VIEWAD&amp;cwrun=200&amp;cwadformat=728X90&amp;cwpid=501657&amp;cwwidth=728&amp;cwheight=90&amp;cwpnet=1&amp;cwtagid=25722)</i>
</li>
<li>A script initializes the VirtualEarth map, which attemps to use the variable &#8220;g.&#8221;  Having been redefined, the variable does not contain what VE code expects it to, and the map cannot be created.</li>
</ol>
<h2>Why it happened</h2>
<p>A typical problem when integrating two third-party JavaScripts into the context of a web page is a global variable conflict. A global variable is one that is available to all scripts running in a particular context.  In a web browser, all global variables are members of the object called &#8220;window,&#8221; and can be referenced simply by typing the name of the variable.  Because JavaScript allows one to rewrite or delete variables created in this space, one can define and rely on a global variable and have that variable overwritten by another script which naively uses the same variable name.
		</p>
<p>Many of today&#8217;s most respected JavaScript developers recommend against the usage of global variables (for example, see <a href="http://yuiblog.com/blog/2006/06/01/global-domination/">Douglas Crockford&#8217;s take on the subject</a>). Unfortunately, the usage of globals is rampant.  The reasons for this are many, including that: </p>
<ul>
<li><b>global variables are convenient</b>
<p>
						It is extremely easy to use a global variable, and many online tutorials unfortunately contain examples wherein globals are used. Many first-time programmers are taught to use a procedural programming style with JavaScript and to write just enough code to get the job done (without namespaceing or context-checking).</p>
</li>
<li><b>JavaScript programmers are relatively inexperienced</b>
<p>
						JavaScript has only recently emerged as a programming language for web applications; in the past, it has been used for very simple tasks on web pages.  Now that it is being used to write full-blown applications, problems such as global variable conflicts become extremely serious.  Lacking understanding of best practices, even programmers who are fluent in other languages can make terrible mistakes in JavaScript.
					</p>
</li>
<li><b>the language has some confusing syntax that promotes the use of global variables</b>
<ul>
<li>
						In the global space (i.e., outside of any function or object) any variable defined with the <b>var</b> or <b>function</b> keyword is global.  This is what happened in the case of VirtualEarth and ContextWeb. For example:</p>
<pre>
function f() { ... }
var t = 4;
alert(typeof window.f); /* "function" */
alert(typeof window.t); /* "number" */
</pre>
</li>
<li>
						Inside a function, the declaration of a variable without the keyword <b>var</b> makes the variable global. Programmers new to JavaScript often are not aware of this. For example: </p>
<pre>

function myFunc() {
	/* LOCAL VARIABLES */
	var myVariable = 3;
	var myFunction = function() { return 3; }

	/* WHOOPS - GLOBAL VARIABLES */
	myOtherVariable = 4;
	myOtherFunction = function() { return 4; }
}
myFunc();

alert(myVariable); /* undefined */
alert(myOtherVariable); /* 4 */
alert(window.myOtherVariable); /* 4 */

alert(myFunction()); /* error, myFunction is not defined */
alert(myOtherFunction()); /* 4 */
</pre>
</li>
</ul>
</li>
</ul>
<h2>How it could have been avoided</h2>
<ul>
<li><b>Namespacing</b>
<p> In JavaScript, the practice of namespacing is simply creating one global variable that is unlikely to create a name conflict (such as the organization name of a company in capital letters). All variables are then stored within that object, and can only be accessed through the object. For example:</p>
<pre>
var IBSYS = {};
IBSYS.foo = 3;
alert(foo); /* undefined */
alert(window.foo); /* undefined */
alert(IBSYS.foo); /* 3 */
</pre>
</p>
</li>
<li><b>Scoping</b>
<p>
					Javascript allows the creation and immediate execution of unnamed (i.e., anonymous) functions.  Functions have their own local scope, and thus any local variables defined in an anonymous function will not conflict with any globals or code in any other scope. For example:</p>
<pre>
(function() {
	var t = 3;
	alert(t); /* 3 */
})();
alert(t); /* undefined */
</pre>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2009/01/real-world-example-of-why-global-variables-are-bad/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Kentucky Derby Pie</title>
		<link>http://billyreisinger.com/blog/2008/12/kentucky-derby-pie/</link>
		<comments>http://billyreisinger.com/blog/2008/12/kentucky-derby-pie/#comments</comments>
		<pubDate>Wed, 24 Dec 2008 03:18:37 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[food holiday]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/2008/12/kentucky-derby-pie/</guid>
		<description><![CDATA[I love this pie!  It is a family favorite, which we always make on Thanksgiving and Christmas.  I&#8217;m immortalizing the recipe here for my own sake; I keep losing the one my mom gave me.  I&#8217;m quoting this directly from: http://www.nickers.com/kentucky-derby-pie-recipe.htm
1 Pie crust
Filling:
1/2 cup butter, melted and cooled
2 eggs
1 cup sugar
1/2 cup all-purpose flour
1 cup [...]]]></description>
			<content:encoded><![CDATA[<p>I love this pie!  It is a family favorite, which we always make on Thanksgiving and Christmas.  I&#8217;m immortalizing the recipe here for my own sake; I keep losing the one my mom gave me.  I&#8217;m quoting this directly from: <a href="http://www.nickers.com/kentucky-derby-pie-recipe.htm">http://www.nickers.com/kentucky-derby-pie-recipe.htm</a></p>
<p>1 Pie crust</p>
<p>Filling:</p>
<p>1/2 cup butter, melted and cooled</p>
<p>2 eggs</p>
<p>1 cup sugar</p>
<p>1/2 cup all-purpose flour</p>
<p>1 cup semi-sweet chocolate chips</p>
<p>1 1/2 cups chopped pecans</p>
<p>2 tablespoons Kentucky Bourbon</p>
<p>Beat eggs with cooled butter. Add flour &amp; sugar. Beat until mixed well. Stir in pecans, chocolate &amp; bourbon. Pour mixture into pie shell. Bake at 350° for about 30 minutes, or until set.</p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/12/kentucky-derby-pie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PNG background-image support in IE6 &#8211; better late than never</title>
		<link>http://billyreisinger.com/blog/2008/12/png-background-image-support-in-ie6-better-late-than-never/</link>
		<comments>http://billyreisinger.com/blog/2008/12/png-background-image-support-in-ie6-better-late-than-never/#comments</comments>
		<pubDate>Mon, 08 Dec 2008 16:53:00 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[png]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=16</guid>
		<description><![CDATA[My buddy Drew Diller (who is a freaking CSS genius) has come up with a clever solution to get CSS backgroun d-image support working in IE &#8211; including background positioning and repeating.  If you are tired of using AlphaImageLoader and want something easier, check this out:
http://www.dillerdesign.com/experiment/DD_belatedPNG/
It lets you use a PNG image as a CSS [...]]]></description>
			<content:encoded><![CDATA[<p>My buddy Drew Diller (who is a freaking CSS genius) has come up with a clever solution to get CSS backgroun d-image support working in IE &#8211; including background positioning and repeating.  If you are tired of using AlphaImageLoader and want something easier, check this out:</p>
<p><a title="DD_belatedPNG" href="http://www.dillerdesign.com/experiment/DD_belatedPNG/">http://www.dillerdesign.com/experiment/DD_belatedPNG/</a></p>
<p>It lets you use a PNG image as a CSS background-image property in IE6 without much fuss at all!</p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/12/png-background-image-support-in-ie6-better-late-than-never/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Enterprise JavaScript build system &#8211; Sysbliss</title>
		<link>http://billyreisinger.com/blog/2008/12/enterprise-javascript-build-system-sysbliss/</link>
		<comments>http://billyreisinger.com/blog/2008/12/enterprise-javascript-build-system-sysbliss/#comments</comments>
		<pubDate>Wed, 03 Dec 2008 03:59:18 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[enterprisey]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=15</guid>
		<description><![CDATA[I&#8217;ll soon be working on a screencast for the JavaScript build module that Jonathan Doklovic wrote for his enterprise build system (which leverages Jira, Bamboo, Ivy, and Ant).  The JavaScript module takes advantage of JsUnit for unit testing, YUICompressor for compression and lint checking, and JsDoc Toolkit for source documentation.
I&#8217;ve also contributed a Flex build [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll soon be working on a screencast for the JavaScript build module that <a title="Sysbliss" href="http://blog.sysbliss.com/">Jonathan Doklovic</a> wrote for his enterprise build system (which leverages Jira, Bamboo, Ivy, and Ant).  The JavaScript module takes advantage of JsUnit for unit testing, YUICompressor for compression and lint checking, and JsDoc Toolkit for source documentation.</p>
<p>I&#8217;ve also contributed a Flex build module to this system, and hopefully it will be put through the paces soon so that any major deficiencies can be exposed and worked out.</p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/12/enterprise-javascript-build-system-sysbliss/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSUnit XML to JUnit XML</title>
		<link>http://billyreisinger.com/blog/2008/07/jsunit-xml-to-junit-xml/</link>
		<comments>http://billyreisinger.com/blog/2008/07/jsunit-xml-to-junit-xml/#comments</comments>
		<pubDate>Tue, 08 Jul 2008 03:31:34 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[bamboo]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jsunit]]></category>
		<category><![CDATA[xsl]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=11</guid>
		<description><![CDATA[We&#8217;re using JSUnit to run tests in our build system, and we&#8217;re using Bamboo to do continuous integration.  Unfortunately, the XML spit out by JSUnit is not recognizable as JUnit XML for the purposes of integrating into Bamboo. I wrote this XSL stylesheet to transform the JSUnit XML report into a JUnit XML report that [...]]]></description>
			<content:encoded><![CDATA[<p>We&#8217;re using JSUnit to run tests in our build system, and we&#8217;re using Bamboo to do continuous integration.  Unfortunately, the XML spit out by JSUnit is not recognizable as JUnit XML for the purposes of integrating into Bamboo. I wrote this XSL stylesheet to transform the JSUnit XML report into a JUnit XML report that Bamboo can parse.  It&#8217;s simple and inefficient, but hey, if you are looking at this, you probably just want to get the job done (like I did). </p>
<p>View <a href='http://billyreisinger.com/blog/wp-content/uploads/2008/07/jsunit_to_junit.xsl'>jsunit_to_junit.xsl</a></p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/07/jsunit-xml-to-junit-xml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Type enforcement and argument validation in JavaScript saves time</title>
		<link>http://billyreisinger.com/blog/2008/05/type-enforcement-and-argument-validation-in-javascript-saves-time/</link>
		<comments>http://billyreisinger.com/blog/2008/05/type-enforcement-and-argument-validation-in-javascript-saves-time/#comments</comments>
		<pubDate>Wed, 21 May 2008 03:09:54 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=10</guid>
		<description><![CDATA[Debugging JavaScript is hard enough &#8211; but it is especially annoying when you have spent a good amount of time tracking down a bug and it turns out to be a type error (i.e., your function expected a Boolean true but got a String &#8220;true&#8221;).  Perhaps your value was implicitly cast to another type [...]]]></description>
			<content:encoded><![CDATA[<p>Debugging JavaScript is hard enough &#8211; but it is especially annoying when you have spent a good amount of time tracking down a bug and it turns out to be a type error (i.e., your function expected a Boolean true but got a String &#8220;true&#8221;).  Perhaps your value was implicitly cast to another type by some operation, or maybe you forgot to pass the right arguments to a method.  In a statically-typed, compiled language (such as AS3 or Java), you would find out about bad arguments during compile time &#8211; and you&#8217;d probably get a nice, descriptive error message of what was going on.  Not so with JavaScript &#8211; in fact, because it is loosely and dynamically typed, you may not find out about your bad argument until you waste an hour or two tracking down a bug. </p>
<p>To avoid this sort of thing, you can throw your own errors when a method or constructor doesn&#8217;t get what it expects. The pattern is easy to get the hang of.  The very first time you get one of these errors, you will feel good about all this extra typing.    </p>
<pre>
/**
* A function that creates a new barf bag.
* @param {Boolean} zip          Whether this bag has a zipper or not.
* @param {String} bagType     Valid types: "paper"|"plastic"
* @param {String} vomitType  Valid types: "chunky"|"bile"|"watery"
*/
var VomitBag = function(zip, bagType, vomitType) {
   /* validate arguments */
   if(typeof zip != "boolean") throw new Error("VomitBag: expected zip to be Boolean");
   if(typeof bagType != "string" || !(/^paper$|^plastic$/.test(bagType)) throw new Error("VomitBag: expected bagType to be String and to be either 'paper' or 'plastic'");
   if(typeof vomitType != "string" || !(/^chunky$|^bile$|^watery$/.test(vomitType)) throw new Error("VomitBag: expected vomitType to be String and to be 'chunky', 'bile', or 'watery'");

   /* some code... */
}
</pre>
<p>This technique is not at all new to JavaScript.  For example, Marijn Haverbeke talks about it briefly during a good writeup about error handling in Eloquent JavaScript: <a href="http://eloquentjavascript.net/chapter5.html">Error Handling &#8211; Eloquent JavaScript</a>  (that whole site is worth reading).</p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/05/type-enforcement-and-argument-validation-in-javascript-saves-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Disabled form element and dispatchEvent bug in Opera</title>
		<link>http://billyreisinger.com/blog/2008/05/disabled-form-element-and-dispatchevent-bug-in-opera/</link>
		<comments>http://billyreisinger.com/blog/2008/05/disabled-form-element-and-dispatchevent-bug-in-opera/#comments</comments>
		<pubDate>Mon, 19 May 2008 18:41:18 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[dom2]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[opera]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=8</guid>
		<description><![CDATA[I&#8217;ve stumbled across a bug in Opera 9.27 (which I dutifully reported).  Basically, if you disable a form element and use the DOM2 dispatchEvent method on the element to simulate a click, the element fires the event.  Since the element is disabled, it should not fire any click event handlers &#8211; this is the behavior [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve stumbled across a bug in Opera 9.27 (which I dutifully reported).  Basically, if you disable a form element and use the DOM2 <a href="http://developer.mozilla.org/en/docs/DOM:element.dispatchEvent"><code>dispatchEvent</code></a> method on the element to simulate a click, the element fires the event.  Since the element is disabled, it should not fire any click event handlers &#8211; this is the behavior in Firefox and Safari.   Here&#8217;s the html I used to prove it:</p>
<p><a href="http://billyreisinger.com/blog/?attachment_id=9" rel="attachment wp-att-9" title="Opera disabled form element / dispatchEvent test">Opera disabled form element / dispatchEvent test</a></p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/05/disabled-form-element-and-dispatchevent-bug-in-opera/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Encapsulation vs. Efficiency in JavaScript</title>
		<link>http://billyreisinger.com/blog/2008/05/encapsulation-vs-efficiency-in-javascript/</link>
		<comments>http://billyreisinger.com/blog/2008/05/encapsulation-vs-efficiency-in-javascript/#comments</comments>
		<pubDate>Wed, 14 May 2008 23:22:55 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=7</guid>
		<description><![CDATA[I&#8217;m an encapsulation fanatic.  I love to write code where data is protected from view and unavailable for mischief.  I like the ability to react to changes to the internal state of a function.  Also, the thought of something accessing and re-writing a method or variable on another class instance scares me, and I&#8217;d [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m an encapsulation fanatic.  I love to write code where data is protected from view and unavailable for mischief.  I like the ability to react to changes to the internal state of a function.  Also, the thought of something accessing and re-writing a method or variable on another class instance scares me, and I&#8217;d rather just not let it happen.  A ton of my code ends up looking like this:</p>
<pre>
var Cookie = function() {
   var chips = {};
   this.addChip = function(type) {
      chips[type]++;
      bakeCookie();
   }
}
</pre>
<p>On the other hand, there are quite a few times when I&#8217;m writing JavaScript that I wonder when I should be worrying about efficiency.  It&#8217;s an obvious fact that using prototype methods can increase efficiency by reducing the amount of memory and processing required.  I&#8217;ve always assumed (from doing very short, non-scientific tests in a browser) that this technique pays off only when using many instances of a particular object.</p>
<pre>var Cookie = function() {
   this.chips = {};
}
Cookie.prototype.addChip = function(type) {
   this.chips[type]++;
}
</pre>
<p>You might as well not even have the <code>addChip</code> method at this point.  Anybody could come along and change <code>chips</code> &#8211; hell, they could turn it into a number or something.</p>
<p>Without the ability to maintain privacy, you won&#8217;t ever know when your properties change (in case you want to do something when one changes).  Without privacy, you can&#8217;t hide your implementation details and provide a clean interface (in case you need to re-write the guts of your function) without a guarantee that nobody has latched onto one of the properties or methods you don&#8217;t care about anymore.</p>
<p>This is one of the most frustrating things about JavaScript for me.  For performance, we are forced to make a decision wherein we must sacrifice privacy.  Personally, I don&#8217;t use prototype methods all that much &#8211; until I know that a  class I&#8217;m using will be instantiated many, many times, it just doesn&#8217;t make sense to me to lose all the benefits of privacy.  Performance be damned &#8211; hell, from what I heard, you are supposed to <a href="http://en.wikipedia.org/wiki/Optimization_(computer_science)#When_to_optimize">optimize as a last resort</a>, anyway.</p>
<p>I&#8217;d love to hear what other people think, though.</p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/05/encapsulation-vs-efficiency-in-javascript/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Script Everything</title>
		<link>http://billyreisinger.com/blog/2008/05/script-everything/</link>
		<comments>http://billyreisinger.com/blog/2008/05/script-everything/#comments</comments>
		<pubDate>Wed, 07 May 2008 04:33:07 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[nfjs]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=6</guid>
		<description><![CDATA[One of the neat things I learned at the last No Fluff Just Stuff conference I went to was from one of Neal Ford&#8217;s Productive Programmer seminars.   Script everything.  I&#8217;ve been using this as my mantra lately.  Why should I do steps a, b, c, d, e, f, and g again, even if I only do the [...]]]></description>
			<content:encoded><![CDATA[<p>One of the neat things I learned at the last <a href="http://www.nofluffjuststuff.com/">No Fluff Just Stuff</a> conference I went to was from one of <a href="http://www.nealford.com/">Neal Ford</a>&#8217;s Productive Programmer seminars.   Script everything.  I&#8217;ve been using this as my mantra lately.  Why should I do steps a, b, c, d, e, f, and g again, even if I only do the task once a day or even once a week?  I&#8217;m still looking for a script to help me remember stuff, like car keys and feeding the cats.  </p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/05/script-everything/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use only the JavaScript that you need</title>
		<link>http://billyreisinger.com/blog/2008/04/use-only-the-javascript-that-you-need/</link>
		<comments>http://billyreisinger.com/blog/2008/04/use-only-the-javascript-that-you-need/#comments</comments>
		<pubDate>Mon, 07 Apr 2008 03:14:14 +0000</pubDate>
		<dc:creator>billy</dc:creator>
				<category><![CDATA[frameworks]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://billyreisinger.com/blog/?p=5</guid>
		<description><![CDATA[I am a person who likes to use JavaScript development frameworks, such as Prototype or JQuery.  There is a time and a place for such things &#8211; as when developing your own website or working on some code that relies on lots of UI bells and whistles (fade outs, complex event handling, etc).   On [...]]]></description>
			<content:encoded><![CDATA[<p>I am a person who likes to use JavaScript development frameworks, such as Prototype or JQuery.  There is a time and a place for such things &#8211; as when developing your own website or working on some code that relies on lots of UI bells and whistles (fade outs, complex event handling, etc).   On the other hand, when I&#8217;m writing code that is going to end up as a distributed application, such as a widget,  I don&#8217;t think that using a development framework is appropriate.   There are a few reasons for this: 
<ol>
<li>Serving only the code that is used saves user time &#8211; less downloading and less parsing.  </li>
<li>Part of developing JavaScript applications is accepting the fact that you don&#8217;t know where your code is going to run.  You should maximize compatibility. </li>
<li>Frameworks make hard things easier to code &#8211; but not necessarily faster to run. </li>
</ol>
<p>I&#8217;ll start with the first point: serve only the code that you use.   Even when I&#8217;ve used a framework heavily on a project, it seems like there is about 60% or 70% of the framework that is useless to me.   Why should I bother with that crud?  Most of the time, it makes more sense to steal code from one framework or another to accomplish what I want to do.  More often than not, the problem I&#8217;m faced with can be stripped down to the statement: &#8220;I need a cross-browser way to do &#8216;x.&#8217;&#8221; If that&#8217;s all I need, I&#8217;d rather solve it myself through some simple research, or steal code from someone who has already done the research, such as <a href="http://www.quirksmode.org/">PPK</a>.   The ugly truth is that JavaScript developers need to think about bandwidth and processor overhead.   Not all users are running their browser on &#8220;decent&#8221; hardware and a fast connection.   There are no hardware requirements for JavaScript!  Sure, you need a  web browser with a JavaScript interpreter &#8211; but that includes such a large swath of browsers and versions of browsers that it&#8217;s literally a crap shoot. </p>
<p>Second point  - maximizing code compatibility.  I disagree with using a framework that pollutes the global scope in such a manner that it can break others&#8217; scripts through its mere existence.  I am specifically referring to the Prototype library, which adds methods to native objects such as the Array object.   Of course, when you know where and how your code is running, use what you want.   I happen to think Prototype is a great library, and that the people working on it are incredibly smart.  On the other hand, if your code is supposed to run on a bunch of other sites, you should try to write it so that it doesn&#8217;t pollute and possibly break other scripts.   These days, there are tons of authoritative sites to find a cross-browser way to solve your particular problem. You can steal code from a framework,  Google the problem until you find a good snippet, or learn about the issue and come up with your own solution.  Using a library to solve only a few of these problems is heavy-handed if you are expecting a large amount of traffic on your particular project.  </p>
<p>Lastly - frameworks make hard things easy to code, but not necessarily faster to run.  For example, take the JQuery library.  It&#8217;s extremely useful to be able to query the DOM in the CSS/XPathy kind of thing that JQuery implements. On the other hand, if you are not concerned with the manner in which the library accomplishes what you ask it to do, you are asking for trouble.  The classic example is running a class name query on a large node set.  Yuck &#8211; that can take eons to complete in Internet Explorer!  Granted, it&#8217;s not JQuery&#8217;s fault that your code is inefficient &#8211; but if you had gone through the trouble of selecting all nodes and checking each class name to see if it matched what you were interested in, you&#8217;d quickly see that you were being inefficient.  When you use one of these libraries, you are tempted to use the concise, convenient syntax without caring how it works.  Understanding how it works, though, is the only way to understand how to use it efficiently.   </p>
]]></content:encoded>
			<wfw:commentRss>http://billyreisinger.com/blog/2008/04/use-only-the-javascript-that-you-need/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
