<?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>{ Code: Impossible } &#187; code-style</title>
	<atom:link href="http://codeimpossible.com/tag/code-style/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeimpossible.com</link>
	<description>this = HowI.Roll();</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:58:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Comments stink!</title>
		<link>http://codeimpossible.com/2010/07/16/comments-stink/</link>
		<comments>http://codeimpossible.com/2010/07/16/comments-stink/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 05:28:26 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[opinionated]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=619</guid>
		<description><![CDATA[I&#8217;ve been thinking about the whole Comments-as-a-code-smell argument for a very long time. When I first heard this idea, I was in the comments are definitely needed side of the argument.
&#8220;Who could hate comments so much that they would label them as a code smell?&#8221; I thought.
Well, I had an epiphany the other day.
I&#8217;ve never [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking about the whole <a href="http://memeagora.blogspot.com/2008/11/comments-code-smell.html" target="_blank">Comments-as-a-code-smell argument</a> for a very long time. When I first heard this idea, I was in the comments are definitely needed side of the argument.</p>
<p><em>&#8220;Who could hate comments so much that they would label them as a code smell?&#8221;</em> I thought.</p>
<p>Well, I had an epiphany the other day.</p>
<p><strong>I&#8217;ve never seen a block of code that actually needed a comment. Ever.</strong></p>
<p>If you have a section of code that feels too complex, instead of adding a comment do any/all of the following and you can, in almost every case, reduce the need for comments by 100%:</p>
<ol>
<li>add a sourcecontrol commit comment</li>
<li>do a simple refactor (<a href="http://www.industriallogic.com/xp/refactoring/composeMethod.html" target="_blank">Compose Method</a> ftw people),</li>
<li>use more descriptive variable/function/class/whatever names.</li>
</ol>
<p>If you do all of these things and the code you are working on still seems too complex, you may have bigger problems with your overall architecture/design and adding a comment isn&#8217;t going to help. In this case it&#8217;s time to go back to the drawing board.</p>
<p>Also, everytime you commit a changeset into sourcecontrol that contains a section of code commented out god kills a kitten. Please think of the kittens.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/07/16/comments-stink/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Solving &#8220;$(document).ready is not a function&#8221; and other problems</title>
		<link>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/</link>
		<comments>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 01:29:29 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=767</guid>
		<description><![CDATA[Has this ever happened to you: you&#8217;ve been working on a customer&#8217;s site, writing some really awesome jQuery flashy, fadey, scrolly, interactivey thing, you deploy it, and everything is awesome. The customer rejoices and the customer&#8217;s customers rejoice. Rejoicing is had by everyone. 
And then you get an email one day:

&#8220;Everything is broken. We&#8217;ve kidnapped [...]]]></description>
			<content:encoded><![CDATA[<p>Has this ever happened to you: you&#8217;ve been working on a customer&#8217;s site, writing some really awesome jQuery flashy, fadey, scrolly, interactivey thing, you deploy it, and everything is awesome. The customer rejoices and the customer&#8217;s customers rejoice. Rejoicing is had by everyone. </p>
<p>And then you get an email one day:</p>
<blockquote><p>
&#8220;Everything is broken. We&#8217;ve kidnapped your dog. Fix our site or you&#8217;ll never see Spartacus again.&#8221;</p></blockquote>
<p>And before you have time to wonder why you ever named your dog &#8220;Spartacus&#8221; to begin with (i mean <strong>come. on.</strong>), you&#8217;re off in debug hell. You load the site and see all sorts of weird errors:</p>
<p><code>“$().ready is not a function”</code></p>
<p><code>“$(document) doesn’t support this property or method”</code></p>
<p>Or my personal favorite: </p>
<p><code>“null is null or not an object”</code></p>
<p>You open up FireFox, activate FireBug, load the console, and type “alert($)”, press run, and instead of seeing the expected jQuery function:</p>
<pre class="prettyprint"><code>
function (E, F) {
    return new (o.fn.init)(E, F);
}
</code></pre>
<p>You instead get:</p>
<pre class="prettyprint"><code>
function $(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++) {
            elements.push($(arguments[i]));
        }
        return elements;
    }
    if (Object.isString(element)) {
        element = document.getElementById(element);
    }
    return Element.extend(element);
}
</code></pre>
<p>Or even:</p>
<pre class="prettyprint"><code>
function $(id) {
    return document.getElementById(id);
}
</code></pre>
<p><strong>DOH!</strong> Looks like another javascript library has been loaded and has overwritten the <code>$()</code> shortcut for jQuery. Woe is I. Why can’t we all just get along?!? </p>
<p>Well, we can’t stop people from including their favorite javascript libraries, but what we can do is prevent our code from suffering as a result. We’ll need a nice, big beefy, bodyguard to make sure our code isn’t messed with while it’s out clubbing with Prototype, Scriptaculous or even MooTools (who invited <em>him</em>??!?).</p>
<p>Here’s what our bodyguard function will look like</p>
<pre class="prettyprint"><code>
( function($) {

} ) ( jQuery );
</code></pre>
<p>So what this does is call our anonymous function and pass the <code>jQuery</code> object. This will scope ‘$’ to within our little function so we won’t step on anyone else’s toes (and they won’t bump into us while we’re on the dance floor and spill our drink everywhere). Okay, I think I've taken the clubbing metaphor far enough.</p>
<p>Basically this will allow our code to run and use the <code>$</code> shortcut for JQuery as if it were loaded without any of these other libraries on the page. </p>
<p>Here is what the completed code would look like:</p>
<pre class="prettyprint"><code>
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"&gt;
&lt;/script&gt;

&lt;script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript">
&lt;/script&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js" type="text/javascript">
&lt;/script&gt;

&lt;script type="text/javascript"&gt;
( function($) {
    // we can now rely on $ within the safety of our “bodyguard” function
    $(document).ready( function() { alert("nyah nyah! I’m able to use '$'!!!!");  } );
} ) ( jQuery );

//this will fail
$(document).ready( function() { alert('fail?'); } );
&lt;/script&gt;
</code></pre>
<p>I love using this simple self-calling anonymous function style when working with jQuery because it saves me from typing <code>jQuery()</code>, which really does look a lot more ugly than using the <code>$()</code> shortcut. It also protects my code from any scoping issues and lets the code function normally when <a href="http://docs.jquery.com/Core/jQuery.noConflict">jQuery is put into no conflict mode</a>. </p>
<p>My opinion, if you're doing work in jQuery on sites that you don't control 100%, you should be using this method to protect your code and your clients.</p>
<p><strong>Updated: changed link for jquery to use 1.4.1 at the google CDN (tsk, tsk, tsk I was using the googlecode.com link)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Code comments = respect</title>
		<link>http://codeimpossible.com/2008/07/22/code-comments-equal-respect/</link>
		<comments>http://codeimpossible.com/2008/07/22/code-comments-equal-respect/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 03:41:37 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code-comments]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://pistalwhipped.wordpress.com/?p=198</guid>
		<description><![CDATA[I was browsing around Code Project the other day, I subscribe to their most recent submissions feed to watch for interesting samples, and I saw a unique take on a logging system.
It used IL replacement, much like TypeMock Isolator, to allow developers to enable/disable the logger without having to compile any code.
In theory, I haven&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I was browsing around Code Project the other day, I subscribe to their most recent submissions feed to watch for interesting samples, and I saw a unique take on a logging system.</p>
<p>It used IL replacement, much like TypeMock Isolator, to allow developers to enable/disable the logger without having to compile any code.</p>
<p>In theory, I haven&#8217;t tried it out yet, you would be able to add this logging system to any project without coding anything.</p>
<p>I downloaded the code and it&#8217;s huge. 5 assemblies, over 2000 lines and there is some COM stuff in there. I notice two things. First it&#8217;s all in c++. This is not a bad thing it&#8217;s just not my first language.</p>
<p>So I start looking around for some comments to let me know what the heck is going on in this code.</p>
<p>Annnnnnd&#8230; hmmmm thats odd.</p>
<p>There are <strong>no</strong> comments. Not one. I checked the author notes on the original submission article to see if this was an error and there was an updated link.</p>
<p>Nope. Nothing. It takes me a minute but near the bottom of the post I see why there are no comments.</p>
<p>The author writes:</p>
<blockquote><p>&#8220;I like to think I write self-documenting code so I tend to not have any comments in my code.&#8221;</p></blockquote>
<p>I instantly deleted the code from my system. My thought is if the author of this code didn&#8217;t think it was worthy of some kind of explanation then I am certainly not going to waste my time with it.</p>
<p>Comments aren&#8217;t just some &#8220;nice to have&#8221; thing. They show that you actually care about what you are putting out there and they show your thought process throughout the codes execution. If you don&#8217;t care about that then why would I?</p>
<p>I&#8217;m not saying that every line, function call and variable needs a comment but any programmer worth his salt should put some form of documentation into his/her code. It&#8217;s a sign of respect.</p>
<p>So my fellow developers let&#8217;s respect each other enough to document what we put out into the world. What do you say?</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2008/07/22/code-comments-equal-respect/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
