<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description></description><title>"fallenrogue" Under Leon's hat.</title><generator>Tumblr (3.0; @fallenrogue)</generator><link>http://fallenrogue.com/</link><item><title>Kickstarter - Theater Town: A Documentary about a High School Reunion Show 60 years in the Making.</title><description>&lt;a href="http://kck.st/azYgAQ"&gt;Kickstarter - Theater Town: A Documentary about a High School Reunion Show 60 years in the Making.&lt;/a&gt;: &lt;p&gt;Mitch’s documentary looks amazing. I can’t wait to see how it comes out!&lt;/p&gt;</description><link>http://fallenrogue.com/post/761782517</link><guid>http://fallenrogue.com/post/761782517</guid><pubDate>Fri, 02 Jul 2010 10:59:48 -0400</pubDate></item><item><title>ftw</title><description>&lt;a href="http://www.atomicwang.org/motherfucker/Index/Entries/2010/6/24_What_money_can_buy.html"&gt;ftw&lt;/a&gt;</description><link>http://fallenrogue.com/post/739222616</link><guid>http://fallenrogue.com/post/739222616</guid><pubDate>Sat, 26 Jun 2010 15:35:04 -0400</pubDate></item><item><title>On Code etc.: 0 to application in a day, with Ocsigen/OCaml.</title><description>&lt;a href="http://blog.dbpatterson.com/post/551110039/0-to-application-in-a-day-with-ocsigen-ocaml"&gt;On Code etc.: 0 to application in a day, with Ocsigen/OCaml.&lt;/a&gt;: &lt;p&gt;I just saw this today and loved it. Enjoy.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://rubyonrails.org/" target="_blank"&gt;Web&lt;/a&gt; &lt;a href="http://www.djangoproject.com/" target="_blank"&gt;frameworks&lt;/a&gt; &lt;a href="http://happstack.com/" target="_blank"&gt;are&lt;/a&gt; &lt;a href="http://erlyweb.org/" target="_blank"&gt;a&lt;/a&gt; &lt;a href="http://www.seaside.st/" target="_blank"&gt;dime&lt;/a&gt; &lt;a href="http://cappuccino.org/" target="_blank"&gt;a&lt;/a&gt; &lt;a href="http://cakephp.org/" target="_blank"&gt;dozen&lt;/a&gt; these days, and they all promise to deliver enormous productivity boosts without limiting your creativity. The darker side of it is that while they often allow you to create applications very quickly, sometimes they make it pretty hard to…&lt;/p&gt;
&lt;/blockquote&gt;</description><link>http://fallenrogue.com/post/568126613</link><guid>http://fallenrogue.com/post/568126613</guid><pubDate>Mon, 03 May 2010 08:44:42 -0400</pubDate></item><item><title>Photo</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_l0bw7ohT4B1qz534vo1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;</description><link>http://fallenrogue.com/post/494512948</link><guid>http://fallenrogue.com/post/494512948</guid><pubDate>Sat, 03 Apr 2010 21:30:51 -0400</pubDate></item><item><title>Photo</title><description>&lt;img src="http://25.media.tumblr.com/tumblr_l0bvs3BXvK1qz534vo1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;</description><link>http://fallenrogue.com/post/494495729</link><guid>http://fallenrogue.com/post/494495729</guid><pubDate>Sat, 03 Apr 2010 21:21:31 -0400</pubDate></item><item><title>Marc Peabody is a lifetime member in the awesome hall of fame....</title><description>&lt;img src="http://24.media.tumblr.com/tumblr_l0bv5qLixt1qz534vo1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;Marc Peabody is a lifetime member in the awesome hall of fame. That is all.&lt;/p&gt;</description><link>http://fallenrogue.com/post/494470906</link><guid>http://fallenrogue.com/post/494470906</guid><pubDate>Sat, 03 Apr 2010 21:08:06 -0400</pubDate></item><item><title>This just in: Nerds are Mad at the iPad!!!! </title><description>&lt;p&gt;I love how a device that no one has really used has caused such a rift in the geek/nerd/tech/yawn universe. So, I’m going to weigh in…. &lt;/p&gt;

&lt;p&gt;I remember when Apple came out with the Macbook Air and nerds were up in arms over that because of the price. It was under powered by their stupid, nonsensical standards. You know what happened? People who travel a lot and need a computer that allows them to get things done (email, documents, presentations, etc) while traveling on a plane or a subway or whatever. Guess what happened? They loved it and geeks didn’t buy one. You also forgot about it the next time another machine was added to the Macbook Pro line. Because __that__ machine was for you. &lt;/p&gt;

&lt;p&gt;Not every user experience has to be a ubiquitous homogenized one. People are heralding iPad as things like a Kindle killer. Nope, you’re wrong again. If sales go down, they’ll drop the price. If no one buys it they’ll devote more time into building apps for iPad or the subsequent Google Android Tablets that are bound to pop up in the next year or two. &lt;/p&gt;

&lt;p&gt;So, if you’re interested in one, buy one. If you’re not, then don’t. If more people like them than don’t then they’ll go the way of the Newton. If not, then get a Macbook and start hacking away at apps for it and fleece the millions of iPhone, iPod and iPad users out there who actually are interested in the device. &lt;/p&gt;

&lt;p&gt;Oh yeah, and no one, __NO ONE__ has ever, __EVER__ said that the iPad was the end all be all of the future of computing, because that would be hyperbolic. IF you’re worried about your kid _not_ getting into computing because you only own an iPad, then buy that little hacker a mac mini and give them room to run. But stop with the whiny conjecture and hyperbolic punditry. I’m over it.&lt;/p&gt;

&lt;p&gt;DISCLAIMER: I’ve been programming for years. Frankly, a computer that my parents can use without calling me for tech support every week has me pretty excited. &lt;/p&gt;

&lt;p&gt;Me? Waiting to play with it but am very intrigued.&lt;/p&gt;</description><link>http://fallenrogue.com/post/492094765</link><guid>http://fallenrogue.com/post/492094765</guid><pubDate>Fri, 02 Apr 2010 20:12:11 -0400</pubDate></item><item><title>Anti Patterns Catalog</title><description>&lt;p&gt;&lt;a href="http://c2.com/cgi/wiki?AntiPatternsCatalog"&gt;Anti Patterns Catalog&lt;/a&gt;: ” Anti Patterns Catalog

‘Catalog’ is a technical term in the PatternCommunity: a list of patterns is called a catalog. This catalog lists AntiPatterns.
AbstractionInversion
AccidentalComplexity
AccidentalInclusion
AcmePattern
AlcoholFueledDevelopment
AmbiguousViewpoint
AnalogyBreakdownAntiPattern
AnalysisParalysis
AnAthena
AnchoredHelper?
AppointedTeam
ArchitectsDontCode
ArchitectureAsRequirements
ArchitectureByImplication
AsynchronousUnitTesting
AutogeneratedStovepipeAntiPattern
BearTrap
BigBallOfMud
BlameStorming
BlowhardJamboree
BoatAnchor
CargoCult
CascadingDialogBoxesAntiPattern
ConfigurationAbomination?
ContinuousObsolescence
ControlFreak
CornCob
CoverYourAssets
CreepingFeaturitis
CrciCards
CopyAndPasteProgramming
DeadEnd
DeathByPlanning
DecisionByArithmetic
DesignByCommittee
DesignForTheSakeOfDesign.
DiscordantRewardMechanisms
DoerAndKnower
DryWaterhole
EgalitarianCompensation
EmailIsDangerous
EmperorsNewClothes
EmpireBuilding
ExceptionFunnel
FalseEconomy
FalseSurrogateEndpoint
“&lt;/p&gt;

&lt;p&gt;(Via &lt;a href="http://"&gt;&lt;/a&gt;.)&lt;/p&gt;</description><link>http://fallenrogue.com/post/454835934</link><guid>http://fallenrogue.com/post/454835934</guid><pubDate>Wed, 17 Mar 2010 14:28:05 -0400</pubDate></item><item><title>mnmal:


designeriphone:

“Good design means never having to say...</title><description>&lt;img src="http://30.media.tumblr.com/tumblr_kwgteohiSm1qahc9uo1_400.png"/&gt;&lt;br/&gt;&lt;br/&gt;&lt;p&gt;&lt;a href="http://mnmal.tumblr.com/post/438815483/designeriphone-good-design-means-never-having" class="tumblr_blog"&gt;mnmal&lt;/a&gt;:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="http://designeriphone.tumblr.com/post/348146742/good-design-means-never-having-to-say-click"&gt;designeriphone&lt;/a&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;“Good design means never having to say “Click Here”.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;</description><link>http://fallenrogue.com/post/439007809</link><guid>http://fallenrogue.com/post/439007809</guid><pubDate>Wed, 10 Mar 2010 08:57:26 -0500</pubDate></item><item><title>Photo</title><description>&lt;img src="http://30.media.tumblr.com/tumblr_kywbv3HrUi1qz534vo1_500.jpg"/&gt;&lt;br/&gt;&lt;br/&gt;</description><link>http://fallenrogue.com/post/431706808</link><guid>http://fallenrogue.com/post/431706808</guid><pubDate>Sun, 07 Mar 2010 00:13:48 -0500</pubDate></item><item><title>Sooooooooooo tired. And bored.  Gnoght.</title><description>&lt;p&gt;Sooooooooooo tired. And bored.  Gnoght.&lt;/p&gt;</description><link>http://fallenrogue.com/post/431705616</link><guid>http://fallenrogue.com/post/431705616</guid><pubDate>Sun, 07 Mar 2010 00:13:12 -0500</pubDate></item><item><title>"You have enemies? Good. That means you’ve stood up for something, sometime in your life."</title><description>&lt;p&gt;‘You have enemies? Good. That means you’ve stood up for something, sometime in your life.’&lt;/p&gt;

&lt;p&gt;- Winston Churchill&lt;/p&gt;

&lt;p&gt;(Via &lt;a href="http://mnmal.tumblr.com/"&gt;Minimal&lt;/a&gt;.)&lt;/p&gt;</description><link>http://fallenrogue.com/post/349835224</link><guid>http://fallenrogue.com/post/349835224</guid><pubDate>Sat, 23 Jan 2010 20:13:49 -0500</pubDate></item><item><title>The CodeMash Precompiler Part 0</title><description>&lt;p&gt;I’ve had several interested friends ask about “how the precompiler” went. As the acting Iteration Manager I can say that it exceeded my every expectation but what does that “mean”. Well I’m going to be compiling the information that was collected from the event and putting it into a case study for a team of 50 developers, whom only half of which were familiar with the tools and process methodology, working from scratch on an application. &lt;/p&gt;

&lt;p&gt;What did we learn? &lt;/p&gt;

&lt;p&gt;What did we succeed at? &lt;/p&gt;

&lt;p&gt;What did we fail at? &lt;/p&gt;

&lt;p&gt;Those at the retrospective probably know some of those answers because we discussed them as a group and I made notes about how I may present this workshop in the future. (possibly at CodeMash again next year?) &lt;/p&gt;

&lt;p&gt;But I wanted to let everyone know that we did complete most of the app to make it fully functional. In fact, in the afternoon we were already looking to refactor the architecture of the application and that is where it is right now. So, Cory Flanigan’s group at set out to do just that. Cory and I will seek to complete the touches and push out to &lt;a href="http://symposiast.com"&gt;http://symposiast.com&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;So, stay tuned and if you’re interested in seeing where we ended up check out the code that was committed and merged into master at &lt;a href="http://github.com/fallenrogue/CodeMash-2010-Precompiler-Application."&gt;http://github.com/fallenrogue/CodeMash-2010-Precompiler-Application.&lt;/a&gt;&lt;/p&gt;</description><link>http://fallenrogue.com/post/339398651</link><guid>http://fallenrogue.com/post/339398651</guid><pubDate>Sun, 17 Jan 2010 12:55:49 -0500</pubDate></item><item><title>iPhone and Android Development - NOT STARTING A FLAME WAR!!!! </title><description>&lt;p&gt;Perception is truly reality. The way we see the world shapes how we look to solve problems. It’s with that grain of salt that I offer up this response to Mr. @JonathanPenn’s tweet to substantiate my claims on the interwebs this morning. Boy, I hate getting into these messes but he’s right to call me out and clarify. Here’s our convo:&lt;/p&gt;

&lt;p&gt;&lt;img src="http://grab.by/1qkY" alt="Our Tweet Convo!"/&gt;&lt;/p&gt;

&lt;p&gt;With that history you must know that I spent years in .NET and C# so Java is going to seem like second nature to my eyes; rather than, say, a C++ programmer who will, likely, see something familiar in Apple’s Cocoa/Obj-C environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;That said&lt;/strong&gt;, my comment takes the following into consideration…&lt;/p&gt;

&lt;p&gt;Java is dominant right now &lt;a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html"&gt;(stats!)&lt;/a&gt;. In the Enterprise, they’ve got a pretty large hold on the development community and love it or hate it, that lowers the barrier of entry to developing on Android. Most Java developers will be immediately comfortable with the conventions laid out in Android’s development cycle and given there’s an exceptional Eclipse plugin for Android development Java developers don’t need to learn much more than Android’s specifics in their own language, IDE and platform of choice.&lt;/p&gt;

&lt;p&gt;There’s a mountain of Java tutorials available. Even if you’re new to Java you’re going to be hard pressed to miss out on the latest and greatest information that the platform has to offer. My searches for information on Cocoa development have met with wildly differing opinions and little consensus. In fact, I was in the C based API on my sample app to play/manage sounds until Jon mentioned there was an Objective-C based API that could do the same thing. Even Apple’s documentation was wishy-washy on the subject until I took the time to read the Cocoa Touch programming guide for Audio (not a fun read, BTW) that it even mentioned the class Jon pointed out.&lt;/p&gt;

&lt;p&gt;On a 1-1 basis Android’s frameworks seem to be providing developers simple abstractions to every possible task that you’re going to want to perform on the device while Apple’s Cocoa Touch frameworks seem to be a mess of improvements over Cocoa, missing abstractions and idioms are published by Apple and not driven by the community using them. AGAIN- that is conjecture but that’s what I’m seeing.&lt;/p&gt;

&lt;p&gt;Take, for instance, the following snippets to load an internal sound file reference and play it. First iPhone -&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;NSString *soundFilePath =
    [[NSBundle mainBundle] pathForResource: sound
                                    ofType: theType];

NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: soundFilePath];

AVAudioPlayer *newPlayer =
    [[AVAudioPlayer alloc] initWithContentsOfURL: fileURL
                                           error: nil];


[newPlayer prepareToPlay];
[newPlayer setDelegate: self];
[newPlayer play];
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;See, it’s not complex. The syntax is simple enough (for the AVAudioPlayer class, this is &lt;em&gt;not&lt;/em&gt; the C API which is &lt;strong&gt;far&lt;/strong&gt; more complex) but things like getting a reference to an internal URI is 2 lines of chunky code that create references that I need to track now. &lt;strong&gt;It’s not bad, but there should be a simple way to load our references.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let’s compare that snippet with the Android version.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;MediaPlayer mp = MediaPlayer.create(this, R.raw.mySoundFile);
mp.start();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;That’s it. I’m not splitting hairs over brevity; that’s not the point, the point is that the abstraction seems to be in the right place. We &lt;em&gt;know&lt;/em&gt; we’re going to play sounds on a device. We &lt;em&gt;know&lt;/em&gt; that those sounds are going to be local or networked. These are clear points of abstraction in OO and should be provided to the developer (IMHO).&lt;/p&gt;

&lt;p&gt;From my perspective I get to tell the right objects to do what I want them to do and the details and minutia are encapsulated behind a nice API. If we’re on the same topic here are 2 equally good APIs first from iPhone and then from Android&lt;/p&gt;

&lt;h3&gt;Taking a photo with iPhone (in main.m)&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

// cruft leading to our delegate implementation...
-(void)imagePickerController: (UIImagePickerController *)picker didFinishPickingImage(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
    // now I have image reference I can use! Sweet! 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;See, there’s an operation that I &lt;em&gt;know&lt;/em&gt; I’m going to need to perform on a phone equipped with a camera. Once you’re familiar with cocoa’s delegate/callback system then doing something with the camera is that simple. But still, I’m interfacing with a Controller object and not the Camera or “media” object. From an MVC perspective Apple’s controllers seem pretty heavy and try as I may there’s something icky. The Abstraction is there, though which is my complaint with many of the other functions I’d expect an always connected device to abstract. Let’s look at Android’s API for doing the same thing.&lt;/p&gt;

&lt;h3&gt;Taking a photo with Android&lt;/h3&gt;

&lt;pre&gt;&lt;code&gt;Camera camera = Camera.open();
camera.takePicture(null, null, new PictureCallback(){
    public void onPictureTaken(byte[] _data, Camera _camera){
        //Handle the photo
    }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, lines of code aside they’re very similar but the Android object API is clear and uses the same idioms it has established with other objects in the system. There’s no muddy “is it a Controller or Model” confusion. To me, that’s an simple OO encapsulation that provides an intuitive API. AGAIN: my eyes, my perspective and my opinion.&lt;/p&gt;

&lt;p&gt;For the last few points, before I go back to exploring both of these &lt;strong&gt;GREAT&lt;/strong&gt; platforms. Things that have me more interested in Android at this moment than iPhone…&lt;/p&gt;

&lt;p&gt;1: &lt;strong&gt;Android is open&lt;/strong&gt;. Which means there’s a greater chance that your app will be seen on a diverse set of devices. This is a blessing and a curse. You’ll be required to handle such discrepancies but again, Google seems to have abstracted those decisions into small questions you can ask the platform in one method. But you &lt;strong&gt;will&lt;/strong&gt; have to be concerned about it and I can see a legion of experts born from this very issue. Good knew is you can sell or give away your apps on your terms. Not Apple’s.&lt;/p&gt;

&lt;p&gt;2: &lt;strong&gt;Testing&lt;/strong&gt;. Java has better support for current BDD/TDD methodologies. I’m going to state conjecture as fact here. I can’t find a great BDD framework for Obj-C and who cares if I can’t use it well in cases where I’m testing C code.&lt;/p&gt;

&lt;p&gt;3: &lt;strong&gt;Memory Management is a solved problem&lt;/strong&gt;. Google knows it, you know it. the C champions will always lay claim that Garbage Collection is slower than their own hand crafted memory management techniques and that may, in fact, be true. But by what degree? What about line of business application developers? They know the value of one less thing to worry about; one less thing that can go wrong. I know obj-C 2 has an opt-in GC but I never see it in use on the iPhone and I’m not sure why. I assumed it wasn’t supported, again, someone please let me know in the comments if this is wrong.&lt;/p&gt;

&lt;h2&gt;In the end, everything is perspective&lt;/h2&gt;

&lt;p&gt;As one who primarily has developed line of business applications and the bulk of that on the .NET platform or in Ruby, Google’s Android platform seems directly poised at the GTD crowd and Apple’s iPhone seems hell bent on restoring C++ and it’s superset Obj-C to the forefront of Alpha-Geekdom. Both are great approaches but when you couple the innovation coming out of the Android devices, the open source ease of startup, tooling support and articulate APIs; Apple needs to continue to innovate on the development side as well as the consumer side.&lt;/p&gt;

&lt;p&gt;Apple is, hands down, the reason we’re even interested in this comparison. I love my iPhone. I’m certainly not giving up on my goal of getting in the App Store with something, ANYTHING. But I must say, if they are not cognizant of the power that Google is providing developers they may see folks piloting, prototyping and promoting Android over the iPhone.&lt;/p&gt;

&lt;p&gt;I don’t know if it’s time for the Cocoa community to build a better boat or Apple’s but somehow, to me, that’s yet another solved problem and therefore another win for Android.&lt;/p&gt;

&lt;p&gt;OK, Jon. I await your post clarifying all of this up for me on the iPhone side and even better, I CANT WAIT to pair with you on iPhone fun at CodeMash! ;)&lt;/p&gt;</description><link>http://fallenrogue.com/post/304905380</link><guid>http://fallenrogue.com/post/304905380</guid><pubDate>Mon, 28 Dec 2009 15:56:32 -0500</pubDate></item><item><title>Lessons from Uncle Bob</title><description>&lt;p&gt;Those of you who were fortunate enough to hear Uncle Bob Martin speak at Columbus Ruby Brigade last Monday are aware of the amount of wisdom that can be garnered from listening to him. If that is the case then certainly pair programming with him for the day would be equally enlightening.&lt;/p&gt;

&lt;p&gt;Monday morning when I walked into the EdgeCase offices there in a corner was a face that I was familiar with but had never met personally. This is not unfamiliar for me, I’m usually the last person to know anyone with a reputation that precedes them. I say hello and introduce myself but as he was already pairing with our friend Adam I said hi, got a Mountain Dew out of the fridge, found a seat in the bullpen and got down to the business.&lt;/p&gt;

&lt;p&gt;10 minutes into the day Adam has something else that has to be done for a client so we look around and Ken says: “Leon why don’t you pair with Uncle Bob on a few features”&lt;/p&gt;

&lt;p&gt;I don’t know the app.&lt;/p&gt;

&lt;p&gt;I don’t know what were working on.&lt;/p&gt;

&lt;p&gt;I run to sit next to Uncle Bob.&lt;/p&gt;

&lt;p&gt;I don’t care what we’re working on, there’s no way that I’m going to impress a man who’s literally been there and done that so it was time to sponge. Or at least I thought. Over the next 5 hours we meticulously poured over the details of what I would perceive as a simple feature to understand not just what the feature is but why we couldn’t test the particular abstraction. Uncle Bob was interested in seeing how we could test a haml view in isolation of the rest of the app and frankly I was fascinated. We were looking over APIs and playing around with how to mock state for our view just so we could ensure that numbers that were currency would be properly set to 2 decimal places.&lt;/p&gt;

&lt;p&gt;You see, it was not that the task was simple or complex, the task was not important. What was important was how we were planning to &lt;strong&gt;work on&lt;/strong&gt; the task. How were we going to cleanly isolate the functionality so that we could simply test and verify that we had, in fact, completed the task. In the end, we didn’t quite isolate the view in the way that he (and eventually I) wanted but we completed the task and Uncle Bob was clearly amused by the session that day and, as I hope, he seemed to have fun pairing with me as we ran down the rabbit hole, exploring the possibilities of our API and expanding my concept of what it means to be testable.&lt;/p&gt;

&lt;p&gt;It’s difficult to communicate wisdom transferred; it’s difficult to work next to someone whom you’ve respected from a far for so long and package the experience in 500 words or so and I hope that I’ve been able to capture a bit of it. While I may not communicate it well now, know that it was a great experience, one that I hope to replicate again and again as I seek to improve how I approach my craft and evolve my understanding of the profession I’m in.&lt;/p&gt;

&lt;p&gt;Thanks Uncle Bob for the great day of code! I had a blast!&lt;/p&gt;</description><link>http://fallenrogue.com/post/296832517</link><guid>http://fallenrogue.com/post/296832517</guid><pubDate>Wed, 23 Dec 2009 09:28:18 -0500</pubDate></item><item><title>JavaScript Part 5 - The Client Side</title><description>&lt;p&gt;So, if JavaScript ever really had a true intention, I believe that intention was to bring static HTML documents to life. I’m sure if we read the history since 1995 (give or take a year) then we’ll notice that most work with JavaScript was aimed at giving the static web a much needed shot in the arm.&lt;/p&gt;

&lt;p&gt;To understand how JavaScript works its magic we have to dive into the DOM or Document Object Model and it’s relationship to the document being rendered to the client.&lt;/p&gt;

&lt;h3&gt;DOM: The Document Object Model&lt;/h3&gt;

&lt;p&gt;At the top of the stack we have the object that does the presenting to the user: The Window aka The browser. This is represented as the &lt;strong&gt;Window&lt;/strong&gt; object. A window is presenting one document at a time (I mean, you can’t have more than one URL at once, right? Well, frames but those are children of the main document.) and therefore Window has a property of Document.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;window.document
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;or just…&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;document
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Why can we just call on &lt;strong&gt;document&lt;/strong&gt;? Because our top level object is implicitly the window. Pretty sweet, right? Making sense? I hope you said yes. If not, we’re just looking at the HTML document you requested from the server the same way JavaScript does… as objects. Now we know we’re speaking the same dialect but what else is added?&lt;/p&gt;

&lt;p&gt;In plain English: The DOM is an object model for traversing and manipulating documents rendered by web browsers. There is a W3C standard for the DOM and the reason that JavaScript can hurt is because it is inconsistently implemented by browsers. So developers took to writing a lot of boiler plate “browser sniffer” code to ensure that behaviors were similar for all users viewing their sites. Internet Explorer is typically dragged through the mud because it’s version 6 of the browser was exceptionally slow to adopt DOM elements and events as standard and instead continued down its own path. But why? The answer is simple. IE 4 and 5 drove innovation in the DOM/JavaScript space. IE added additional attributes and events, e.g. drag and drop&lt;/p&gt;

&lt;p&gt;As you can imaging there are various objects representing the HTMLElements that are part of the document (and some that may not be!) so we won’t list all of them here, I just wanted to let you know the top level context in client side JavaScript (window) so that you’re not surprised but what you’re going to see when we move to the bane of client side JavaScript: Events. (this is, without jQuery or your lib of choice!)&lt;/p&gt;

&lt;p&gt;So, working with the DOM is made stupid easy when you’ve got help in the form or jQuery or MooTools or Prototype or some other lib that equalizes the DOM implementations of various browsers. Those folks are doing great work and I encourage you to use them (I certainly do!) for your work. BUT let’s look at what Mozilla’s Firefox does with HTML events so we can see how these event objects and the implicitly passed &lt;strong&gt;this&lt;/strong&gt; contextual object cause confusion to the uninitiated.&lt;/p&gt;

&lt;p&gt;First we have to establish an event to listen for. We do this in Mozilla’s flavor of JavaScript by doing adding a “listener” to a particular event. How about a click on a button? Easy enough. :)&lt;/p&gt;

&lt;p&gt;Here’s the HTML document we’re going to use. Save it as an html page and open that document in Firefox. Open Firebug and follow along.&lt;/p&gt;

&lt;script src="http://gist.github.com/260659.js?file=blank_doc_with_button.html"&gt;&lt;/script&gt;&lt;p&gt;OK, first up is to grab a reference to the button element in the document.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var btn = document.getElementById("clickr");
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, let’s create a simple function that will handle clicks the user makes on “clickr”.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function ourCallback(evt){
    alert(evt);
    alert(this);
};
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now let’s listen for clicks on &lt;em&gt;btn&lt;/em&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;btn.addEventListener("click", ourCallback, false);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If you’ve been reading along then it should come as no surprise the to types of objects that are alerted when we run this code in the Firebug JavaScript console.&lt;/p&gt;

&lt;p&gt;The event object sent as an explicit argument is…
    [object MouseEvent]
The &lt;strong&gt;this&lt;/strong&gt; operator at this point gets the value of the implicitly passed sender… 
    [object HTMLButtonElement]&lt;/p&gt;

&lt;p&gt;So our button is this because it directly broadcasted the click and all listeners know who initiated the click.&lt;/p&gt;

&lt;p&gt;That should make pretty good sense by now but what happens if the callback function has expectation on &lt;strong&gt;this&lt;/strong&gt; that we’re not going to know at runtime? Here’s a case where things can be odd and cause lots and lots of frustration, well at least for programmers in the late 90s. :) Let’s create an object that simply counts a number every second. We’ll add an interval counter that alerts that value. Sounds simple right? It is, if you know what to expect when using &lt;strong&gt;this&lt;/strong&gt;. Consider the following…&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var ob = {count:1, currentCount: function(){ alert("my count is "+ this.count);}}
ob.currentCount();
setTimeout(ob.currentCount, 2000);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, what’s going to happen when we run this sample? We’ve created an object to do our incrementing (even if we don’t have an incrementer for it… details!) for us. On line 2, ob calls currentCount and then on line 3 we ask the window to tell ob to call currentCount after 2 seconds. right? well, not so much, go ahead on run it. If you’re following along you’re going to see the following message alerted to the window:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;my count is 1
my count is undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;OH NOES!!! That’s right, friends, let’s read these same 3 lines of code the way JavaScript did… in plain english:&lt;/p&gt;

&lt;p&gt;“Ok, the programmer created an object with one property and one method and assigned it to a variable named ‘ob’. Cool. I can do that. Next the programmer is asking ob to call currentCount. Cool, no problem. Finally they want the window to call currentCount in 2 seconds. done and done!”&lt;/p&gt;

&lt;p&gt;You see, here we have our first curiosity caused by the simplicity and power of JavaScript. Remember when we said functions where higher order and first class citizens? Remember how “this” refers to the contextual object? Well if you do, then in plain english, what is happening here is that we’re delegating the function defined in ob.currentCount which is&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function(){ alert("my count is "+ this.count);}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;So, when we call the setTimeout method we’re just caching the function signature and not any reference to the parent object that references the function. So when the function is called after 2 seconds what is &lt;strong&gt;really&lt;/strong&gt; being called is this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;window.currentCount(); 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But that’s not what we &lt;em&gt;mean&lt;/em&gt;. We want ob to call it. SO, let’s not forget that other great feature of JavaScript: &lt;strong&gt;closures&lt;/strong&gt;. Let’s instead, curry the exact state that we want in the form of a closure to be called at the timeout.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;setTimeout(function(){ob.currentCount();}, 2000); 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now when you run line 3, you should see the right alert message. WOW! Isn’t JavaScript cool?! I think so! Anyway, I hope that goes a long way to helping you understand what’s going on in the browser when you’re using JavaScript. Even though libraries like jQuery let us forget about these particulars when we code it’s nice to know what’s going on under the covers. :)&lt;/p&gt;</description><link>http://fallenrogue.com/post/292361688</link><guid>http://fallenrogue.com/post/292361688</guid><pubDate>Sun, 20 Dec 2009 18:10:46 -0500</pubDate></item><item><title>JavaScript Part 4 - the "this" operator</title><description>&lt;p&gt;OK, take a deep breath, hold your nose and get ready to finally understand &lt;strong&gt;this&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;When my friends first dive into JavaScript the this operator throws people for a major curve. To really understand what it is I’m going to try my best to distill its essence into a simple explanation that while not fully encompassing the nuances of “this” use should go along way to helping you understand the resulting behaviors of using &lt;strong&gt;this&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;From Mozilla:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;The &lt;em&gt;this&lt;/em&gt; keyword refers to the context object aka the current object.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;See, that’s simple right? Well, not really. The problem presents itself when we add in JavaScripts scoping rules (hopefully in this series soon!).&lt;/p&gt;

&lt;p&gt;OK, first &lt;strong&gt;this&lt;/strong&gt; being a pointer to the context object is passed into functions implicitly. That’s right folks, it’s not sitting there waiting in the scope that it was originally created in, no, it’s actually passed through to functions auto-magically when you call a function. Consider the following code running in a browser context.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var frank = {name:"Frank"};
var betty = {name:"Betty"};

function sayMyName(){
    document.write(this.toString()+"'s name is "+this.name+"&lt;br&gt;");
}

betty.sayMyName = frank.sayMyName = sayMyName;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All we’ve done here is introduce a few new objects, frank and betty, a globally accessible function called “sayMyName” and gave both betty and frank properties that will call that function. So, if we run this we’re going to see…&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[object Window]'s name is
[object Object]'s name is Betty
[object Object]'s name is Frank
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ah, did you see what happened there? the first time we call it the current top level context in the browser is actually the Window object! It was passed to our function (because there’s always a caller) implicitly. So, when betty calls the function the betty object is the current object making the call. Therefore, we see it’s something of type Object (remember where we inherit from?) and that it responds to name with Betty. Frank is the same.&lt;/p&gt;

&lt;p&gt;The lesson here is that &lt;strong&gt;this&lt;/strong&gt; is not set when the function is defined it’s determined when the function is executed and the current contextual object is &lt;strong&gt;this&lt;/strong&gt;. So, where does this mess with people’s heads? Check this example out…&lt;/p&gt;

&lt;script src="http://gist.github.com/258229.js?file=js-this-fail.js"&gt;&lt;/script&gt;&lt;p&gt;Let’s run this sample and then run it again with the commented out line… well back into the code. That should bring this crazy subject clearly into light.&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="370" id="viddler_fallenrogue_10"&gt;&lt;param name="movie" value="http://www.viddler.com/player/97dd7b5/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;embed src="http://www.viddler.com/player/97dd7b5/" wmode="transparent" width="437" height="370" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" name="viddler_fallenrogue_10"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;The important thing to remember is that this is a reference to context object. When we transfer the context to a variable in the top level (global) space we’re really adding that as a property on Window in the case of browser scripting. So, the first time we call it, name is not defined, but if you call it a second time, you’ll notice that name is updated to the variable and since window now has a name value it’s printed to the screen.&lt;/p&gt;

&lt;p&gt;There’s a whole host of variations on this very wide topic but I believe if you understand exactly what &lt;strong&gt;this&lt;/strong&gt; is referring to it can help you to quickly identify when it’s been used in an unintentional way in your JavaScript code. In fact, having written this part, I believe we could do another follow up on the quirks of &lt;strong&gt;this&lt;/strong&gt; in the browser which is where most will have context to it. Events… yes… events + this can be tricky. Stay tuned for that. :)&lt;/p&gt;</description><link>http://fallenrogue.com/post/286582175</link><guid>http://fallenrogue.com/post/286582175</guid><pubDate>Wed, 16 Dec 2009 17:27:00 -0500</pubDate></item><item><title>JavaScript Part 3 - Prototype Based Language</title><description>&lt;p&gt;For a few years the alpha geek crowd has been debating (read: justifying their own preferences) what type of Object Oriented Language features are the most developer friendly. I never have the heart to remind these folks that everyone experiences the world differently and some will always understand class based OO and others want something else. Well, one of those “something else” is used in JavaScript: Prototype Based Objects.&lt;/p&gt;

&lt;p&gt;Given my known readership and audience I’m going to assume you’re all familiar with a class based language. I’m going to use C# in this example but the comparison should hold up for similar languages like Java.&lt;/p&gt;

&lt;p&gt;Let’s take a look at defining a class with with to create objects (a.k.a. instances). My example is a simple model that most folks can relate to… Person!&lt;/p&gt;

&lt;p&gt;C#
&lt;script src="http://gist.github.com/257978.js?file=C%23+baseed+object+creation"&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;Now let’s do the same thing in JavaScript…&lt;/p&gt;

&lt;p&gt;JavaScript 
&lt;script src="http://gist.github.com/257979.js?file=JavaScript+object+creation"&gt;&lt;/script&gt;&lt;/p&gt;

&lt;p&gt;These examples are nearly identical from the standpoint that they represent the same data. They are 2 ways of saying the same thing, one in class based way and the other in a prototype based way. By assigning the &lt;strong&gt;proto&lt;/strong&gt; attribute on a prototype based language you’re essentially saying this is your new “parent”, thus providing the object the features and functionality.&lt;/p&gt;

&lt;p&gt;Now, in the JavaScript version we did not create a constructor for creating those objects but we can do that too if we like…&lt;/p&gt;

&lt;script src="http://gist.github.com/257990.js?file=JS-+alternative+object+const."&gt;&lt;/script&gt;&lt;p&gt;And finally, remember that our functions are first class citizens and can be used to establish members for an object.&lt;/p&gt;

&lt;script src="http://gist.github.com/257991.js?file=gistfile1.txt"&gt;&lt;/script&gt;&lt;p&gt;Now, &lt;strong&gt;proto&lt;/strong&gt; is not the idiomatic why of defining this inheritance. Most the time you’ll see the more common “prototype” property. Why did I show the other? Just giving you options. Here’s a slight variation on what we’ve done using the prototype object.&lt;/p&gt;

&lt;script src="http://gist.github.com/258119.js?file=alt+inheritance+-+JS"&gt;&lt;/script&gt;&lt;p&gt;As you can see, this is &lt;strong&gt;very&lt;/strong&gt; close to the version I presented and is more common. It’s nice to know but methods just for your own reference. I personally prefer the latter but that could be habit more than preference.&lt;/p&gt;

&lt;p&gt;OK, well, that’s basically it for now from a 500000 foot view. Well talk more about this awesome topic soon!&lt;/p&gt;</description><link>http://fallenrogue.com/post/286438599</link><guid>http://fallenrogue.com/post/286438599</guid><pubDate>Wed, 16 Dec 2009 15:09:36 -0500</pubDate></item><item><title>JavaScript Part 1 - hello JavaScript!</title><description>&lt;p&gt;JavaScript is an object oriented scripting language.&lt;/p&gt;

&lt;p&gt;It is a dialect of the ECMAScript standard.&lt;/p&gt;

&lt;p&gt;It is dynamic, loose typed and prototype-based.&lt;/p&gt;

&lt;p&gt;It has first-class functions. That means a function is an object in JavaScript. You can treat it as such.&lt;/p&gt;

&lt;p&gt;If you’re looking for some history of the language and an introduction of the “why” check out Mozilla’s &lt;a href="https://developer.mozilla.org/en/A_re-introduction_to_JavaScript"&gt;A re-introduction to JavaScript&lt;/a&gt; And once you’ve ready that or if you’re skipping it please continue…&lt;/p&gt;

&lt;p&gt;It’s time to say hello to one of my favorite languages again. This time from my perspective. If there’s something you love, I believe you have little reason not to share it with the world. Do I want everyone to start programming in JavaScript? Well, that’s a lofty goal and not really my point here. My point is more to share my passion and clear up a few misconceptions.&lt;/p&gt;

&lt;p&gt;So, play along with me friends… first task is to create a way to play. There are many but I’m going for low barrier for entry. Open firefox and download (if you don’t have it) firebug.&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="329" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/66e7aacb/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/66e7aacb/" width="437" height="329" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;Now that you’ve got a way to play with JavaScript and the DOM, let’s start building a better understanding the features of the language. Create a blank HTML page and open it in Firefox. This will be the blank canvas with which we experiment with the language in a REPL style system via Firefox and Firebug. Let’s play with the loose type system first. Try assigning a variable a numeric value and then assign the same variable a string.&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="353" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/33e38452/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/33e38452/" width="437" height="353" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;See? Type is loose.&lt;/p&gt;

&lt;p&gt;Wanna see why we functions are “first-class” or “objects”? Let’s create a function. The syntax for creating a function is…&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function [name](params[,n]){
    //method body
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now, why is name optional? Because functions, even without a name, are still objects. A common practice is to keep the function anonymous but assign it to a variable for later use.&lt;/p&gt;

&lt;p&gt;var sayHello = function(say){alert(say);}&lt;/p&gt;

&lt;p&gt;If you type both types of function into firebug you’ll see…&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="353" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/2b2fac2c/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/2b2fac2c/" width="437" height="353" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;That they can be called the same way and as objects can be passed around just as you would any other type of object.&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="353" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/9c022013/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/9c022013/" width="437" height="353" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;Internet darling jQuery makes extensive use of this feature in its implementation. It typically calls this practice “accepting a callback” which is just another way of saying “give me a function to call when I’m done doing whatever I’m doing and I’ll call it. I will also pass that function data related to my initial task.”&lt;/p&gt;

&lt;p&gt;Finally, what does it mean to be “prototype based”? Well, that’s where we’re going to start Part 3, so until next time write something fun using Firebug and JavaScript. Try using the DOM’s document object to write something to the page.&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="353" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/6a5bb39b/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/6a5bb39b/" width="437" height="353" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;See, good times. gooooood times. :)&lt;/p&gt;</description><link>http://fallenrogue.com/post/286438240</link><guid>http://fallenrogue.com/post/286438240</guid><pubDate>Wed, 16 Dec 2009 15:09:11 -0500</pubDate></item><item><title>JavaScript Part 2 - The Free Stuff</title><description>&lt;p&gt;This is a tough one. I don’t generally like to discuss the built in objects of a language because they are easily searched for. Instead I’ll list a few and then talk about using them as that’s a little more subjective and worthy of discussion and continual review.&lt;/p&gt;

&lt;p&gt;Quick Reference:&lt;/p&gt;

&lt;h4&gt;Types&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
&lt;li&gt;Numbers&lt;/li&gt;
  &lt;li&gt;Strings&lt;/li&gt;
  &lt;li&gt;Booleans (true|false) &lt;/li&gt;
  &lt;li&gt;Objects&lt;/li&gt;
  &lt;li&gt;undefined and null &lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;h4&gt;Special Objects&lt;/h4&gt;

&lt;blockquote&gt;
  &lt;ul&gt;
&lt;li&gt;Date&lt;/li&gt;
  &lt;li&gt;Regular Expression&lt;/li&gt;
  &lt;li&gt;Functions&lt;/li&gt;
  &lt;li&gt;Array&lt;/li&gt;
  &lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, yeah, mostly these will function as you’d expect them to. Therefore, as I stated before, let’s skip that. Instead let’s discuss some fun things that are legitimately ambiguous to developers sharpening their JavaScript knives.&lt;/p&gt;

&lt;h3&gt;Objects in JavaScript&lt;/h3&gt;

&lt;p&gt;One of the things that throws folks is the notion of object being a specific type and staying that way after being initialized from a class. But in JavaScript objects are more like Hashes in Ruby or Dictionary&lt;key, value&gt; in C#. If you make that mental connection then seeing the JavaScript Object Notation (or JSON) will provide context for what you’re working with.&lt;/p&gt;

&lt;p&gt;If you remember from part one, our first object creation was done as such:&lt;/p&gt;

&lt;script src="http://gist.github.com/257991.js?file=gistfile1.txt"&gt;&lt;/script&gt;&lt;p&gt;If you look the object is created as it’s defined using the object notation which looks &lt;strong&gt;remarkably&lt;/strong&gt; familiar to just some key-value collections mentioned about. When doing this you can then access those properties on the person instance using the dot or [] notation&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;person.name
person["name"]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;both are fine ways to access the properties on your objects. So, knowing that, there are a couple of ways to create new objects in JavaScript they both establish a direct relationship to the super “Object” class.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var person = new Object();
var person = {}; 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;{} is object notation so by specifying it on the right side of the assignment operator (=) yields a new Object instance to person.&lt;/p&gt;

&lt;p&gt;There are many different ways to use the properties of this new object (which we mentioned earlier see new/[]) but the important thing to note is that since our objects have no concrete relationship to strong types we can access and assign properties on our objects at will.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;person.likes_cake = true
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;if perfectly legal even if the member “likes_cake” is not a property on person. This allows for some real dynamic behaviors to occur at runtime. So, why would you use [] vs the . property syntax? Well, if you’re a daring individual you could assign properties that are named the same as reserved keywords. for example, “if” is a reserved keyword in JavaScript so just coming out with&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var letter = {};
letter.for = "leon@foo.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;is not going to work. BUT if use the [] property notation we can!&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;var letter = {};
var letter["for"] = "Leon@foo.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;pretty cool stuff there! I don’t know that you’d want to do it from an idiomatic standpoint but it’s possible if you’d like to have it.&lt;/p&gt;

&lt;h3&gt;Functions&lt;/h3&gt;

&lt;p&gt;Functions are important to understand and as a bonus they are remarkably simple to understand. Basically, here are the “rules” to live by…&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;defined with the function keyword&lt;/li&gt;
&lt;li&gt;optional name&lt;/li&gt;
&lt;li&gt;optional argument list&lt;/li&gt;
&lt;li&gt;code block to be executed when the function is executed. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;AND as a bonus every function gets a few properties that may be of value. One of my favorites is the “arguments” object. It’s just an array of all the arguments that were passed to the function. Let’s play a bit with it.&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="353" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/86d8dd31/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/86d8dd31/" width="437" height="353" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;pretty excellent stuff, right? many languages share this feature but I enjoy the compact way that JavaScript lets you extend the use of a functional all the way to runtime. Now that’s fun but with all languages that provide higher order functions it becomes very important to understand how they can be called recursively. Tail recursion (in short: last part of the function calls itself again until told not to) is an important concept but how do you know what do call again if your function has no name? Well, the answer lies in the arguments object. Let’s write a small tail recursive anonymous function. We’ll assign it so that we can call it a first time but since it doesn’t know what it’s own name we’ll use the arguments object’s callee property to call the method until we’re done. Type along with me using FireBug…&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="300" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/956b2001/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/956b2001/" width="437" height="300" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;In there we see 2 things: first that the callee property is a little more than just a pointer to the current function, it also is an object that is persisted across the function calls so we were able to use that to hold a reference to a number as we counted down from the first argument that was passed in. Pretty cool, right!? That’s some wonderful, powerful introspection and provides JavaScript some of that signature magic that makes me fall in love with it over and over again.&lt;/p&gt;

&lt;p&gt;Next we’ll take a look at arguably the most powerful feature in JavaScript and one that has gained a lot of exposure in other languages recently: closures.&lt;/p&gt;

&lt;h3&gt;Closures&lt;/h3&gt;

&lt;p&gt;Now closures have variation of definition and the minutiae of that semantic debate are not in the scope of this article. Instead let’s go with the following simplistic definition: closures maintain the scope of the variable at the time that the function is created and persisted after you believe they have fallen from scope. A simple example of this “scoping” would be using an inner function to establish an outer scope while establishing an inner scope for later use.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;function greeting(prefix){
    return function(name){
     return prefix + " " + name;
 };
}

helloTo = greeting("hello there,")
document.write(helloTo.toString());
document.write("&lt;br&gt;&lt;br&gt;");
document.write(helloTo("Leon"));
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;let’s run this code to examine the results in our REPL environment: FireFox+FireBug :)&lt;/p&gt;

&lt;p&gt;&lt;object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="437" height="300" id="viddler"&gt;&lt;param name="movie" value="http://www.viddler.com/player/4e16a696/"&gt;
&lt;param name="allowScriptAccess" value="always"&gt;
&lt;param name="allowFullScreen" value="true"&gt;
&lt;param name="flashvars" value="fake=1"&gt;
&lt;embed src="http://www.viddler.com/player/4e16a696/" width="437" height="300" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="fake=1" name="viddler"&gt;&lt;/embed&gt;&lt;/object&gt;&lt;/p&gt;

&lt;p&gt;That’s enough for now, friends!&lt;/p&gt;</description><link>http://fallenrogue.com/post/286438451</link><guid>http://fallenrogue.com/post/286438451</guid><pubDate>Wed, 16 Dec 2009 15:09:00 -0500</pubDate></item></channel></rss>
