<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>XyzzyB - programming</title>
  <id>tag:www.xyzzyb.com,2008:mephisto/programming</id>
  <generator version="0.7.3" uri="http://mephistoblog.com">Mephisto Noh-Varr</generator>
  <link href="http://www.xyzzyb.com/feed/programming/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.xyzzyb.com/programming" rel="alternate" type="text/html"/>
  <updated>2008-10-05T03:24:06Z</updated>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-10-05:794</id>
    <published>2008-10-05T03:20:00Z</published>
    <updated>2008-10-05T03:24:06Z</updated>
    <category term="programming"/>
    <category term="television"/>
    <category term="videogames"/>
    <link href="http://www.xyzzyb.com/2008/10/5/so-what-s-up" rel="alternate" type="text/html"/>
    <title>So, what's up?</title>
<content type="html">
            &lt;p&gt;We now return our regular infrequent updates, already in progress.&lt;/p&gt;


	&lt;p&gt;The iPod Touch continues to be a really nice gizmo. Now only do I still use it as my primary home email interface, but it&#8217;s also my front end to Wikipedia, the New York Times, and Pandora Radio thanks to some excellent applications. Every night Sarah and I pass a game of Scrabble back and forth. The Scrabble app is surprisingly complete, considering Hasbro phoned in their facebook version. It includes a nifty game play mode wherein each player places a word from the same set of letters, each player gets the score from their word, and whoever&#8217;s word has the higher score is kept on the board. It nicely eliminates luck from the game, so it&#8217;s all down to whoever can tease out the best word.&lt;/p&gt;


	&lt;p&gt;My XBox 360 briefly suffered from the red ring of death, but Microsoft&#8217;s surprisingly expedient (and free, even though my box was out of warranty) repair service had it back to me in about a week. While there was a gap in my high definition gaming I decided to actually buy a game for the so far only used for moving watching Playstation 3. I wanted a game exclusive to the &lt;span class=&quot;caps&quot;&gt;PS3&lt;/span&gt; (why would I play a game without achievements when I have the choice?) and a game on the cheap: &lt;a href=&quot;http://en.wikipedia.org/wiki/MotorStorm&quot;&gt;Motorstorm&lt;/a&gt; fit the bill. Turns out, it&#8217;s not all that bad. I mean, if I had bought that as a first game for my &lt;span class=&quot;caps&quot;&gt;PS3&lt;/span&gt; for $60 I&#8217;d be mighty let-down, but as a bargain-game is pretty ok. Just imagine Excitbike thrown into a multi-route, gorgeously 3d (and it a very gorgeous game), and multi-vehicle game work and you&#8217;ll have a pretty good grasp of the game. It&#8217;s even got the same boosting/overheating mechanic. Unfortunately the developers were so focused on making the pretty, the forgot some of the fun. Yes there are some races were you can just pick any vehicle from big rig to motorcycle, but to artifically extend the length of the game the developers take away that choice whenever possible and force you to race in a a specific type of vehicle. As you win races you unlock new cars and courses, but most often you&#8217;ll unlock…the same course but with a different vehicle type that you are forced to use. Lame.&lt;/p&gt;


	&lt;p&gt;Sarah and I are enjoying the new series, Fringe. The science is &lt;em&gt;completely&lt;/em&gt; bogus, but the show clicks together in a fun way.&lt;/p&gt;


	&lt;p&gt;Work continues to be awesome. I&#8217;ve finished up an internal IP address tracking tool and had a great time learning mod_python and jQuery while I was at it. jQuery is, simply put, an amazing accomplishment. JavaScript and &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; made sane. jQuery plugins allow us coders to add in some terrific shiny things (e.g. &lt;a href=&quot;http://tablesorter.com/docs/&quot;&gt;jQuery Tablesorter&lt;/a&gt;) for the cost of properly marking up our &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; (which would have been done anyway), a one line include, and a one line jQuery script ($(&#8221;#myTable&#8221;).tablesorter();). Hello awesome!&lt;/p&gt;


	&lt;p&gt;Edward continues to get cuter and cuter. He &lt;em&gt;loves&lt;/em&gt; to play peek-a-boo and is starting to get ticklish, which is exceedingly adorable. Moving continues to be his activity of choice and his favorite place to be is hanging out on one of our shoulders peering around at the world.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-07-12:487</id>
    <published>2008-07-12T03:43:00Z</published>
    <updated>2008-07-12T03:45:34Z</updated>
    <category term="programming"/>
    <link href="http://www.xyzzyb.com/2008/7/12/getting-paid-to-have-fun" rel="alternate" type="text/html"/>
    <title>Getting paid to have fun</title>
<content type="html">
            &lt;p&gt;So what&#8217;s being going on in my life, except for the whole newborn baby thing? A new job, that&#8217;s what. Two weeks ago I started work as the newest member of &lt;span class=&quot;caps&quot;&gt;UNC&lt;/span&gt;-Chapel Hill&#8217;s University Library web team. Although this job move meant giving up my corner office (and its glorious floor to ceiling windows) in the Undergraduate Library for a cube in a windowless room in Davis, it&#8217;s been lots of fun. It&#8217;s just so great to have a job where I can actually apply the knowledge I&#8217;ve gotten from reading tons of programming and web design books. So far I&#8217;ve gotten to get into the &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; and jsp code for an upcoming catalog design (IE6, we hates you), had serious chunks of time to work on the reserves website that&#8217;s been languishing in my todo list for over a year, have been encouraged to explore an interesting project idea, and have had lots of collaborative fun with &lt;a href=&quot;http://nivex.net/&quot;&gt;Nivex&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;Today I also had the brand new pleasure of working an entire day from home. I&#8217;ve just never had a job that didn&#8217;t require me to be physically present. I gotta say, it was pretty enjoyable and genuinely productive. I wasn&#8217;t sure how well it would work, but I was really able to just hunker down at the kitchen table and hack out code for hours straight. Although library systems doesn&#8217;t allow telecommuting on a regular basis, I&#8217;ve gotten approval to do it for the rest of the Fridays this month to be be available for baby helping.&lt;/p&gt;


	&lt;p&gt;This job is also nice because I feel like I&#8217;ve finally completed a long circular journey. My library career started in Davis Library as a student assistant for the technical services department. When I was returning to the library as a reserves processor and exploring the (still on the horizon) possibility of library school I contacted one of my old bosses who put me in touch with the guy who is now my new boss in the web team. It&#8217;s weird, but it just feels complete. Like I&#8217;ve finished one major life stage and am moving on to the next. Although a lot of that may come from the whole baby thing, I&#8217;m still loving the new job. Programming has always been one of the &#8220;work&#8221; activities that just makes the time fly by until I find myself staying ten or fifteen minutes late just to try out one more idea, or wrap up to a stopping point. Somehow I&#8217;ve always ended up doing it no matter what job I&#8217;ve had, so it&#8217;s great to actually get explicitly paid for it.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-07-08:483</id>
    <published>2008-07-08T14:47:00Z</published>
    <updated>2008-07-08T14:50:31Z</updated>
    <category term="learning"/>
    <category term="programming"/>
    <category term="quicklinks"/>
    <link href="http://www.xyzzyb.com/2008/7/8/edit-the-text-of-any-website" rel="alternate" type="text/html"/>
    <title>Edit the text of any website</title>
<content type="html">
            &lt;p&gt;From &lt;a href=&quot;http://www.blogstorm.co.uk/cut-and-paste-one-line-of-code-to-make-any-website-editable/&quot;&gt;Cut and paste one line of code to make any website editable&lt;/a&gt;:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;javascript:document.body.contentEditable='true';
document.designMode='on'; void 0&lt;/code&gt;&lt;/pre&gt;

What&#8217;s that you ask? That is an awesome small chunk of JavaScript that allows you to make the text of any website editable within the browser window. Just:
	&lt;ol&gt;
	&lt;li&gt;Copy the code to the clipboard&lt;/li&gt;
		&lt;li&gt;Browse to the site you want to edit&lt;/li&gt;
		&lt;li&gt;Paste the code into the address bar and press return&lt;/li&gt;
		&lt;li&gt;Edit the site&#8217;s text however you like&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Let the pranking begin.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-05-29:387</id>
    <published>2008-05-29T00:28:00Z</published>
    <updated>2008-05-29T00:29:43Z</updated>
    <category term="learning"/>
    <category term="programming"/>
    <category term="quicklinks"/>
    <link href="http://www.xyzzyb.com/2008/5/29/ajax-head-design-pattern" rel="alternate" type="text/html"/>
    <title>"AJAX Head" Design Pattern</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.metaskills.net/2008/5/24/the-ajax-head-br-design-pattern&quot;&gt;&lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; Head design pattern&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-05-26:376</id>
    <published>2008-05-26T15:33:00Z</published>
    <updated>2008-05-26T17:38:45Z</updated>
    <category term="learning"/>
    <category term="programming"/>
    <link href="http://www.xyzzyb.com/2008/5/26/notes-on-javascript-video-lecture-2" rel="alternate" type="text/html"/>
    <title>Notes on Crockford's Javascript Video Lecture 2</title>
<content type="html">
            &lt;p&gt;Notes I took while watching the &lt;a href=&quot;http://video.yahoo.com/watch/111594&quot;&gt;second video of Douglas Crockford&#8217;s JavaScript lecture&lt;/a&gt;&lt;/p&gt;


	&lt;h1&gt;Statements&lt;/h1&gt;


	&lt;p&gt;JavaScript has all the statements that you&#8217;d expect to find in any of the other C langauges. e.g. if, switch, while, do, for, break, continue, return, try/throw; but there are some differences in how they are used.&lt;/p&gt;


	&lt;p&gt;You can label loops and then break out of them by label. Handy if you want to break out of a nest of loops.&lt;/p&gt;


	&lt;p&gt;The for statement can loop through an array and through the members of objects.&lt;/p&gt;


	&lt;p&gt;Unfortunately for looping through an object will take you through all the kys of all the objects that the object inherits from. To prevent this you have to test that the object being looped through itself has that property. This is highly recommended to avoid strange behavior.&lt;/p&gt;


	&lt;p&gt;Switch values don&#8217;t need to be numbers, can be strings&lt;/p&gt;


	&lt;p&gt;Case values can be expressions &#8211; handy&lt;/p&gt;


	&lt;p&gt;You have to explicitly terminate case clauses, as usual.&lt;/p&gt;


	&lt;p&gt;Switch statements allow a default case.&lt;/p&gt;


	&lt;p&gt;Throwing exceptions behaves typically, as does try/catch.&lt;/p&gt;


	&lt;p&gt;You can generate exception objects by calling its new constructor, or use with object literal&lt;/p&gt;


JavaScript comes with the following exceptions:
	&lt;ul&gt;
	&lt;li&gt;Error&lt;/li&gt;
		&lt;li&gt;EvalError&lt;/li&gt;
		&lt;li&gt;RangeError&lt;/li&gt;
		&lt;li&gt;SyntaxError&lt;/li&gt;
		&lt;li&gt;TypeError&lt;/li&gt;
		&lt;li&gt;URIError&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;You can, of course, make up your own exceptions.&lt;/p&gt;


	&lt;p&gt;Avoid using the with statement. It was designed to be a convience for dealing with objects, but there is an error in its design leading to ambiguous statements.&lt;/p&gt;


	&lt;p&gt;There is a function statement used for declaring functions.&lt;/p&gt;


	&lt;p&gt;The var statement defines variables within functions. JavaScript is loosely typed so you just declare the variable and optionally initialize.&lt;/p&gt;


	&lt;p&gt;Without initialization variables are undefined.&lt;/p&gt;


	&lt;p&gt;Unless you limit the variable scope with var they are assumed to be global. :-/&lt;/p&gt;


	&lt;p&gt;Unlike most C languages, blocks do not have scope. There is &lt;strong&gt;only&lt;/strong&gt; function scope.&lt;/p&gt;


	&lt;p&gt;Return can return an expression or just return;&lt;/p&gt;


	&lt;p&gt;return; doesn&#8217;t return nothing, it returns undef&lt;/p&gt;


	&lt;p&gt;When used in constructors they will return the new object.&lt;/p&gt;


	&lt;h1&gt;Objects&lt;/h1&gt;


	&lt;p&gt;Objects contain data and methods.&lt;/p&gt;


	&lt;p&gt;Objects only inherit from other objects, there is no concept of a Class.&lt;/p&gt;


	&lt;p&gt;Objects in JavaScript are an unordered collection of name/value pairs. Names are strings, values are anything including other objects or expressions.&lt;/p&gt;


	&lt;p&gt;Every object is essentially a tiny database&lt;/p&gt;


	&lt;h2&gt;Object Literals&lt;/h2&gt;


	&lt;p&gt;&lt;strong&gt;Object Literals&lt;/strong&gt; are an easy way of creating a new object. The are data wrapped in { }. &#8221;:&#8221; separates names and values. &#8221;,&#8221; separates pairs. An object literal can be used anywhere a value can appear.&lt;/p&gt;


Object Literal Example: var myObject = {firstName: &#8220;Stephen&#8221;, &#8216;lastName&#8217;:&#8217;Ball&#8217;, middleInitial:&#8217;A&#8217;, age: 29};
&lt;pre&gt;
&lt;code&gt;
  // These syntaxes are interchangable
  var theName = myObject.firstName;
  var destination = myObject['firstName'];
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Maker functions can be used to build objects. Pass material to maker function and it will make an object and return it&lt;/p&gt;


	&lt;p&gt;Object Literals can have nested objects, or object literals, as values.&lt;/p&gt;


	&lt;p&gt;If we pass an object literal to a function, the function doesn&#8217;t know if the object already existed or was a literal declared with the call.&lt;/p&gt;


	&lt;p&gt;Rather than define a function that takes a lot of parameters (e.g. more than two or three), think about passing an object instead.&lt;/p&gt;


Objects in JavaScript can be augmented at anytime with new methods and data. There is no class, so obviously no need to define a new one. Just modify the object you want to expand directly.
&lt;pre&gt;
&lt;code&gt;
  // to add data to an object simply set it
  existingObject[newKey] = newValue;
  existingObject.newKey = newValue;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;h2&gt;Object Linkage&lt;/h2&gt;


	&lt;p&gt;When objects are created they have a secret link to another object. This is how inheritance is achived.&lt;/p&gt;


	&lt;p&gt;If a member is requested from an object and the object doesn&#8217;t have it, JavaScript silently follows the link to the secret object and sees if it has the member and, if so, returns it. The child object now has the data member locally. Odd side effect: if you delete a data member of a child object that is set in the parent object then the child object&#8217;s data isn&#8217;t really deleted. If requested the &#8220;deleted&#8221; data will be fetched from the parent object again without notice.&lt;/p&gt;


	&lt;p&gt;The secret link is not used for storing new values in the parent object. Data is only retreived.&lt;/p&gt;


	&lt;p&gt;Obviously this means that there is only single inheritence in JavaScript. Also that there is truly no Class equivalent in JavaScript. Objects only inhereit from objects.&lt;/p&gt;


	&lt;p&gt;We can use the object function to make a new empty object that has that linkage to an existing object. ex: var myNewObject = object(myOldObject);&lt;/p&gt;


	&lt;p&gt;Some languages have classes, methods, constructors, modules: JavaScript has functions, and functions do the work of all of those. This allows greater expressive power, but requires a different way of thinking.&lt;/p&gt;


	&lt;p&gt;There is garbage collection in JavaScript.&lt;/p&gt;


	&lt;p&gt;All objects are linked directly or indirectly to Object.prototype that has some basic methods, but no copy method and no comparison method.&lt;/p&gt;


	&lt;p&gt;You can see if two objects are, in fact, the same object; but not tell whether they are equivilent.&lt;/p&gt;


	&lt;h2&gt;Object Construction&lt;/h2&gt;


There are three ways to create a new, empty object:
	&lt;ul&gt;
	&lt;li&gt;new Object{}&lt;/li&gt;
		&lt;li&gt;{}&lt;/li&gt;
		&lt;li&gt;object(Object.prototype)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;All three return exactly the same object, {} is recommended for conciseness.&lt;/p&gt;


	&lt;p&gt;Objects can be passed to functions as arguments and returned from fucntions.&lt;/p&gt;


	&lt;p&gt;Objects are always are passed by reference.&lt;/p&gt;


	&lt;p&gt;=== between objects will only return true if both objects are the same object.&lt;/p&gt;


	&lt;p&gt;The delete operator will remove members from objects, delete myObj[key] by changing the value to undefined.&lt;/p&gt;


	&lt;h1&gt;Arrays&lt;/h1&gt;


Arrays are unusual:
	&lt;ul&gt;
	&lt;li&gt;array inherits from object&lt;/li&gt;
		&lt;li&gt;array indexes are converted into strings and then used as names for retrieving values&lt;/li&gt;
		&lt;li&gt;very efficient for sparse arrays, but not for everything else&lt;/li&gt;
		&lt;li&gt;arrays aren&#8217;t typed&lt;/li&gt;
		&lt;li&gt;arrays have length member, it is always 1 larger than the highest integer subscript which may not be its actual length (!)&lt;/li&gt;
		&lt;li&gt;it does allow a for loop to go through the array easily by just saying less than array.length&lt;/li&gt;
		&lt;li&gt;do not use for&#8230;in with arrays&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Array Literals&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;uses []&lt;/li&gt;
		&lt;li&gt;can contain any number of expressions&lt;/li&gt;
		&lt;li&gt;new items can be appended, arr[arr.length] = value&lt;/li&gt;
		&lt;li&gt;can&#8217;t use dot notation with arrays, subscript notation instead&lt;/li&gt;
		&lt;li&gt;[] is the preferred method to create a new array, not the new array construct&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Array Methods&lt;/h2&gt;


	&lt;ul&gt;
	&lt;li&gt;concat&lt;/li&gt;
		&lt;li&gt;join&lt;/li&gt;
		&lt;li&gt;pop&lt;/li&gt;
		&lt;li&gt;push&lt;/li&gt;
		&lt;li&gt;slice&lt;/li&gt;
		&lt;li&gt;sort&lt;/li&gt;
		&lt;li&gt;splice&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Deleting from array: delete array[number] removes element but leaves a &#8220;hole&#8221; in the array as an undefined value. To completely delete a value and index you need to splice it out.&lt;/p&gt;


	&lt;h2&gt;Use Object or Array?&lt;/h2&gt;


	&lt;p&gt;Since objects and arrays are so similar, when do you use which?&lt;/p&gt;


	&lt;p&gt;Use objects when names are arbitrary strings, e.g. associative array.&lt;/p&gt;


	&lt;p&gt;Use arrays when names need to be sequential.&lt;/p&gt;


	&lt;p&gt;Arrays all inherit from array.prototype.&lt;/p&gt;


If you get a value, there are two methods to tell whether it is an array or an object:
	&lt;ul&gt;
	&lt;li&gt;value.constructor === Array&lt;/li&gt;
		&lt;li&gt;value instanceof Array&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;BUT&lt;/span&gt; neither of those methods work when value comes from a different frame, a bug in the language.&lt;/p&gt;


	&lt;p&gt;You can&#8217;t inherit from an array because the value produced will be an object, not an array. You can augment an individual array by adding methods to it. You can also assign methods directly to Array.prototype to change all arrays in the program.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-05-26:377</id>
    <published>2008-05-26T15:26:00Z</published>
    <updated>2008-05-26T15:26:25Z</updated>
    <category term="learning"/>
    <category term="programming"/>
    <link href="http://www.xyzzyb.com/2008/5/26/notes-on-crockfords-javascript-video-lecture-1" rel="alternate" type="text/html"/>
    <title>Notes on Crockfords JavaScript Video Lecture 1</title>
<content type="html">
            &lt;p&gt;Notes I took while watching the &lt;a href=&quot;http://video.yahoo.com/watch/111593&quot;&gt;first video of Douglas Crockford&#8217;s JavaScript lecture&lt;/a&gt;&lt;/p&gt;


	&lt;h1&gt;Language Outline&lt;/h1&gt;


	&lt;p&gt;&#8220;script&#8221; suggests that JavaScript isn&#8217;t a real programming language, Douglas posits that not only is it a real programming language, but a pretty good one.&lt;/p&gt;


	&lt;p&gt;The language &lt;em&gt;does&lt;/em&gt; contain some design errors.&lt;/p&gt;


	&lt;p&gt;Early bad implementations resulted in JavaScript getting a bad reputation. The implementation are now good.&lt;/p&gt;


	&lt;p&gt;Programming for the browser and &lt;span class=&quot;caps&quot;&gt;DOM&lt;/span&gt; is extremely difficult. A lot of people think that the problem is javacsript itself, but it&#8217;s more the environment.&lt;/p&gt;


	&lt;p&gt;Books on JavaScript are almost (as of 2007) universally bad. The Definitive Guide from O&#8217;Reilly is the &#8220;least bad&#8221; book.&lt;/p&gt;


	&lt;p&gt;JavaScript standard defined by &lt;span class=&quot;caps&quot;&gt;ECMA&lt;/span&gt;, but the standard is not very good. Very difficult to read which led to the bad book problem &#8211; no good authoritive source to reference.&lt;/p&gt;


	&lt;p&gt;JavaScript is a functional language like lisp and scheme.&lt;/p&gt;


	&lt;h2&gt;JavaScript&#8217;s History&lt;/h2&gt;


	&lt;p&gt;1992: Jim Gosling started working on a language he called C+&lt;ins&gt;+&lt;/ins&gt; then changed to Oak. Gosling go into a new startup, Oak was used in applications. Company fail. Moved back to Sun. What to do with Oak? Needed new name, Java. Application to demo new language would be web browser, HotJava.&lt;/p&gt;


	&lt;p&gt;Meanwhile at Netscape. They looked at Java but decided that it was too heavy for browsers. Brendan Ike had idea to do dialect of scheme in the browser, but management said to make a scripting language that looked like Java. That became Livescript. First scripting language to be put into a browser, and first to be put on a server.&lt;/p&gt;


	&lt;p&gt;Reason Netscape and Java so exciting at the time was that they were envisioned as a way to escape from Microsoft: applications on the net. They decided to ally. Sticky part: what to do with Livescript. A divide between those that wanted Java to be the language of the web, Netscape refused for above reasons. So Livescript name changed to JavaScript and then Sun took naming control of the language.&lt;/p&gt;


	&lt;p&gt;Microsoft didn&#8217;t like this so they reverse engineered the language into JScript.&lt;/p&gt;


	&lt;p&gt;Netscape didn&#8217;t care for this at all. To prevent Microsoft from assuming control of the language they decided to make JavaScript a standard. They took it to the European Computer Manufactors Association (ECMA) because they thought that their language standard would just be rubber stamped there. Unfortunately Microsoft was a member of &lt;span class=&quot;caps&quot;&gt;ECMA&lt;/span&gt;, so from the first day Microsoft dictated the standardization. Microsoft had made some errors while reverse-engineering JavaScript into JScript, and they insisted that those errors become part of the standard. It was very important to Microsoft at that time to never do anything to cause anyone&#8217;s programs to break. &lt;span class=&quot;caps&quot;&gt;ECMA&lt;/span&gt; agreed.&lt;/p&gt;


	&lt;h2&gt;What is JavaScript?&lt;/h2&gt;


	&lt;p&gt;JavaScript is not a web toy language, it is real, useful, and sophisticated. Also very effective.&lt;/p&gt;


JavaScript&#8217;s key set of ideas:
	&lt;ul&gt;
	&lt;li&gt;load and go delivery: programs are delivered to the execution site as source code. Reasoning is that it was intended to be embedded in webpages, which are text. This is, of course, no longer the preferred way to getting programs to browsers but the legacy remains.&lt;/li&gt;
		&lt;li&gt;Loose Typing&lt;/li&gt;
		&lt;li&gt;Objects are general containers: unification of objects and hash tables&lt;/li&gt;
		&lt;li&gt;Prototypal inheritance: much different than Class inheritance. Objects can only inherit from other objects. There are no Classes.&lt;/li&gt;
		&lt;li&gt;Lambda: functions are first class objects.&lt;/li&gt;
		&lt;li&gt;Linkage through global variables. Because of &#8220;load and go&#8221; JavaScript doesn&#8217;t have any kind of linker. Separate compilation units are combined into a global namespace, which is a really bad idea.&lt;/li&gt;
	&lt;/ul&gt;


JavaScript has a small set of possible values
	&lt;ul&gt;
	&lt;li&gt;Numbers&lt;/li&gt;
		&lt;li&gt;Strings&lt;/li&gt;
		&lt;li&gt;Booleans&lt;/li&gt;
		&lt;li&gt;Objects&lt;/li&gt;
		&lt;li&gt;null&lt;/li&gt;
		&lt;li&gt;undefined&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;JavaScript doesn&#8217;t have multiple number types (e.g. Integer, Float). There are, in fact, no integers. All numbers are represented as 64-bit floating point (i.e. doubles). This means that common arithmetic can act strangely: .1 + .2 != .3&lt;/p&gt;


	&lt;p&gt;If dealing with decimals need to multiply by 100 for the operations, then scale back.&lt;/p&gt;


	&lt;p&gt;NaN is a value that is &#8220;not a number&#8221;. It is returned as the result of undefined or erroneous mathematical statements, e.g. 0/0. It is toxic: any arithmetic operation with NaN as an input will return NaN. NaN is not equal to anything, even itself. NaN === NaN is false. NaN is also not less than NaN or greater than NaN. But if you get typeof NaN it is Number.&lt;/p&gt;


	&lt;p&gt;Number function converts string into a number. Produces NaN if it has a problem. Similar to + operator.&lt;/p&gt;


	&lt;p&gt;parseInt function parses integers from a string. Generally you should include radix argument to specify the base we are parsing.&lt;/p&gt;


	&lt;p&gt;Like Java, JavaScript has a separate Math object. This is an unfortunate idea. The Math object contains a number of useful functions e.g. abs, floor, log, random, round, sqrt.&lt;/p&gt;


	&lt;p&gt;JavaScript has Strings. They are a sequence of 0 or more 16-bit characters encoded in &lt;span class=&quot;caps&quot;&gt;UCS&lt;/span&gt;-2 (not &lt;span class=&quot;caps&quot;&gt;UTF&lt;/span&gt;-16 as it has no awareness of pairs for extended character range). The extra characters of &lt;span class=&quot;caps&quot;&gt;UTF&lt;/span&gt;-16 are very rarely used, but it is something to be aware of.&lt;/p&gt;


	&lt;p&gt;No character type in JavaScript. A &#8220;character&#8221; is a string of one character.&lt;/p&gt;


	&lt;p&gt;Strings are immutable.&lt;/p&gt;


	&lt;p&gt;Similar strings are equal with &lt;/p&gt;


	&lt;p&gt;String literals can be written with single or double quotes, they are the same.&lt;/p&gt;


	&lt;p&gt;All Strings have a &quot;length&quot; method that returns the number of 16-bit &quot;characters&quot; in the string. This won't necessarily be the number of unicode characters in the string.&lt;/p&gt;


	&lt;p&gt;String function converts a number into a string.&lt;/p&gt;


Strings are objects and so have methods, e.g.:
	&lt;ul&gt;
	&lt;li&gt;charAt&lt;/li&gt;
		&lt;li&gt;concat&lt;/li&gt;
		&lt;li&gt;indexOf&lt;/li&gt;
		&lt;li&gt;lastIndexOf&lt;/li&gt;
		&lt;li&gt;match&lt;/li&gt;
		&lt;li&gt;replace&lt;/li&gt;
		&lt;li&gt;search&lt;/li&gt;
		&lt;li&gt;slice&lt;/li&gt;
		&lt;li&gt;split&lt;/li&gt;
		&lt;li&gt;substring&lt;/li&gt;
		&lt;li&gt;toLowerCase&lt;/li&gt;
		&lt;li&gt;toUpperCase&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Two boolean values in JavaScript: true and false.&lt;/p&gt;


	&lt;p&gt;Boolean function will take a value and returns its boolean value.&lt;/p&gt;


	&lt;p&gt;Null is the value that isn't anything.&lt;/p&gt;


	&lt;p&gt;Undefined is the value that isn't even null. It is the default value for variables. This is confusing because if you define a variable without initializing it it will have the value &quot;undefined&quot;.&lt;/p&gt;


	&lt;p&gt;Undefined is the value you get when you extract a member from an object that doesn't have that member. It is the &quot;missing value&quot; value.&lt;/p&gt;


Values that evaluate as false, everything else evaluates as true:
	&lt;ul&gt;
	&lt;li&gt;false&lt;/li&gt;
		&lt;li&gt;null&lt;/li&gt;
		&lt;li&gt;undefined&lt;/li&gt;
		&lt;li&gt;empty string&lt;/li&gt;
		&lt;li&gt;0&lt;/li&gt;
		&lt;li&gt;NaN&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;After these simple values, everything else in JavaScript is Objects. JavaScript is actually an object-oriented language.&lt;/p&gt;


Dynamic Objects
	&lt;ul&gt;
	&lt;li&gt;unification of Object and Hashtable&lt;/li&gt;
		&lt;li&gt;new Object() produces an empty container of name/value pairs&lt;/li&gt;
		&lt;li&gt;Name can be any string, value can be any value except undefined.&lt;/li&gt;
		&lt;li&gt;Object members can be access with dot notation or subscript notation: myObj.key or myObj['key']&lt;/li&gt;
		&lt;li&gt;Although they are hases, no hash nature is visible: no hash methods&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;JavaScript is loosely typed, which means that any variable is capable of receiving any value. The values do have a type (so the language isn't &quot;untyped&quot;), but variables aren't bound to them.&lt;/p&gt;


	&lt;p&gt;JavaScript is syntactically a C family language. Differs from C with its type system which allows functions (which are objects) to be values.&lt;/p&gt;


Identifiers follow same rules as most C languages.
&lt;pre&gt;
&lt;code&gt;
  Variable names match: /^[A-Za-z_$]*$/
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;By convention everything is lowercase except for constructors.&lt;/p&gt;


	&lt;p&gt;Using the initial _ should be reserved for implementations, but are very popular. Initial $ should be reserved for machines: macro processors, etc. Ajax programmers use $ variables a lot for some reason.&lt;/p&gt;


	&lt;p&gt;JavaScript has a &lt;span class=&quot;caps&quot;&gt;LOT&lt;/span&gt; of reserved words, but only a few are used.&lt;/p&gt;


	&lt;p&gt;Two comment styles: // or /*&lt;/p&gt;


Common operators that you&#8217;d expect for a C language.
&lt;pre&gt;
&lt;code&gt;
  +&quot;42&quot; = 42, just like Number(&quot;42&quot;)
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Division of two integers can produce a non integer result&lt;/p&gt;


 and != do type coercion, so always use === and !== which confirm variables are same value and type.

&lt;p&gt;&#38;&#38; is the guard operator or &#8220;logical and&#8221;. If first operand is truthy then the result is the second operard, otherwise result is first operand. Can be used to avoid null references.&lt;/p&gt;
&lt;pre&gt;
&lt;code&gt;
  return a &#38;&#38; a.member;

  does the same as:

  if (a) {
    return a.member;
  } else {
    return a;
  }
&lt;/code&gt;
&lt;/pre&gt;

|| is default or &#8220;logical or&#8221; operator. If first operand is truthy then result is first operand, otherwise second operand. Can be used to fill in default values.
&lt;pre&gt;
&lt;code&gt;
  // if formField is true, then userInput = formFieldValue
  var userInput = formFieldValue || default_value;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;! is &#8220;logical not&#8221; operator. If operand is truthy the result is false and vice versa. From this if you do !!value you will get its boolean representation.&lt;/p&gt;


JavsScript has Bitwise Operators
&lt;pre&gt;
&lt;code&gt;
  &#38; | ^ &amp;gt;&amp;gt; &amp;gt;&amp;gt;&amp;gt; &amp;lt;&amp;lt;
&lt;/code&gt;
&lt;/pre&gt;
The bitwise operators convert the operand into a 32-bit signed integer, do the operation, then convert the result back into a 64-bit floating point. Unlike normal bitwise operation, this isn&#8217;t faster. So unless you really need a bitwise operation don&#8217;t use them.
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-05-15:359</id>
    <published>2008-05-15T19:32:00Z</published>
    <updated>2008-05-25T14:37:43Z</updated>
    <category term="learning"/>
    <category term="programming"/>
    <category term="quicklinks"/>
    <category term="techtips"/>
    <link href="http://www.xyzzyb.com/2008/5/15/javascript-video-lectures" rel="alternate" type="text/html"/>
    <title>Javascript Video Lectures</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.catonmat.net/blog/learning-javascript-programming-language-through-video-lectures/?stolen_from=hacker_news&quot;&gt;Javascript Video Lectures&lt;/a&gt;&lt;/p&gt;


	&lt;p&gt;The videos are extremely well done. I rank them right up there with the videos of Knuth lecturing about TeX for clarity and flow.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-04-09:351</id>
    <published>2008-04-09T20:08:00Z</published>
    <updated>2008-05-25T14:34:16Z</updated>
    <category term="books"/>
    <category term="family"/>
    <category term="learning"/>
    <category term="math"/>
    <category term="programming"/>
    <category term="quicklinks"/>
    <category term="science"/>
    <link href="http://www.xyzzyb.com/2008/4/9/teaching-computer-science-without-a-computer" rel="alternate" type="text/html"/>
    <title>Teaching Computer Science without a Computer</title>
<content type="html">
            &lt;p&gt;I am so going to be all over this in a few years: &lt;a href=&quot;http://csunplugged.com/index.php/activities.html&quot;&gt;teach children Computer Science without a computer&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-04-02:349</id>
    <published>2008-04-02T16:48:00Z</published>
    <updated>2008-05-25T14:33:27Z</updated>
    <category term="programming"/>
    <category term="quicklinks"/>
    <category term="techtips"/>
    <link href="http://www.xyzzyb.com/2008/4/2/php-logging-class" rel="alternate" type="text/html"/>
    <title>PHP Logging Class</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://urbanoalvarez.es/blog/2008/03/21/php-logging-class/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; logging class&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-01-27:195</id>
    <published>2008-01-27T18:36:00Z</published>
    <updated>2008-09-06T19:38:36Z</updated>
    <category term="design"/>
    <category term="programming"/>
    <category term="techtips"/>
    <link href="http://www.xyzzyb.com/2008/1/27/rails-vs-django" rel="alternate" type="text/html"/>
    <title>Rails vs Django</title>
<content type="html">
            &lt;p&gt;After getting more into the depths of Django I was all set to write a comparison article, then I found one made by two guys who made the same website with both frameworks. Nicely written, lots of detail, objectively puts forward the strengths and weaknesses of both. Unfortunately the documents are not presented on a nicely written website, but in a subversion repository. I&#8217;ll put the links to the external resource first, but if those go away feel free to use the mirrored copy of the article below.&lt;/p&gt;


Rails vs. Django:
	&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://3columns.net/habitual/docs/&quot;&gt;Docs directory&lt;/a&gt;
	&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://3columns.net/habitual/docs/RailsVsDjango.pdf&quot;&gt;Rails vs. Django article&lt;/a&gt; [pdf, 132 KB]&lt;/li&gt;
		&lt;li&gt;&lt;a href=&quot;http://3columns.net/habitual/docs/Pres2.pdf&quot;&gt;Rails vs. Django presentation&lt;/a&gt; [pdf, 6.7 MB]&lt;/li&gt;
	&lt;/ul&gt;&lt;/li&gt;
	&lt;/ul&gt;


Local mirror:
	&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://xyzzyb.com/assets/2008/1/27/RailsVsDjango.pdf&quot;&gt;Rails vs. Django article&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;While both frameworks do a great job of producing databases from their corresponding language code, my biggest complaint with Django is that it lacks a counterpart to Rails&#8217; migrations. Migrations enable a Rails projec to incrementally develop the database model. Essentially it&#8217;s subversion for the database structure. You build up changes (adding/removing/altering tables, columns, etc.) using &#8216;migrations&#8217; and can apply them or roll back at your whim. Django, on the other hand, really wants a fully formed database structure to start off the project. Any changes after the initial creation have to be shoehorned in by: 1) adding the stuctures to the database directly, then 2) updating the database model within Django…bleh!&lt;/p&gt;


	&lt;p&gt;Django is clearly designed to get sites with simple models up and running fast. Using it you can definitely feel its lineage as a rapid news story development framework. Rails feels more methodical, a framework for building many types of applications but with a corresponding increase in development time. But that&#8217;s just me. I&#8217;m much more familiar with the Ruby language and (as the Rails vs. Django article concludes) both frameworks are essentially equally capable, so go with the one that uses the language you know. There is a lot of awesome (and not so awesome) in Django and Rails.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-01-25:194</id>
    <published>2008-01-25T07:30:00Z</published>
    <updated>2008-05-25T14:08:59Z</updated>
    <category term="essays"/>
    <category term="learning"/>
    <category term="programming"/>
    <category term="techtips"/>
    <link href="http://www.xyzzyb.com/2008/1/25/advantages-of-mvc" rel="alternate" type="text/html"/>
    <title>The advantages of MVC</title>
<content type="html">
            &lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt; stands for &#8220;model-view-controller&#8221;, a programming paradigm where the application is split into three interconnected yet disparate parts (as interpreted by Django):
	&lt;ol&gt;
	&lt;li&gt;the &lt;strong&gt;model&lt;/strong&gt;: the &lt;em&gt;data&lt;/em&gt; of the application&lt;/li&gt;
		&lt;li&gt;the &lt;strong&gt;view&lt;/strong&gt;: the &lt;em&gt;presentation and selection&lt;/em&gt; of data to present to the user&lt;/li&gt;
		&lt;li&gt;the &lt;strong&gt;controller&lt;/strong&gt;: the &lt;em&gt;brains&lt;/em&gt; of the application that connects the user to the correct view&lt;/li&gt;
	&lt;/ol&gt;


	&lt;p&gt;Note, the &lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt; paradigm is interpreted differently by the popular &#8220;Rails&#8221; framework (used for this very blog!). In Rails there are multiple controllers that decide what data to present to the user, and the view is left to &lt;em&gt;simply display&lt;/em&gt; the data. In this interpretation Django&#8217;s views would be seen as controllers, and Django&#8217;s templates would be views.&lt;/p&gt;


	&lt;p&gt;To best describe how &lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt; helps us do our jobs as web programmers better, lets look at a simple &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; webpage application written as a script:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
&amp;lt;?php

$page_title = &quot;Ten most recent blog entries&quot;;

include_once($include_path.'/header.php');

// setup $db
include_once($include_path.'/db_connection_for_this_application.php');

$recent_blog_posts = mysql_query(&quot;SELECT 
  posts.post_date, 
  posts.post_title, 
  posts.post_content 
FROM 
  posts
WHERE 
  posts.post_status='publish'
ORDER BY posts.post_date DESC LIMIT 10, $db);

echo '&amp;lt;h1&amp;gt;Recent Posts&amp;lt;/h1&amp;gt;';
while($posts_data = mysql_fetch_array($recent_blog_posts)) {
  echo '&amp;lt;div class=&quot;post&quot;&amp;gt;';
  echo '&amp;lt;div class=&quot;blog_date&quot;&amp;gt;' . $posts_data['post_date'] . &quot;&amp;lt;/div&amp;gt;\n&quot;;
  echo '&amp;lt;div class=&quot;blog_entry_title&quot;&amp;gt;' . $posts_data['post_title'] . &quot;&amp;lt;/div&amp;gt;\n&quot;;
  echo '&amp;lt;div class=&quot;blog_entry&quot;&amp;gt;' . $posts_data['post_content'] . &quot;&amp;lt;/div&amp;gt;\n&quot;;
  echo '&amp;lt;/div&amp;gt;';
}

include_once($include_path.'/footer.php');

?&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Simple enough. That&#8217;s actually the big advantage of writing web applications as scripts. They are (almost) entirely self-contained and easy to understand. You start reading at the top and finish at the bottom, with no file jumping or object modeling required.&lt;/p&gt;


Unfortunately, this simpliciy is also very limiting:
	&lt;ul&gt;
	&lt;li&gt;&lt;strong&gt;The content and the programming are combined.&lt;/strong&gt; This means that, aside from &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;, if any web &lt;em&gt;designers&lt;/em&gt; want to update the look of the page then they&#8217;ll have to modify the same file that contains the application. That&#8217;s a great opportunity for things to go wrong.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;The header and footer are fixed&lt;/strong&gt;. This means altering something like the title of the page forces the application to declare prespecified variables (e.g. the $page_title), that the header file assumes are in place. A bunch of these variables can quickly clutter an application. At a simple level, including headers and footers makes sense, but as pages get more complex they get harder to maintain. What if you have a standard header/footer, but want slightly modified versions for other sections? Using header/footer includes means that you&#8217;ll have to create separate include files for each. Without a clear organizational structure things can get confusing pretty quickly.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;Low-level programming is involved.&lt;/strong&gt; The programmer has to build database queries by hand, which is a great place for bugs to hide.&lt;/li&gt;
		&lt;li&gt;&lt;strong&gt;No object oriented programming.&lt;/strong&gt; You can&#8217;t wrap up functions and data into logical blocks with specific interfaces (e.g. objects). In a better system, we&#8217;d just ask the &#8220;Blog&#8221; object directly for the ten most recent posts with something like {{ blog.posts | &#8216;limit&#8217;: 10 }}&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;As you can see, there is room for something better. That something is an &lt;span class=&quot;caps&quot;&gt;MVC&lt;/span&gt; framework such as Django or Rails. Let&#8217;s look at how one (Django) solves the problems with our &lt;span class=&quot;caps&quot;&gt;PHP&lt;/span&gt; script. I&#8217;ll show you the code first, then get into the explanation:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
### models.py (the *model*) ###

from django.db import models

class Blog(models.Model):
    entry_title = models.CharField(maxlength=50)
    blog_date = models.DateField()
    entry = models.TextField()

### views.py (the *view*) ###

from django.shortcuts import render_to_response
from models import Blog

def recent_posts(request):
    post_list = Blog.objects.order_by('-blog_date')[:10]
    return render_to_response('recent_posts.html', {'post_list': post_list})

### urls.py (the *controller*) ###

from django.conf.urls.defaults import *
import views

urlpatterns = patterns('',
    (r'^recent/$', views.recent_posts),
)

### recent_posts.html (the *template* (part of the view))###

&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;Recent Blog Posts&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;h1&amp;gt;Recent Posts&amp;lt;/h1&amp;gt;
{% for post in post_list %}
&amp;lt;div class=&quot;post&quot;&amp;gt;
  &amp;lt;div class=&quot;blog_date&quot;&amp;gt;{{blog_date}}&amp;lt;/div&amp;gt;
  &amp;lt;div class=&quot;blog_entry_title&quot;&amp;gt;{{entry title}}&amp;lt;/div&amp;gt;
  &amp;lt;div class=&quot;blog_entry&quot;&amp;gt;{{entry}}&amp;lt;/div&amp;gt;
{% endfor %}
&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;Ok! That seems a little confusing compared to the script doesn&#8217;t it? Let&#8217;s dive in:&lt;/p&gt;


	&lt;h3&gt;recent_posts.html&lt;/h3&gt;


	&lt;p&gt;Take a closer look at the &#8220;recent_posts.html&#8221;. Think of how lucidly clear that file is to a web designer? There&#8217;s hardly any code! While of course no templating language can eliminate programming constructs Django&#8217;s system does a great job of only giving the template designers what they need to get the job done. The template &#8220;programming&#8221; is using its own programming language, not straight Python. There are two big reasons for this: 1) the language is meant to be simple and only provide the features needed to select or present the proper data, 2) the language doesn&#8217;t allow templates to do anything that the application should handle (e.g. a template can&#8217;t tell the database to delete itself).&lt;/p&gt;


	&lt;p&gt;Yes, my example doesn&#8217;t demonstrate how Django helps with header/footer includes, that&#8217;s coming up so be patient!&lt;/p&gt;


	&lt;h3&gt;models.py&lt;/h3&gt;


	&lt;p&gt;This is simply describing to Django how to organize the data object that we&#8217;ll be dealing with.&lt;/p&gt;


	&lt;h3&gt;urls.py&lt;/h3&gt;


	&lt;p&gt;This is routing a user&#8217;s request for the web address &#8216;recent/&#8217; (e.g. mysite.com/recent) to the recent_posts function in views.py.&lt;/p&gt;


	&lt;h3&gt;views.py&lt;/h3&gt;


	&lt;p&gt;This is the best part, take a look again:&lt;/p&gt;


&lt;pre&gt;
&lt;code&gt;
def recent_posts(request):
    post_list = Blog.objects.order_by('-blog_date')[:10]
    return render_to_response('recent_posts.html', {'post_list': post_list})
&lt;/code&gt;
&lt;/pre&gt;

	&lt;p&gt;That&#8217;s it? That&#8217;s it! Our complex &lt;span class=&quot;caps&quot;&gt;SQL&lt;/span&gt; query is now a higher level abstraction where we tell Django to tell the blog to give us the latest ten posts. Done!&lt;/p&gt;


	&lt;p&gt;Now lets look at that last piece: header/footer files.&lt;/p&gt;


	&lt;p&gt;Django does allow us to build templates that pull in header/footer includes, but it also lets us solve the common data problem with &lt;strong&gt;template inheritance&lt;/strong&gt;. With template inheritance we don&#8217;t abstract the pieces of our web pages that are the same, we pull out the pieces that are &lt;em&gt;different&lt;/em&gt;. Let me explain with a very simple webpage:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;&amp;gt;
&amp;lt;html lang=&quot;en&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;My Website&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Page Title&amp;lt;/h1&amp;gt;
    &amp;lt;p&amp;gt;Customized content!&amp;lt;/p&amp;gt;

    &amp;lt;hr&amp;gt;
    &amp;lt;p&amp;gt;This is my footer&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Done using header/footer includes:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
### header include file ###
&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;&amp;gt;
&amp;lt;html lang=&quot;en&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;My Website&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;

### footer include file ###
&amp;lt;p&amp;gt;This is my footer&amp;lt;/p&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

### custom page ###
include(header_file)

&amp;lt;h1&amp;gt;Page Title&amp;lt;/h1&amp;gt;
&amp;lt;p&amp;gt;Customized content!&amp;lt;/p&amp;gt;

include(footer_file)
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now done with Django&#8217;s template inheritence:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
### base.html ###
&amp;lt;!DOCTYPE HTML PUBLIC &quot;-//W3C//DTD HTML 4.01//EN&quot;&amp;gt;
&amp;lt;html lang=&quot;en&quot;&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;{% block title %}My Website{% endblock %}&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;{% block pagetitle %}{% endblock %}&amp;lt;/h1&amp;gt;
    {% block content %}{% endblock %}
    {% block footer %}
    &amp;lt;p&amp;gt;This is my footer.&amp;lt;/p&amp;gt;
    {% endblock %}
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;

### page.html ###
{% extends &quot;base.html&quot; %}

{% block title %}Customized Title!{% endblock %}

{% block pagetitle %}Customized page title!{% endblock %}
{% block content %}
&amp;lt;p&amp;gt;Customized content!&amp;lt;/p&amp;gt;
{% endblock %}
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;See what we did there? The parts of the page that will &lt;strong&gt;change&lt;/strong&gt; are pulled out of the base. Django&#8217;s template system lets you declare &#8220;blocks&#8221; that indicate that that part of the page &lt;em&gt;may&lt;/em&gt; change. If an extending template declares a block that matches that of the parent template, then the parent&#8217;s block is overwritten. If a block isn&#8217;t declared by the sub-page, that is in the parent page then the parent page&#8217;s block is used. Notice in our &#8220;page.html&#8221; the footer isn&#8217;t discussed at all. Django sees that we are &#8220;extending&#8221; base.html and that we haven&#8217;t specified our own footer block so it defaults to the footer block that was in base.html.&lt;/p&gt;


	&lt;p&gt;Perfect! We can create base templates that allow for child pages to overwrite &lt;strong&gt;any part that we explicitly allow&lt;/strong&gt;! No more locked headers or footers!&lt;/p&gt;


	&lt;p&gt;Templates can go through multiple levels of inheritence as well. We could easily have a base template that is then extended into &#8220;section&#8221; templates that are then extended to specific pages. With a clear and logical chain of command it is easy to see how the webpage templates work together. Much better than a couple dozen header/footer files lying around. We get all the advantages of reusing designs without the headaches!&lt;/p&gt;


	&lt;p&gt;So there you have it. Sorry for the rambling/unedited nature of this post. It&#8217;s 2:30am, I can&#8217;t sleep, but I felt like sharing.&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-01-23:185</id>
    <published>2008-01-23T02:49:00Z</published>
    <updated>2008-05-25T14:08:09Z</updated>
    <category term="learning"/>
    <category term="programming"/>
    <category term="quicklinks"/>
    <link href="http://www.xyzzyb.com/2008/1/23/django-book" rel="alternate" type="text/html"/>
    <title>Django Book</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.djangobook.com/&quot;&gt;The Django Book&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-01-07:155</id>
    <published>2008-01-07T20:26:00Z</published>
    <updated>2008-05-25T00:45:55Z</updated>
    <category term="books"/>
    <category term="programming"/>
    <category term="quicklinks"/>
    <link href="http://www.xyzzyb.com/2008/1/7/how-to-think-like-a-python-programmer" rel="alternate" type="text/html"/>
    <title>How to think like a (Python) Programmer</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.greenteapress.com/thinkpython/&quot;&gt;How to think like a (Python) Programmer&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-01-03:151</id>
    <published>2008-01-03T13:35:00Z</published>
    <updated>2008-05-25T00:44:05Z</updated>
    <category term="programming"/>
    <category term="quicklinks"/>
    <category term="science"/>
    <link href="http://www.xyzzyb.com/2008/1/3/dna-as-code" rel="alternate" type="text/html"/>
    <title>DNA as Code</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://ds9a.nl/amazing-dna/index.html&quot;&gt;&lt;span class=&quot;caps&quot;&gt;DNA&lt;/span&gt; interpreted as sourcecode&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.xyzzyb.com/">
    <author>
      <name>stephen</name>
    </author>
    <id>tag:www.xyzzyb.com,2008-01-02:150</id>
    <published>2008-01-02T14:25:00Z</published>
    <updated>2008-05-25T00:43:49Z</updated>
    <category term="programming"/>
    <category term="quicklinks"/>
    <link href="http://www.xyzzyb.com/2008/1/2/programming-for-the-xo" rel="alternate" type="text/html"/>
    <title>Programming for the XO</title>
<content type="html">
            &lt;p&gt;&lt;a href=&quot;http://www.ibm.com/developerworks/linux/edu/l-dw-linux-xo-python-i.html?ca=dgr-lnxw01OLPCAppDev&quot; title=&quot;OLPC laptop&quot;&gt;application development for the XO&lt;/a&gt;&lt;/p&gt;
          </content>  </entry>
</feed>
