<?xml version="1.0" encoding="UTF-8" ?>
					<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
					<channel>
                                        <atom:link href="http://nathansweet.me/subscribe" rel="self" type="application/rss+xml" />
					<title>Nathan Sweet's Thoughts on Coding and the Coding-Life</title>
					<description>Syndication feed for thoughts on JavaScript, php, and more...</description>
					<language>en-us</language>
					<copyright>Copyright (C) 2015 nathansweet.me</copyright>
					<link>http://nathansweet.me/subscribe</link>
					<lastBuildDate>Sat, 17 Oct 2015 19:57:44 PDT</lastBuildDate>
		<pubDate>Sat, 27 Oct 2012 18:08:51 PDT</pubDate>
			<item>
			<title>RestComplete Tutorial</title>
			<description> <![CDATA[ <iframe src="http://player.vimeo.com/video/52297886?badge=0" width="500" height="281" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> ]]></description>
			<link>http://nathansweet.me/restcomplete-tutorial</link>
			<guid isPermaLink="true">http://nathansweet.me/restcomplete-tutorial</guid>
			<pubDate>Sat, 27 Oct 2012 18:08:51 PDT</pubDate>
			</item>
			
			<item>
			<title>JavaScript for Node JS I</title>
			<description> <![CDATA[ <p><span class="first-letter">I</span>'m going to alternate between articles on Node and my selector engine series. Not to worry dear reader, part two of the continuing selector engine saga will continue shortly, but I thought I would address something that's been bothering me. It seems to me that Node JS is going to revolutionize web application development once it hits 1.0. My main reason for thinking this (aside from the limited technical information I'm able to grasp) is that a lot of smart people say it will. I know that <a href="http://teddziuba.com/2011/10/node-js-is-cancer.html" target="_blank">some people</a> have railed against it for certain reasons, but the reasons they suggest seem hallow to me, especially the computational one. If you are getting your framework to do continuous computations of your data as it receives it from its database than you're doing something wrong, Hadoop was invented because of this problem. Node is an I/O handler not a computational maven. That being said, it seems to me that there are two groups of people programming for Node right now. Those who know JavaScript very well and are just starting to beef up there server-side chops, and those who know the server very well and are excited about Node (for things like the non-blocking event loop, and yes I have accepted epoll into my heart, etc) and are just embarking upon their JavaScript journey. Both groups have one very similar disadvantage, they both have or will have bad JavaScript prejudices built up around a JavaScript programming paradigm that has been the result of its use in the most torn up API landscape in computer science history: the Browser.</p>
<p>JavaScript programming best practices have been built up around a very feckless set of APIs. When programming for "the Browser", you're not just programming for one API (in theory you are), you are actually programming for many that look somewhat similar. This model of hack and burn programming works well for the Browser and has produced some of the most imaginative and ingenious code ever created. However, this model and paradigm of JavaScript programming is inherently broken when approaching a coherent and unified API like Node JS.</p>
<p>Where before in JavaScript you had to worry about clobbering global variables because your page might use a mash-up one day, Node JS does not have this problem. Where before you had to prioritize what methods you could use, because one fo them might not work in IE (think Array.prototype.indexOf), Node JS provides relief. I am here to tell you boys and girls, that the days of downloading your favorite JavaScript library to make your API work as intended are a bygone thing in Node! I am excited to see the code that gets produced because of Node, because I think it will be JavaScript as the good Lord intended it to be. That being said I am going to do a small series bashing old browser JavaScript patterns that are no longer necessary, and in fact are quite bad, for Node JS. Starting with the "for...in" statement.</p>
<p>"For...in" is an, almost, unnecessary statement when using Node. In the past/browser you would often have to loop through an object like so:</p>
<pre class="brush: js">
    var key;
    for(key in obj){
        if(obj.hasOwnProperty(key)){
            obj[key];
            //your code sir.
        }
    }
</pre>
<p>In Node JS, this would be much slower than the new hotness available to you in ES5:</p>

<pre class="brush: js">
    var keys = Object.keys(obj),
        l = keys.length,
        i = 0;
        while(i < l){
            obj[keys[i]];
            //Your code ma'am.
        }
</pre>
<p>This <a href="http://jsperf.com/object-keys-vs-hasownproperty" target="_blank">jsPerf example</a> shows just how much faster using Object.keys really is. Now you might be crying foul right now for a couple of reasons. The first being how can I compare Node JS performance to a set of browser benchmarks on jsPerf. My answer: V8, check the Chrome stats and you'll get a reasonable idea. The second is that the "For...in" statement isn't obsolete, especially if we are looking to enter an object's prototype chain. My answer: fair enough. "For...in" is still the only way to traverse up an object's prototype chain and get its first tier values at the same time. However, using Object.keys on an object's prototype would work perfectly fine as well, so there are <i>a few</i> instances when going up the prototype chain with "For...in" might be a bad call in Node. If anybody else has some cool ideas on JavaScript that would work well in Node, that was previously a pariah in the browser-world, please leave it in the comments. Never fear though, I have more thoughts on this topic.</p> ]]></description>
			<link>http://nathansweet.me/nodejs-best-practices-part-1</link>
			<guid isPermaLink="true">http://nathansweet.me/nodejs-best-practices-part-1</guid>
			<pubDate>Sat, 08 Oct 2011 09:55:50 PDT</pubDate>
			</item>
			</channel>
			</rss>