<?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>Big Nerd Ranch Blog</title>
	<atom:link href="http://blog.bignerdranch.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.bignerdranch.com</link>
	<description>We offer classes for programmers in a resort-like setting, and this is our blog.</description>
	<lastBuildDate>Sat, 25 May 2013 03:29:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4.2</generator>
		<item>
		<title>Inside the Bracket, part 1 &#8211; Open for business</title>
		<link>http://blog.bignerdranch.com/2833-inside-the-bracket-part-1-open-for-business/</link>
		<comments>http://blog.bignerdranch.com/2833-inside-the-bracket-part-1-open-for-business/#comments</comments>
		<pubDate>Thu, 23 May 2013 14:10:13 +0000</pubDate>
		<dc:creator>Mark Dalrymple</dc:creator>
				<category><![CDATA[C Stuff]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2833</guid>
		<description><![CDATA[<p><p>What is something that we use every day as a Mac or iOS programmer? Objective-C. What do we use every day in Objective-C? Those square brackets. How many times a day do you type something like this?</p>
<pre>[someObject doSome:stuff for:reasons];</pre>
<p>Ever wondered what&#8217;s really happening inside those square brackets?&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2833-inside-the-bracket-part-1-open-for-business/">Inside the Bracket, part 1 &#8211; Open for business</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>What is something that we use every day as a Mac or iOS programmer? Objective-C. What do we use every day in Objective-C? Those square brackets. How many times a day do you type something like this?</p>
<pre>[someObject doSome:stuff for:reasons];</pre>
<p>Ever wondered what&#8217;s really happening inside those square brackets? Polymorphism!</p>
<h3>Polly want a morphism</h3>
<p>Great. Fancy words. Thank you! As every Introduction to Object-Oriented Programming book tells you, polymorphism comes from the Greek words &#8220;poly&#8221;, meaning &#8220;many&#8221;, and &#8220;morph&#8221;, meaning shapes. We have a bunch of shapes (a pile of assorted Lego bricks). Or, it can mean we have something that can take on many shapes (a Lego brick that can change from a 2&#215;2 into a 1&#215;4.). These days it pretty much means &#8220;I&#8217;m sending a message to an object, and the behavior caused by that message will happen. But I don&#8217;t really create precisely what it does.&#8221; You can ask an <code>NSArray</code> its count. You can ask an <code>NSSet</code> its count. The implementation of -count can be radically different between the two, but you get each one&#8217;s count by sending the same message. What problem is it solving, though? Why have polymorphism? Back in the Old Days of contrived programming straw-men (straw-persons?), you might be implementing a graphical toolkit, and you might have code <a href="https://gist.github.com/markd2/5629516">like this</a> which draws all the views in a window:</p>
<pre>void DrawViews (View *views[], int count) {

    for (int i = 0; i &lt; count; i++) {
        View *view = views[i];

        switch (view-&gt;kind) {
          case kButtonView:
            printf ("Drawing a button!\n");
            ButtonDraw (view);
            break;

          case kSliderView:
            printf ("Drawing a slider!\n");
            SliderDraw (view);
            break;

          case kPonyView:
            printf ("OMG PONIES!\n");
            PonyDraw (view);
            break;
        }
    }

} // DrawViews</pre>
<p>Where views is an array of pointers to Views, which a &#8220;kind&#8221; flag to tell what kind of view is what:</p>
<pre>typedef struct View {
    ViewKind kind;
    Rect   bounds;
} View;
</pre>
<p>The Kind is just an enum:</p>
<pre>typedef enum {
    kButtonView,
    kSliderView,
    kPonyView
} ViewKind;
</pre>
<p>It&#8217;s pretty readable. You could ship this and not feel sad. The problem comes when you need to update the software, say by adding an Image View. You&#8217;d need to touch the <code>ViewKind</code> enum, add an <code>ImageDraw</code> function (which isn&#8217;t too bad), and also add a new case to DrawViews. If you had other code (hit-test view) that used views, you&#8217;d need to update that code as well. That&#8217;s actually bad. Would anyone actually design code like this? Not really. But it does highlight the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open/Closed principle</a> (invented by Bertrand Meyer, and later evangelized by Robert C. Martin). Robust code should be open to extension but closed to modification. It&#8217;d be nice to write <code>DrawViews</code> once in such a way where we could add new kinds of views (open) without doing violence to the code that makes the views draw (closed). Something like this pseudocode:</p>
<pre>void DrawViews (View *views, int count) {
    for (int i = 0; i &lt; count; i++) {
        View *view = views[i];
        <strong>YoViewDrawYourself</strong> (view);
    }
} // DrawViews
</pre>
<p>If Only We Had that <code>YoViewDrawYourself</code>, that no matter what view is passed in, it could figure out what the code behind the view is. Why is that good? Bugs tend to congregate where code changes happen. Got a weird bug? Oftentimes the most recent code change either introduced it or exposed it. Touching a central loop like <code>DrawViews</code> every time we add a new kind of view is courting disaster. Maybe your wife&#8217;s brother&#8217;s second cousin who &#8220;Knows how to program those phone things&#8221; isn&#8217;t the world&#8217;s greatest software enginerd. Do you want him messing with one of the most-called routines in your toolkit?</p>
<h3>Indirection To The Rescue</h3>
<p>A truism in the programming biz is &#8220;any problem can be solved by adding a layer of indirection.&#8221; Of course, this doesn&#8217;t mean that adding a layer of indirection is the only solution, or the best solution, but a lot of times it&#8217;s true. Especially in a case like this: rather than having <code>DrawViews</code> call functions directly, we add a bit of indirection. Instead of using the function name, bounce off a function pointer. Where would be a good place for that function pointer? Put it in with the view. Let&#8217;s make the views a little more interesting. They can be drawn, hit-tested, and described. Here&#8217;s some function pointers types that describe the different features:</p>
<pre>typedef void (*<strong>DrawCallback</strong>) (View *view);
typedef bool (*<strong>HitTestCallback</strong>) (View *view, Point mouseClick);
typedef char * (*<strong>DebugDescriptionCallback</strong>) (View *view);
</pre>
<p>C function pointer syntax is kind of annoying. The name of the pointer type is in bold here. The the return type is to the left, and the stuff on the right are the arguments to the function. Thus, <code>DrawCallback</code> is a pointer to a function that takes a <code>View</code> pointer, and returns nothing. <code>HitTestCallback</code> takes a <code>View</code> and a <code>Point</code>, and returns <code>true</code> or <code>false</code> if the mouse click is inside or outside of the view. Actually using function pointers is pretty easy. Once you have them typedef&#8217;d, you can assign them. Here&#8217;s a function that corresponds to the <code>DrawCallback</code> signature:</p>
<pre>static void ButtonDraw (View *view) {
    printf ("Drawing a button!\n");
}</pre>
<p>You can have a variable that points to the function:</p>
<pre>DrawCallback drawer = ButtonDraw;</pre>
<p>Notice <code>ButtonDraw</code> doesn&#8217;t have any parens after it here. A paren-less function means &#8220;give me the address of the function, where the object code lives in memory, but don&#8217;t call it.&#8221; You jump through the function pointer by adding arguments (if there are any) in parentheses:</p>
<pre>drawer (someView);</pre>
<p>This will call <code>ButtonDraw</code>, passing it <code>someView</code>. It is effectively identical to calling <code>ButtonDraw</code> directly except you&#8217;re bouncing off of a variable—adding that little bit of indirection.</p>
<h3>The Vtables Have Turned</h3>
<p>So, back to view drawing. How can you use these function pointer types to your advantage? If you can put a table of function pointers at a well-known location in a <code>View</code>, <code>DrawViews</code> can find each view&#8217;s individual <code>DrawCallback</code> and call it. A common term for such a list of function pointers is a &#8220;virtual method table&#8221;, or vtable for short. Here&#8217;s the vtable for Views:</p>
<pre>typedef struct ViewVTable {
    DrawCallback             draw;
    HitTestCallback          hitTest;
    DebugDescriptionCallback description;
} ViewVTable;</pre>
<p>It&#8217;s just a struct with three function pointers. Buttons will have <code>draw</code>, <code>hitTest</code>, and <code>description</code> functions:</p>
<pre>static void ButtonDraw (View *view) {
    printf ("Drawing a button!\n");
}

static bool ButtonHitTest (View *view, Point point) {
    printf ("Hit testing a button!\n");
    return false;
}

static char * ButtonDebugDescription (View *view) {
    static char s_unsafeBuffer[1024];
    snprintf (s_unsafeBuffer, sizeof(s_unsafeBuffer), "Button at %p", view);
    return s_unsafeBuffer;
}
</pre>
<p>And <code>Slider</code> will have a similar set of functions. Here&#8217;s the draw:</p>
<pre>static void SliderDraw (View *view) {
    printf ("Drawing a slider!\n");
}
</pre>
<p>Rather than having a view type constant, replace it with the vtable:</p>
<pre>typedef struct View {
    ViewVTable vtable;
    Rect       bounds;
} View;</pre>
<p>Here&#8217;s what the object looks like in memory once everything is populated.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/bracket-vtable.png" alt="Bracket vtable" title="bracket-vtable.png" border="0" width="761" height="352" /></p>
<p>(Side note—the function pointers are duplicated in each <code>View</code>. For realsies, you&#8217;d construct a table once in memory, and have <code>View</code>s point to that table.) Setting up the button is pretty easy:</p>
<pre>View button;
    button.vtable.draw = ButtonDraw;
    button.vtable.hitTest = ButtonHitTest;
    button.vtable.description = ButtonDebugDescription;
    button.bounds = (Rect) { 0.0, 0.0, 100.0, 200.0 };</pre>
<p>Just assign the functions-that-do-stuff to the corresponding function pointers.</p>
<h3>Draw Them Views</h3>
<p>So, that&#8217;s a lot of work and kind of weird indirection. What does it buy us? Here&#8217;s an updated <code>DrawViews</code>:</p>
<pre>void DrawViews (View *views[], int count) {
    for (int i = 0; i &lt; count; i++) {
        View *view = views[i];
        printf ("drawing %s\n",
                view-&gt;vtable.description(view));
        view-&gt;vtable.draw (view);
    }
} // DrawViews</pre>
<p>It takes an array of <code>View</code> pointers and a count, and then chugs through the views, fishing out the description and draw function pointers and jumping through them. Running our button through this function yields:</p>
<pre>View *views[] = { &#038;button };
    DrawViews (views, 1);

    drawing Button at 0x7fff6ad6e720
    Drawing a button!
</pre>
<p>So, does this version of <code>DrawViews</code> adhere to the Open/Closed principle? Let&#8217;s check. First, openness—how do you extend it with other view types? Add a slider. First, some functions to do the slidery stuff:</p>
<pre>static void SliderDraw (View *view) {
    printf ("Drawing a slider!\n");
}

static bool SliderHitTest (View *view, Point point) {
    printf ("Hit testing a slider!\n");
    return false;
}

static char * SliderDebugDescription (View *view) {
    static char s_unsafeBuffer[1024];
    snprintf (s_unsafeBuffer, sizeof(s_unsafeBuffer), "Slider at %p", view);
    return s_unsafeBuffer;
}
</pre>
<p>Populate a <code>View</code> with these function pointers:</p>
<pre>View slider;
    slider.vtable.draw = SliderDraw;
    slider.vtable.hitTest = SliderHitTest;
    slider.vtable.description = SliderDebugDescription;
    button.bounds = (Rect) { 150.0, 77.0, 300.0, 32.0 };</pre>
<p>Call DrawViews:</p>
<pre>View *views[] = { &#038;button, &#038;slider };
    DrawViews (views, 2);</pre>
<p>And get this output:</p>
<pre>drawing Button at 0x7fff6ad6e720
Drawing a button!
drawing Slider at 0x7fff6ad6e6f8
Drawing a slider!</pre>
<p>So, we&#8217;ve added a new <code>View</code> type, so <code>DrawViews</code> is open to extension. Now for closed-ness. You added a slider, but didn&#8217;t have to touch <code>DrawViews</code>. That means it&#8217;s closed to modification. Looks like a Win. In case you didn&#8217;t notice, <code>View</code> can be thought of as a class, with draw, hitTest, and description being methods of that class. An individual View struct floating around memory is an instance of that class.</p>
<h3>So, What about Objective-C?</h3>
<p>This model, using vtables, is similar to what C++ does, as well as any number of do-your-own-OOP toolkits written in straight C. It&#8217;s very fast. Just pointer+offset to get a function pointer (in this case), or pointer+offset to get the vtable, and then another pointer+offset to get the actual function (when you have your vtable separate from the object). Still, that&#8217;s very fast. The tradeoff in speed is flexibility. The vtables are defined at compile time, whether manually like with the Views, or by the compiler. The offsets from the table pointers are baked-in at compile time too, making it problematic to upgrade libraries without requiring a recompile. (This is similar to the <a href="http://en.wikipedia.org/wiki/Fragile_base_class">Fragile Base Class Problem</a>.) Objective-C takes a different approach. Rather than just having a pile of function pointers, it has a dictionary of function pointers, stored under a name. That doesn&#8217;t sound like a big difference. Instead of invoking a view&#8217;s drawing code with <code>someView.vtable.draw</code>, you&#8217;d actually do <code>someView.dictionary.GetFunctionPointerForName("draw");</code></p>
<h3>No, Really. It&#8217;s Huge.</h3>
<p>Turns out this is a massive difference in behavior. It adds another layer of indirection. Using a function pointer is one layer of indirection. Now the function pointer lookup is another layer of indirection. The big thing is it&#8217;s deferring the decision &#8220;where do I look for the function to draw with&#8221; from compile time (pointer + offset in a struct) to run time (grovel around in a dictionary). You trade some efficiency and safety (e.g. a C++ compiler will guarantee that any View will implement draw) for flexibility.</p>
<p>What is this added flexibility? It has two aspects. The first is you can ask an object questions. &#8220;Do you know how to draw?&#8221; or &#8220;Do you know how to hit test?&#8221; or &#8220;Can you be a Table View data source?&#8221;. This is a familiar operation if you&#8217;ve ever used <code>-respondsToSelector</code>. The second aspect is you can change stuff. &#8220;Hey Button, even though you didn&#8217;t know how to animate a badger running across the screen, here&#8217;s a function you should store under the name <code>badgerRunningAcrossScreen</code>.&#8221; This is familiar if you&#8217;ve ever used categories.</p>
<p>Why can&#8217;t we do that stuff using a vtable-style way of finding implementations? All of the interesting information about &#8220;Button&#8217;s <code>DrawCallback</code> is implemented by the static function <code>ButtonDraw</code>&#8221; is gone. If you recall the discussion on <a href="http://blog.bignerdranch.com/2628-static-cling/">symbol visibility</a>, static functions lose identity. There&#8217;s no way you can ask &#8220;is <code>ButtonDraw</code> used anywhere?&#8221; Similarly, assignments to the <code>ViewVTable</code>, and subsequent access, are all pointer+offset. The compiler doesn&#8217;t care any more that &#8220;<code>DrawCallback</code>&#8221; is the first entry in the table. Also, if you have two different &#8220;objects&#8221; with different vtable layouts—say draw is the first function pointer in <code>View</code>&#8216;s vtable, and draw is the last function pointer in <code>Cowboy</code>&#8216;s vtable, there&#8217;s no way of saying &#8220;hey, here&#8217;s an arbitrary vtable, give me the one that has a struct element named draw.&#8221;</p>
<p>Because Objective-C defers the &#8220;draw -> someFunction&#8221; mapping til runtime, it can expose all sorts of interesting information (a.k.a. metadata). Walk up to any Objective-C object and ask it &#8220;Hey do you -draw?&#8221;. The runtime will then look at the object, grab the pile of name-to-function maps, and see if draw is in there. If so, it&#8217;ll return YES. This is what allows us to have <a href="http://blog.bignerdranch.com/469-protocols-part-2-delegation/">delegates</a> and data sources that aren&#8217;t members of a particular subclass.</p>
<p>Languages like C++ require you to declare a particular class/template heritage for delegate objects so it can place the delegate function pointers at knowable places in the vtable, as well as guarantee that you can call those functions without worrying that they might not be implemented and crashing at runtime. One of the favorite never-ending programming discussions you&#8217;ll find is the suck/rule status of both of these approaches. The C++ way is faster and safer, but not as flexible. The Objective-C way is slower but flexible, but you can die unexpected horrible deaths at runtime. Objective-C is what it is, so I won&#8217;t get into this discussion.</p>
<h3>Back Inside the Bracket</h3>
<p>OK, after that fascinating (eye-roll) discussion of polymorphism strategies, how does that apply to this line of Objective-C code:</p>
<pre>[someObject doSome:stuff for:reasons];</pre>
<p>This says : look at someObject. Find its bag of name->function mappings. Look for doSome:for: in the bag. If found, call that code. (Another aside : There&#8217;s the whole additional world of inheritance which I haven&#8217;t touched on. Subclasses in vtable language just copy the superclass&#8217;s function pointers. There&#8217;s no penalty if you invoke a member function that&#8217;s implemented in a superclass. It&#8217;s still pointer + offset + jump. Objective-C, if it can&#8217;t find a method implementation, will look at the bag of name->function mappings of the superclass if it can&#8217;t find an implementation of the object that got sent a message.) How does this work under the hood? All Objective-C objects have a pointer in a well-known offset from the beginning of the object, called <code>**isa**</code>. This is a pointer to a &#8220;class object&#8221;, which you can think of as the bag of name->function mappings, a pointer to the superclass, and the metadata for the class. Want to send <code>-doSome:for:</code> to an object? Grab that object&#8217;s <code>isa</code>, look up <code>-doSome:for:</code> in the bag, and jump to that code.</p>
<h3>objc_msgsend</h3>
<p>Objective-C, in its first incarnations, was not a stand-alone compiler. It was a preprocessor that read your <code>.m</code> files and emitted C code, which would then get compiled by a C compiler. There was a runtime component that would take objects, pointer+offset them to get the isa pointer, and then look up function pointers. This preprocessor would turn bracketed calls:</p>
<pre>[someObject doSome:stuff  for:reasons];</pre>
<p>into calls to <code>objc_msgSend</code>:</p>
<pre>objc_msgSend (someObject, @selector(doSome:for:), stuff, reasons);</pre>
<p>objc_msgSend is where all the lookup work happens. Nowadays, the compiler doesn&#8217;t have to go through a C intermediary, instead it can emit <code>objc_msgSend</code> directly. Don&#8217;t believe me? You can always <a href="https://gist.github.com/markd2/5636175">look at</a> what the compiler is emitting:</p>
<pre>int main (void) {
    @autoreleasepool {
        SomeObject *obj = [[SomeObject alloc] init];
        [obj doSome: @"stuff"  for: @"reasons"];
    }

    return 0;
} // main</pre>
<p>Run it through <a href="http://blog.bignerdranch.com/2753-leveling-up/">a disassembler</a>, and see that it&#8217;s the case:</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/objc-msgsend.png" alt="Objc msgsend" title="objc-msgsend.png" border="0" width="662" height="98" /></p>
<p>You can see it putting obj (var&#95;32) and the selector, along with @&#8221;stuff&#8221; (var&#95;16) and @&#8221;reasons&#8221; (var_8) into place, and then finally calling <code>objc_msgSend</code> at the end. <code>objc_msgSend</code> is a brilliant piece of engineering, a real example of the power and utility of a little bit of hand-crafted assembly language in the right spot. Bill Bumgarner has a <a href="http://www.friday.com/bbum/2009/12/18/objc_msgsend-part-1-the-road-map/">dissection of objc_msgSend</a> as it existed in OS X 10.6, and since then it&#8217;s been optimized even more.</p>
<h3>Tying it Together</h3>
<p>That&#8217;s a lot of concepts and detail. What do we know now about this code now?</p>
<pre>[someObject doSome:stuff  for:reasons];</pre>
<ul>
<li>It gets boiled down to objc_msgSend </li>
<li>objc_msgSend looks at someObject&#8217;s isa pointer to get the bag of selector->function mappings. </li>
<li>If it finds a function, it&#8217;ll jump to it, otherwise it walks up the superclass chain. </li>
</ul>
<p>And why is it going going through all of these gyrations to look up a function to call? Amongst lots of other things, it gives us that layer of abstraction that lets us write code that adheres to the Open/Closed principle. The caller of <code>someObject</code> doesn&#8217;t care what actually happens when it&#8217;s asked to do stuff, so long as it does it. By hiding the details behind this layer of abstraction, it allows the code sending this message to operate at a higher, more abstract level. We now have flexibility to have core code working on abstract entities to not worry about the details, allowing more flexible (if sometimes harder to follow) code and architectures. Up next, into the Objective-C runtime.</p>
<p>The post <a href="http://blog.bignerdranch.com/2833-inside-the-bracket-part-1-open-for-business/">Inside the Bracket, part 1 &#8211; Open for business</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2833-inside-the-bracket-part-1-open-for-business/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Illuminating ARCLite</title>
		<link>http://blog.bignerdranch.com/2813-illuminating-arclite/</link>
		<comments>http://blog.bignerdranch.com/2813-illuminating-arclite/#comments</comments>
		<pubDate>Wed, 22 May 2013 20:21:37 +0000</pubDate>
		<dc:creator>Mikey Ward</dc:creator>
				<category><![CDATA[C Stuff]]></category>
		<category><![CDATA[Cocoa]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2813</guid>
		<description><![CDATA[<p><p>Today we&#8217;re going to look at using Objective-C&#8217;s array and dictionary subscripting syntax with older iOS and OS X versions.</p>
<p>If you haven&#8217;t already, I can&#8217;t recommend enough reading <a href="/398-objective-c-literals-part-1/">Part 1</a> and <a href="/407-objective-c-literals-part-2/">Part 2</a> of Mark Dalrymple&#8217;s excellent two-part series about Objective-C&#8217;s literal/boxing/subscripting syntax.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2813-illuminating-arclite/">Illuminating ARCLite</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>Today we&#8217;re going to look at using Objective-C&#8217;s array and dictionary subscripting syntax with older iOS and OS X versions.</p>
<p>If you haven&#8217;t already, I can&#8217;t recommend enough reading <a href="/398-objective-c-literals-part-1/">Part 1</a> and <a href="/407-objective-c-literals-part-2/">Part 2</a> of Mark Dalrymple&#8217;s excellent two-part series about Objective-C&#8217;s literal/boxing/subscripting syntax. The code in those posts can be found <a href="https://gist.github.com/2135746">on GitHub as a Gist</a>.</p>
<h3>Recap</h3>
<p>When the literal syntax for creating dictionaries and arrays (and numbers) was announced, we as a developer community sang the praises of short, concise code. Then we were introduced to the subscripting syntax for the same, and many of us squealed with joy.</p>
<p>In case you&#8217;ve been living under a very large rock, I&#8217;m talking about our ability to read a value (and store one) in an NS(Mutable)Array using C-array-like syntax:</p>
<pre><code>NSMutableArray *cultOfSkaro = [NSMutableArray arrayWithObjects:@"Sec",@"Caan",@"Thay",@"Jast",nil];
Dalek *leader = cultOfSkaro[0]; // The new hotness
cultOfScaro[0] = [NSNull null]; // We can also write values!
</code></pre>
<p>And don&#8217;t forget dictionaries!</p>
<pre><code>NSMutableDictionary *theGuide = [NSMutableDictionary dictionary];
theGuide[@"Earth"] = @"Mostly harmless."; // ...mostly.
</code></pre>
<p>This &#8220;new&#8221; subscripting syntax is super-duper wonderful for sparing us lots of typing.</p>
<p>The problem, of course, is that it&#8217;s still new. Subscripting is only supported at runtime in iOS 6 and OS X 10.8, and while we can dream, most clients are not yet ready to drop support for iOS 5 and OS X 10.7.</p>
<p>What makes this feature not backward-compatible? Consider that:</p>
<pre><code>cultOfScaro[0]
</code></pre>
<p>doesn&#8217;t equate to:</p>
<pre><code>[cultOfScaro objectAtIndex:0]
</code></pre>
<p>as we&#8217;d expect. It instead equates to:</p>
<pre><code>[cultOfScaro objectAtIndexedSubscript:0]
</code></pre>
<p>and that method doesn&#8217;t exist on NSArray in iOS 5 or OS X 10.7. We get the same raw deal with dictionaries, where</p>
<pre><code>theGuide[@"Earth"] = @"Mostly harmless.";
</code></pre>
<p>is short for:</p>
<pre><code>[theGuide setObject:@"Mostly harmless." forKeyedSubscript:@"Earth"];
</code></pre>
<h3>So what do I do about it?</h3>
<p>If you want to be able to use array and dictionary subscripting syntax with older versions of iOS and OS X, you&#8217;re in luck!</p>
<p>If you&#8217;re already familiar with <a href="http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/ProgrammingWithObjectiveC/CustomizingExistingClasses/CustomizingExistingClasses.html">Objective-C categories</a>, you can just add the subscript-related methods to NS(Mutable)Array and NS(Mutable)Dictionary yourself!</p>
<p>For example, you could implement a cheap <code>-objectAtIndexedSubscript:</code> in a category on NSArray, like so:</p>
<pre><code>- (id)objectAtIndexedSubscript:(NSInteger)index
{
    NSAssert(index &amp;gt;= 0, @"If you want negative indices, see Mark's posts linked above.");
    return [self objectAtIndex:index];
}
</code></pre>
<p>And there you have it. This implementation isn&#8217;t particularly robust, but it would get you back to level ground for being allowed to use subscripting syntax for reading values.</p>
<h3>But wait, there&#8217;s more!</h3>
<p>Unfortunately, there are two problems with this approach. One is more technical and one more practical.</p>
<p>The technical problem is that when a category is loaded, its methods are installed onto their appropriate classes, which is a good thing. If you implement a method in a category that was already present on the class, however, you <em>replace</em> that method. It&#8217;s generally poor form to replace a method whose implementation you didn&#8217;t write (or don&#8217;t fully understand). On devices running iOS 5, we&#8217;d be adding the method, but under iOS 6, we&#8217;d be replacing it. Harrumph.</p>
<p>The practical problem is that we&#8217;d be <em>wasting our time</em> to begin with! Apple has already provided us with a mechanism for utilizing subscripting syntax with older deployment targets.</p>
<p>You&#8217;re welcome to try it yourself. Take a new command line project, set its deployment target to OS X 10.7, and give it a basic test:</p>
<div>
<pre><code>#import &lt;Foundation/Foundation.h&gt;

int main(int argc, const char * argv[])
{
    @autoreleasepool {
        NSArray *strings = @[@"E",@"G",@"B",@"D",@"F"];
        NSString *eString = strings[0];
        NSLog(@"%@",eString);
    }
    return 0;
}</code></pre>
</div>
<p>You&#8217;ll find that this (tiny) app will build and run just fine, even on a Mac running OS X 10.7. It just works! Magic!</p>
<p>Welp, that was a short blog post. Cheers!</p>
<h3>Not so fast, Bub.</h3>
<p>Nerds tend not to like magic. Oh, we love to see a good trick. But <em>things that we can&#8217;t explain</em> really tend to get under our skin.</p>
<p>&#8220;Now, Mikey,&#8221; you might ask, &#8220;what in tarnation is going on that makes this work?&#8221;</p>
<p>First, I&#8217;d laugh at you for using a word like &#8220;tarnation&#8221;. Then, I&#8217;d tell you a short story about a small library called <strong>ARCLite</strong>.</p>
<p>When ARC was first introduced, our minds were blown. We could feel years being added to our lives at the thought of not having to write <code>-retain</code> and <code>-release</code> calls anymore. Even better, it turned out that ARC was backward-compatible! But how?</p>
<p>Apple had provided a build <a href="http://en.wikipedia.org/wiki/Shim_(computing)">shim</a> in the form of a static library called libarclite. Xcode 4.2 and later knew to link against this library anytime you built a project with a deployment target of iOS 4 or Mac OS X 10.6 with ARC enabled. This library provides ARC support for older systems.</p>
<p>It turns out that the-little-lib-that-could has also taken up the torch of providing older systems with support for container subscripting, while also solving our technical problem above: libarclite provides implementations of <code>-objectAtIndexedSubscript:</code> and friends to the container classes on iOS 5 <em>without</em> replacing the implementations provided by iOS 6.</p>
<p>libarclite does this by waiting until runtime to decide whether or not to add the method, by first finding out whether the method already exists.</p>
<h3>Waiting until whattime?</h3>
<p>If you&#8217;ve ever <a href="http://www.mikeash.com/pyblog/friday-qa-2010-01-29-method-replacement-for-fun-and-profit.html">swizzled a method</a>, go ahead and move on. If you haven&#8217;t, you&#8217;ll want to be seated for this bit. We&#8217;re going to talk about the Objective-C runtime library, and use it to understand a bit about how Apple&#8217;s pulling off the feat of only adding a category method when it doesn&#8217;t already exist.</p>
<p>The Objective-C runtime is the beating heart of a Cocoa application. It&#8217;s the low-level bit that puts the &#8220;Objective&#8221; in Objective-C by teaching C how to be object-oriented. The runtime library is also almost completely <a href="http://www.opensource.apple.com/">open source</a>! We&#8217;re interested in one particular and integral header, however: <a href="http://www.opensource.apple.com/source/objc4/objc4-437/runtime/runtime.h">runtime.h</a>.</p>
<p>If you take a moment to browse this file, your imagination will start to run wild with possibilities. With these functions, you can define an entire class <em>after</em> your program has started running! There&#8217;s not really much practical use for such a thing (in our position), but when has that ever stopped us from trying? In fact, runtime class definition is how KVO works! But that could be a totally separate post.</p>
<p>There&#8217;s a specific function of interest to us in runtime.h:</p>
<pre><code>OBJC_EXPORT BOOL class_addMethod(Class cls, SEL name, IMP imp, const char *types)
</code></pre>
<p>This function allows you to attach to a class an entirely new method that didn&#8217;t appear in the class&#8217; header <em>or</em> implementation file. Of course, the method must be defined <em>somewhere</em> in your code, but this function allows you to attach it to a class that didn&#8217;t have it before.</p>
<p>The <code>class_addMethod()</code> function takes four parameters:</p>
<ul>
<li>a Class to which the method should be added, such as that returned by [NSString class]. Just as <code>@"Hello"</code> is an instance of type NSString*, NSString itself is of type Class.</li>
<li>a selector that names the method—yes, the same sort of selector that you use with NSTimer </li>
<li>a <a href="http://en.wikipedia.org/wiki/Function_pointer">function pointer</a> to the actual implementation of the method you wish to add, and </li>
<li>a C character array describing the types of arguments the method accepts</li>
</ul>
<p>The function returns a BOOL indicating the success or failure of the method addition. The function will fail and return NO if the target Class already has a method with the specified selector.</p>
<h3>So what now?</h3>
<p>How can we use <code>class_addMethod()</code> for ultimate science?</p>
<p>Let&#8217;s do it. Step zero? Import runtime.h so that we can use the functions declared there:</p>
<div>
<pre><code>#import &lt;objc/runtime.h&gt;</code></pre>
</div>
<p>First, we&#8217;ll go ahead and create our NSArray+Subscripting category, as we discussed at the beginning of the post:</p>
<div>
<pre><code>@implementation NSArray (Subscripting)

- (void)bnr_objectAtIndexedSubscript:(NSInteger)index
{
    return [self objectAtIndex:index];
}

@end</code></pre>
</div>
<p>You&#8217;ll notice immediately that I&#8217;ve changed the name of the subscripting method. Remember that if I&#8217;d named it:</p>
<pre><code>- (void)objectAtIndexedSubscript:(NSInteger)index
</code></pre>
<p>then this method would be installed on NSArray as is, regardless of the OS version. We don&#8217;t want that, so we define the method using a fake/temporary name.</p>
<p>For this same reason, we should always namespace our category methods like this (prefixing the method name with an identifier of some sort, such as bnr_ above) so that we don&#8217;t <em>accidentally</em> replace methods that we didn&#8217;t even know existed.</p>
<p>The second step is to find a place to put our call to <code>class_addMethod()</code>. We want to implement or override a method that we know will execute very early in an application run.</p>
<p>When an application launches, one of the very first things that happens (even before <code>main()</code> is called!) is that each class that the application will use is loaded into the runtime. Each class is sent the <code>+load</code> message (and, because it&#8217;s special and doesn&#8217;t play by the usual rules, to each category on each class). This is a dangerous place for most types of activity, but it&#8217;s the perfect place to make changes to the runtime. That&#8217;s not to say that making runtime changes is always safe, mind you.</p>
<p>So, here&#8217;s our NSArray+Subscripting.m:</p>
<div>
<pre><code>#import "NSArray+Subscripting.h"
#import &lt;objc/runtime.h&gt;

@implementation NSArray (Subscripting)

+ (void)load
{
    class_addMethod([NSArray class],
                @selector(objectAtIndexedSubscript:),
                method_getImplementation(bnr_objectAtIndexedSubscript:),
                method_getTypeEncoding(bnr_objectAtIndexedSubscript:)
                );
}

- (void)bnr_objectAtIndexedSubscript:(NSInteger)index
{
    return [self objectAtIndex:index];
}

@end</code></pre>
</div>
<p>There are some fantastic bits at work here. First, <code>class_addMethod()</code> will fail if a method already exists with the passed-in selector. Second, arguments that initially looked incredibly daunting when we saw this function&#8217;s declaration (what on earth is an IMP or a type encoding?) are satisfied by calling <em>other</em> runtime functions from runtime.h! It feels like cheating!</p>
<p>I challenge you now to spend some time looking through the documentation for the various functions in runtime.h, and experimenting on your own.</p>
<h3>Excellent, so this is all I need to get subscripting in iOS 5?</h3>
<p>Not so fast. Remember, Apple is already doing this (or something like it) for you with libarclite! We&#8217;ve meandered down the runtime&#8217;s rabbit-hole as an exercise in pulling away the magic curtains, as it were.</p>
<p>There are certainly plenty of runtime hacks at varying levels of evil and danger that you may find useful in your own application, but this one&#8217;s already been done for you.</p>
<p>If you&#8217;re interested in learning more about the Objective-C runtime and its dark secrets, sound off in the comments.</p>
<p>Also, check out these excellent resources: *</p>
<ul>
<li><a href="http://www.mikeash.com/pyblog/">Mike Ash&#8217;s Friday Q&amp;A</a> (particularly his article on <a href="http://www.mikeash.com/pyblog/friday-qa-2010-01-29-method-replacement-for-fun-and-profit.html">method swizzling</a>)</li>
<li><a href="http://cocoasamurai.blogspot.com/2010/01/understanding-objective-c-runtime.html">Colin Wheeler&#8217;s excellent and deep treatise on the runtime</a></li>
</ul>
<p>The post <a href="http://blog.bignerdranch.com/2813-illuminating-arclite/">Illuminating ARCLite</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2813-illuminating-arclite/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Exploring SlidingPaneLayout</title>
		<link>http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/</link>
		<comments>http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/#comments</comments>
		<pubDate>Mon, 20 May 2013 20:59:14 +0000</pubDate>
		<dc:creator>Chris Stewart</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2765</guid>
		<description><![CDATA[<p><p>Android developers spend a lot of time developing tablet versions of their applications.</p>
<p>OK, maybe they don’t, which is probably why there was a big push at <a href="https://developers.google.com/events/io/">Google I/O</a> this year for developers to optimize their apps for devices larger than phones.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/">Exploring SlidingPaneLayout</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>Android developers spend a lot of time developing tablet versions of their applications.</p>
<p>OK, maybe they don’t, which is probably why there was a big push at <a href="https://developers.google.com/events/io/">Google I/O</a> this year for developers to optimize their apps for devices larger than phones. Google even announced a featured section of the Google Play Store for tablet-optimized apps. Of course, Android developers have powerful tools that can be used to create applications that gracefully scale to different screen sizes. Last week, Google added another tool to our arsenal: SlidingPaneLayout.</p>
<h3>Sliding What?</h3>
<p>You may have seen the new Hangouts application released last week. This app is designed around the <a href="http://developer.android.com/reference/android/support/v4/widget/SlidingPaneLayout.html">SlidingPaneLayout</a>, which is a new addition to the support library.</p>
<p><a href="http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/hangouts-landscape/" rel="attachment wp-att-2767"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/hangouts-landscape.png" alt="" width="512" height="320" class="aligncenter size-full wp-image-2767" /></a></p>
<p><a href="http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/hangouts-portrait/" rel="attachment wp-att-2768"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/hangouts-portrait.png" alt="" width="320" height="512" class="aligncenter size-full wp-image-2768" /></a></p>
<p>A SlidingPaneLayout consists of two panes: the master pane and the detail pane. In the Hangouts application, the master pane contains a list of ongoing hangouts and the detail pane contains the actual hangout conversation. Selecting an item in the master pane will update the detail pane.</p>
<p>The really cool thing about SlidingPaneLayout is that the rightmost pane, the detail pane, can be dragged horizontally to uncover the master pane below. On a screen that is large enough to display both panes, the user will see both simultaneously. On a small screen, the user will see a single pane at a time and can slide the detail pane to reveal the master pane.</p>
<h3>I’m Sold, How Does It Work?</h3>
<p>Good news! SlidingPaneLayout is incredibly easy to use. SlidingPaneLayout is a ViewGroup, so it is designed to contain child views. However, this particular ViewGroup is intended to have only two children. To make use of this Layout, simply add its tag to your layout XML file for an Activity:</p>
<pre>&lt;android.support.v4.widget.SlidingPaneLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" &gt;

    &lt;textview android:layout_width="250dp"
        android:layout_height="match_parent"
        android:background="#CC00FF00"
        android:text="Pane 1" /&gt;

    &lt;textview android:layout_width="400dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#CC0000FF"
        android:text="Pane 2" /&gt;
&lt;/android.support.v4.widget.SlidingPaneLayout&gt;</pre>
<p>That’s it. You are now using SlidingPaneLayout and you have a tablet-optimized app!</p>
<p><a href="http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/device-2013-05-19-202459/" rel="attachment wp-att-2770"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/device-2013-05-19-202459-1024x640.png" alt="" width="80%" height="80%" class="aligncenter size-large wp-image-2770" /></a></p>
<p><a href="http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/device-2013-05-19-202417/" rel="attachment wp-att-2771"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/device-2013-05-19-202417-614x1024.png" alt="" width="55%" height="55%" class="aligncenter size-large wp-image-2771" /></a></p>
<h3>There Must Be More</h3>
<p>Of course, a real app would have something more complex than two TextViews in each of the panes. Fragments would be a great fit here.</p>
<p>A master Fragment and a detail Fragment could be used, and would encapsulate all of your app’s custom controller code into reusable classes. If requirements change and you decide to do things the old-fashioned way (without SlidingPaneLayout), you would have to change only the Activity that is hosting your Fragments, not the Fragments themselves.</p>
<h3>The Catch</h3>
<p>As you would expect, SlidingPaneLayout works just fine with Fragments. I highly recommend using a Fragment for each of the panes.</p>
<p>However, there is one problem. Options menus (the items that show up in the Action Bar or when hitting the menu hardware button on some devices) do not work correctly. Since the SlidingPaneLayout is just a ViewGroup, it is not in control of the options menu and the user will always see the menu items from both fragments, even when you&#8217;re looking at just a single pane.</p>
<p>In an ideal world, I would like to see the SlidingPaneLayout show only the options items that are available for the currently selected Fragment in the layout (of course, seeing menu items for both fragments is fine, if the user is on a device that is large enough to show both panes). Obviously, there are ways to implement this yourself, but it does require a little extra work. The Hangouts application is clearly doing that extra work to update the options menu and the rest of the Action Bar when panes become selected.</p>
<h3>What’s The Verdict?</h3>
<p>SlidingPaneLayout is not a natural fit for all applications, and it’s certainly not a replacement for the new Navigation Drawer paradigm. It is a handy Layout, though, especially when creating applications that work well on any size device. Of course, there are downsides, like the Fragment options menu problem from above. SlidingPaneLayout is also marked as experimental in the documentation, so its future is uncertain. Like ViewPager, though, this will cause a problem only if/when you decide to update to a new version of the support library.</p>
<p>I’m excited to see the Android team take components that they use internally and encourage developers to include them in their own apps. Components like these as well as those contributed by other Android developers allow us to make better Android apps with less work.</p>
<p>The post <a href="http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/">Exploring SlidingPaneLayout</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2765-exploring-slidingpanelayout/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Leveling Up</title>
		<link>http://blog.bignerdranch.com/2753-leveling-up/</link>
		<comments>http://blog.bignerdranch.com/2753-leveling-up/#comments</comments>
		<pubDate>Fri, 17 May 2013 20:45:05 +0000</pubDate>
		<dc:creator>Mark Dalrymple</dc:creator>
				<category><![CDATA[C Stuff]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Nerd Skills]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2753</guid>
		<description><![CDATA[<p><p>So.  That Clash of the Coders <a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/">Thing</a>.  Kind of nice being able to flex mental muscles over a 72-hour sleep-deprived Dr Pepper-infused period of time, performing acts of violence upon the Objective-C runtime, <code>UIApplication</code>, and the layer stack.  It was a blast being able to use all my platform knowledge with the express purpose of subverting it.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2753-leveling-up/">Leveling Up</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>So.  That Clash of the Coders <a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/">Thing</a>.  Kind of nice being able to flex mental muscles over a 72-hour sleep-deprived Dr Pepper-infused period of time, performing acts of violence upon the Objective-C runtime, <code>UIApplication</code>, and the layer stack.  It was a blast being able to use all my platform knowledge with the express purpose of subverting it.</p>
<p>I was chatting with one of my Ranch cohorts the other day. He said, &#8220;Hey MarkD, how do I learn all those details?  I feel like I&#8217;m kind of stuck in limbo land, just using tableviews and whatnot.&#8221;  Talk about a daunting question. Especially coming from an engineer of considerable skill.  &#8220;Uh, you just do stuff?&#8221; isn&#8217;t a good answer.</p>
<p>I&#8217;ve been programming professionally (that is, actually making a living at it) for 23 years now. That&#8217;s longer than some of my coworkers have been alive.  That&#8217;s a scary thought.  Get off my lawn.  Over the years I&#8217;ve fallen into a style of learning and exploration that&#8217;s paid some pretty good dividends.  Of course, everyone is different, but here&#8217;s how I would answer his question.</p>
<h3>Read</h3>
<p>Read a lot.  Throw information at your brain.  There are a lot of books and blogs out there, especially compared to the old days when all of the Mac programming books would fit on a single shelf in a small IKEA bookcase.   My favorite book of the moment is Rob Napier and Mugunth Kumar&#8217;s <a href="http://www.amazon.com/iOS-Programming-Pushing-Limits-Application/dp/1118449959">iOS 6: Pushing The Limits</a>.  I also must pimp <a href="http://www.bignerdranch.com/book/advanced_mac_os_x_programming_rd_edition_">Advanced Mac OS X Programming : The Big Nerd Ranch Guide</a> because it digs into some of the lower-level details of OS X, many of which apply to iOS too. Don&#8217;t forget Amit Singh&#8217;s massive <a href="http://www.amazon.com/Mac-OS-Internals-Systems-Approach/dp/0321278542/)">OS X Internals book</a> (The ebook version will make your Kindle heavier).  Some parts are out of date, but it&#8217;s fascinating the kinds of details a real-live operating system kernel takes care of.</p>
<p>We live in a wealth of information online was well.  In addition to this humble weblog, you should be reading Mike Ash&#8217;s <a href="http://www.mikeash.com/pyblog/">NSBlog</a>.  I also regularly read <a href="http://nshipster.com">NSHipster</a> and fellow rancher <a href="http://jeremywsherman.com">Jeremy W. Sherman&#8217;s</a> blog.</p>
<p>Don&#8217;t forget to read the official documentation.  Browse the Cocoa / UIKit docs in Xcode.  I have <a href="https://github.com/omz/DocSets-for-iOS">DocSets</a> on my iPad so I can skim stuff while I&#8217;m waiting for something.  Don&#8217;t limit yourself to the classes that you use all the time.  Spend all your time in <code>NSTableView</code>?  Give <a href="http://developer.apple.com/library/mac/#documentation/Kernel/Reference/IOService_reference/translated_content/IOService.html">IOService</a> a read.  You&#8217;ll probably never use it, but maybe you&#8217;ll find some topic that&#8217;ll inspire further learning.</p>
<p>I try to read through the compiler and debugger docs on a regular basis.  <a href="http://www.gnu.org/software/gdb/documentation/">gdb</a> is well documented.  gdb is still relevant these days &#8211; lldb is still somewhat unreliable running on a device.  The <a href="http://lldb.llvm.org">lldb</a>  website has some supporting documentation, so check its built-in help to learn all the available commands.  Be sure to <a href="http://blog.bignerdranch.com/wp-content/uploads/2013/05/read-all-the-things.jpg">read all the things</a>.  If you see an esoteric feature, try to figure out why it exists.</p>
<p>The lowdown on the compiler can be found at <a href="http://clang.llvm.org">http://clang.llvm.org</a>. Don&#8217;t forget the <a href="http://blog.bignerdranch.com/2490-spelunkhead/">header files</a> too.  There&#8217;s lots of useful information are buried in them.</p>
<p>I don&#8217;t remember everything.  I don&#8217;t remember most anything these days.  But I do retain shadows of &#8220;I think I read something like this before.  Now where was it.&#8221; and a little cogitation reminds me &#8220;oh yeah, Jeremy blogged about his reimplementation of all of Cocoa in 12 lines of code, and he had a cool higher-order-messaging category that might turn out to be useful.&#8221;</p>
<h3>Dissect</h3>
<p>To learn how things work, I like to see how things work.  Knowing who-calls-whom can be illuminating. &#8220;Who is creating this undo manager?&#8221; was the key to solving a <a href="http://blog.bignerdranch.com/2031-hooked-on-dtrace-part-3/">program bug</a>.  Maybe seeing the notifications that fly around an app can help you discover what <code>MPMusicPlayerController</code> is doing when it moves from song to song in a playlist.</p>
<p>We have a lot of really powerful tools to peek into our programs and libraries. You probably won&#8217;t use every one of them every day.  Some you might only use once a month or once a quarter, but they&#8217;re good to have in your utility belt.</p>
<p><strong>The source</strong>:  The source to <code>clang</code> and <code>lldb</code> are easily obtained, so you can download them and build them.  Have a question about how something works in the language?  Poke around the source and see if you can find it.  You can also get a decent subset of the Core Foundation source (amongst a lot of other stuff) at <a href="http://www.opensource.apple.com">http://www.opensource.apple.com</a>.  The really interesting parts are &#8220;xnu&#8221;- the kernel, &#8220;CF&#8221; &#8211; Core Foundation, and objc &#8211; the objective-C runtime.  Also, dig through the Cocoa headers and find something you might not understand, like <code>NSAssert</code>.  Then figure out what makes it work.</p>
<p><strong>The debugger</strong>: You can place breakpoints on any <a href="http://blog.bignerdranch.com/2628-static-cling/">visible symbol</a>, whether it&#8217;s your own code where you have file and line information, or functions and methods inside of binary-only libraries.  You can enter breakpoints directly in Xcode by adding a &#8220;symbolic breakpoint&#8221;.  Here&#8217;s one I added that will break on a private method in UIApplication called <code>_performMemoryWarning</code>:</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/perform-memory-warning.png" alt="Perform memory warning" title="perform-memory-warning.png" border="0" width="542" height="220" /></p>
<p>You can trigger a memory warning in the simulator and see that it gets handled:</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/memory-warning-stack.png" alt="Memory warning stack" title="memory-warning-stack.png" border="0" width="726" height="129" /></p>
<p><strong>Notification spying</strong>: <a href="http://blog.bignerdranch.com/726-notifications-part-1-registering-and-posting/">Notifications</a> are a common way of decoupling code. Something interesting happens and a notification gets posted.  <code>NSNotificationCenter</code> and friends are so convenient that pretty much everything uses it.  You can add a <a href="http://blog.bignerdranch.com/729-notifications-part-2-handling-and-spying/">notification spy</a> to print out all notifications that float by.</p>
<p><strong>DTrace</strong>: I know folks wish I&#8217;d <a href="http://blog.bignerdranch.com/1907-hooked-on-dtrace-part-1/">stop</a> <a href="http://blog.bignerdranch.com/1968-hooked-on-dtrace-part-2/">talking</a> <a href="http://blog.bignerdranch.com/2031-hooked-on-dtrace-part-3/">about</a> <a href="http://blog.bignerdranch.com/2150-hooked-on-dtrace-part-4/">DTrace</a>. How did I find that <code>_performMemoryWarning</code> symbol?  It&#8217;s obviously not in any of Apple&#8217;s documentation, with that leading underscore being the giant &#8220;this is Private API&#8221; hands-off flag.  I DTraced a program in the simulator, triggered a memory warning, and saw what was happening.  During Clash I wanted to answer some other questions too, like &#8220;where did UITouches get created and dispatched?&#8221; and &#8220;what actually hits the file system when loading a nib file?&#8221;.  Thus was born a little utility script, spy.d (available <a href="https://gist.github.com/markd2/5596426">at this gist</a>).</p>
<p>spy.d is a simple script that traces Objective-C messages using the objc provider, ignoring messages on a list of common messages, and displaying full stack traces for methods on an &#8220;especially interesting&#8221; message list.  I ran spy.d and triggered a memory warning in the simulator:</p>
<pre># ./spy.d  61271
...
UIApplication -didReceiveMemoryWarning
NSNotificationCenter +defaultCenter
NSNotificationCenter -postNotificationName:object:
...
UIImage(UIImageInternal) +_flushCache:
UIViewController +_traverseViewControllerHierarchyWithDelayedRelease:
UIViewController -didReceiveMemoryWarning
UIViewController -_traverseViewControllerHierarchyFromLevel:withBlock:
RMScheduleVC -didReceiveMemoryWarning</pre>
<p><code>UIApplication</code> gets the memory warning.  It posts a notification.  UIImage flushes its cache in response.  Then <code>UIViewController's</code> class method walks the controller hierarchy and tells each one that it received a memory warning, and then it bubbles down to my code in <code>RMScheduleVC</code>.</p>
<p><strong>class-dump</strong>: The Objective-C runtime is very rich in metadata.  You can, at runtime, poke around classes and their methods and find all sorts of cool toys to play with.  That information is actually stored in the application binary (and object files, and libraries), and can be extracted.  Steve Nygard&#8217;s <a href="http://stevenygard.com/projects/class-dump/">class-dump</a> will extract this metadata and generate <code>@interfaces</code> for all the classes it finds.  For example, from <code>UIApplication</code>:</p>
<pre>...
- (void)_purgeSharedInstances;
- (void)setReceivesMemoryWarnings:(BOOL)arg1;
- (void)_receivedMemoryNotification;
- (void)didReceiveMemoryWarning;
- (void)_performMemoryWarning;
- (BOOL)_isHandlingMemoryWarning;
- (void)_processScriptEvent:(struct __GSEvent *)arg1;
- (void)_dumpScreenContents:(struct __GSEvent *)arg1;
- (void)_dumpUIHierarchy:(struct __GSEvent *)arg1;
- (void)setSystemVolumeHUDEnabled:(BOOL)arg1;
...</pre>
<p>There&#8217;s all sorts of fun stuff going on.  These are places you can put breakpoints and poke around the call stack.  You can also dig into the implementation, too.</p>
<p><strong>Hopper Disassembler:</strong> The <a href="http://www.hopperapp.com">Hopper Disassembler</a> is a tool that reads object code and displays the corresponding assembly language.  Here it is looking at UIKit, the method implementation of <code>_performMemoryWarning</code> on <code>UIApplication</code>:</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/memory-warning-disassembly.png" alt="Memory warning disassembly" title="memory-warning-disassembly.png" border="0" width="742" height="255" />?</p>
<p>What&#8217;s neat is Hopper can convert the assembly to pseudo code so you can better suss out the code flow.</p>
<p><img style="display:block; margin-left:auto; margin-right:auto;" src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/memory-warning-pseudocode.png" alt="Memory warning pseudocode" title="memory-warning-pseudocode.png" border="0" width="1070" height="397" /></p>
<p>It&#8217;s also a neat way to learn an assembly language by example. Be warned you&#8217;ll be looking at code generated by a compiler, so it might not make a lot of sense at times when things get optimized.</p>
<p><strong>Instruments</strong>: Instruments isn&#8217;t just for finding performance problems.  It can be used to find locations in all the program&#8217;s code, both the code you wrote and the code from libraries, that you can start attacking with other tools.  Wondering how <code>UISlider</code> does its live tracking?  Point Instruments at an app with a slider, move it around for 10 seconds, and then see what&#8217;s at the top of the call stack. Then you can start applying DTrace in the simulator, or disassembling, and see what&#8217;s going on.</p>
<p><em>Just a quick warning</em> &#8211; be very careful how you apply information you learn from these tools.  They&#8217;re great for debugging and figuring out how things work.  Relying on implementation details and private API in the stuff you ship can lead to fragile software that breaks with major or minor OS releases.  If you&#8217;re shipping software to paying customers, or customers are using your software for non-trivial things, you are a professional programmer.  Be sure to act like one.</p>
<h3>Experiment</h3>
<p>Now that you have a fleet of tools, it&#8217;s time to learn stuff.  I learn best by <a href="http://blog.bignerdranch.com/1722-experimentally-yours/">actually doing</a>.  Get dirty and make mistakes!  Interested in learning <code>UITableView</code> in depth?  Write a bunch of table view code.  Browse the docs. Look at the header for API you might not have used before, and use it and see what happens.  Read some blogs.  Class-dump it and look for some intriguing private API and see if you can trigger it from the regular interface.  DTrace it and see the flow of messages.  Add the notification spy and see what the toolkit is trying to tell you.  If something doesn&#8217;t work, apply your usual debugging techniques and figure out why it&#8217;s not working.  See if you can re-implement it yourself.</p>
<p>I tend to play around in the world of code below UIKit / AppKit, so I write a lot of little programs that exercise some data structure or <a href="http://blog.bignerdranch.com/995-tiny-programs-the-atomic-edition/">language feature</a>.  Steve Sparks, my partner in Clash Crime, has his Playgrounder, an Xcode project with tab views and navigation controllers where he can throw a new experiment in there at any time.  Want to muck around with some UIScrollView violence?  Toss in a new view controller, hook it up, and now you can play with it in the simulator or on a device.  Keep it under <a href="http://blog.bignerdranch.com/1239-you-need-source-code-control-now/">source code control</a> and you can have a record of all of your experiments.</p>
<h3>Assimilate</h3>
<p>You decided on something to learn.  You&#8217;ve written a bunch of code.  You&#8217;ve debugged.  Maybe you&#8217;ve taken <a href="http://blog.bignerdranch.com/908-adventures-in-debugging-keeping-a-log/">a lot of notes</a>.  Now it&#8217;s time to let it all digest. Sleep on it. Take a bike ride. Go take an hour-long shower.  Let all the new stuff you&#8217;ve exposed yourself to settle into patterns.  See if you can build abstractions from those patterns, and apply them to other classes.  Much of software development these days can be mechanical &#8211; there&#8217;s a set of features that need to be implemented, and a usual set of classes you glue together.</p>
<p>This assimilation step is where the real fun starts happening as your brain starts building relationships.  Many of the examples here came out of a simple question that came up while working on our Clash entry: &#8220;We want to trigger memory warnings in the app on-demand&#8221;, to help debug memory and caching problems.  The investigation process went like this:</p>
<ul>
<li> We can trigger memory warnings in the simulator
</li>
<li> Use the notification spy to see if there&#8217;s notifications that fly by.  Why yes there are.  We can hook into that and respond to them.
</li>
<li> Posting the notification didn&#8217;t actually trigger stuff.  Bummer.  I wonder why.
</li>
<li> What methods are getting triggered?  Use <code>spy.d</code> and see what&#8217;s happening.  Oh look, <code>_performMemoryWarning</code> looks pretty interesting.
</li>
<li> Are there other memory warning methods I might look at? Pull out <code>class-dump</code> and see what&#8217;s there.
</li>
<li> Sending <code>_performMemoryWarning</code> to the current <code>UIApplication</code> instance seems to kick in all the memory warning machinery.  Why didn&#8217;t posting the notification?
</li>
<li> Just for fun, fire up Hopper and see what it&#8217;s actually doing.  Oh look, it has that view controller hierarchy and sqlite thing, which don&#8217;t get hit just by posting the memory notification.
</li>
<li> Add a memory warning trigger button to the debugging console, wrapped in an <code>#if</code> block to prevent it from getting released to the world.
</li>
</ul>
<h3>Integration By Parts</h3>
<p>And that&#8217;s pretty much my secret strategy to honing my nerdskills:</p>
<ul>
<li> Read &#8211; Throw a lot of facts at the brain.  Some may stick.  I find that kind of stuff fun to read, so it&#8217;s an enjoyable pastime.
</li>
<li> Dissect &#8211; Get comfortable with a wide range of tools, from high to low level, and don&#8217;t be afraid to use them.  And don&#8217;t be afraid to use them in weird ways.  DTrace can be a big hammer.  But sometimes you can smash a bug into tiny little pieces with it.  Use these tools to dig into software to see how it works.  Promise you will use this knowledge for good, not evil.
</li>
<li> Experiment &#8211; Write code.  Write a lot of code.  Experiment.  Play with all the new found toys.  Tease out the patterns.
</li>
<li> Assimilate &#8211; Reflect.  Lather, rinse, repeat.  Then keep doing it for the next twenty years.  Building deep skills is a long-term work in progress.
</li>
</ul>
<p>The post <a href="http://blog.bignerdranch.com/2753-leveling-up/">Leveling Up</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2753-leveling-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google I/O: Lots Of Android Love</title>
		<link>http://blog.bignerdranch.com/2732-google-io-lots-of-android-love/</link>
		<comments>http://blog.bignerdranch.com/2732-google-io-lots-of-android-love/#comments</comments>
		<pubDate>Thu, 16 May 2013 21:00:38 +0000</pubDate>
		<dc:creator>Bill Phllips</dc:creator>
				<category><![CDATA[Android]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2732</guid>
		<description><![CDATA[<p><p>Have you ever sat through a three-hour presentation? Has anyone ever even <em>asked</em> you to?</p>
<p>Well, yesterday morning my colleague <a href="http://www.bignerdranch.com/about_us/nerds/chris_stewart">Chris Stewart</a> and I walked down to <a href="https://developers.google.com/events/io/">Google I/O</a> and waited in line for the privilege of doing just that. No doubt you&#8217;ve seen a lot of talk about the many announcements they packed into this beast of a session.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2732-google-io-lots-of-android-love/">Google I/O: Lots Of Android Love</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>Have you ever sat through a three-hour presentation? Has anyone ever even <em>asked</em> you to?</p>
<p>Well, yesterday morning my colleague <a href="http://www.bignerdranch.com/about_us/nerds/chris_stewart">Chris Stewart</a> and I walked down to <a href="https://developers.google.com/events/io/">Google I/O</a> and waited in line for the privilege of doing just that. No doubt you&#8217;ve seen a lot of talk about the many announcements they packed into this beast of a session. Thirty minutes into the Android portion, though, I was already leaning over to Chris and saying: &#8220;We&#8217;re going to have to write a blog post about this stuff.&#8221;</p>
<p>Oh, you didn&#8217;t see anything exciting? You weren&#8217;t looking with the right rose-colored shades on, then. As Android developers, we saw major movements in some fundamental problem areas within our ecosystem.</p>
<h3>Doubling Down on Libraries</h3>
<p>The first shift is more in what we conspicuously <em>didn&#8217;t</em> see yesterday: a new version of Android. And yet we got a bunch of new APIs! What&#8217;s up with that?</p>
<p>This is something I have been talking about more and more in my classes: these days, the version of Android you&#8217;re programming against matters very little. You can see this idea throughout our <a href="http://www.bignerdranch.com/book/android_the_big_nerd_ranch_guide">Android Programming Guide</a>, too.</p>
<p>It was a slow process getting here, a process that started tentatively a couple of years back with the introduction of the support library, and continued with community acceptance of cross-version libraries like <a href="http://actionbarsherlock.com/">ActionBarSherlock</a>. Slowly but surely, these libraries have become the focus of mainstream app development.</p>
<p>Well, now we have reached the point where Google actually prefers introducing new APIs outside of a minor version release. The new Maps API, the new Locations API (!), cross-platform single sign-on, games services, the new slider drawer in the support library—all of this, and no new version of Android. No doubt we&#8217;ll see more revisions of Android, but don&#8217;t be surprised if the exciting API and tools action happens elsewhere.</p>
<h3>Nifty External Libraries</h3>
<p>That has an interesting consequence: technically, third-party libraries are standing on the same ground as the latest hotness from Google itself. As a result, the Android ecosystem is shaping up to look more like the Ruby community than the iOS community, relying more on an array of third-party libraries than solely on code coming out of Mountain View. Even now, a baseline, best-practices Android app at square one includes a raft of third-party libraries like event buses and ABS.</p>
<p>The most interesting talk I saw yesterday was actually exactly that—a third-party library. Granted, it came from Google, but it is not part of the standard library. <a href="https://developers.google.com/live/shows/474338138/">Volley</a> is an asynchronous networking and caching library, meant to replace ad hoc solutions stitched together out of HttpClient, HttpURLConnection, AsyncTask, HandlerThread or others.</p>
<p>Can you write an app without a library like this? Yes, you can. Would you ever want to? Other unnamed platforms <em>(ahem)</em> include asynchronous magic like this as part of the core APIs. They&#8217;re not part of the core for us yet, but in our own practice we should treat them as close to fundamental.</p>
<h3>So Long, Eclipse</h3>
<p>I would not be surprised if the importance of third-party libraries motivated the most eye-catching bit of news we saw: <a href="http://developer.android.com/sdk/installing/studio.html">Android Studio</a>, the new IDE from the Android tools team.</p>
<p>Managing third-party libraries is not pleasant in Eclipse. Out of the box, there&#8217;s no declarative way of saying what your dependencies are and where to get them. Maven does this, but it does not integrate very well with Eclipse.</p>
<p>The headlines are calling this the &#8220;Android Studio IDE,&#8221; but don&#8217;t be fooled—this is more about moving away from Eclipse, and towards IntelliJ. IntelliJ handles maven better than Eclipse does right now, but it&#8217;s also free of the years of cruft Eclipse has accumulated.</p>
<p>It looks like this lack of cruft has allowed the Android team to move more quickly than they have in the past. So if Android Studio looks more like a dedicated Android IDE than ADT did, it will not be because the Android Tools team are suddenly more ambitious. It will be because they are able to get more done by extending IntelliJ than with Eclipse.</p>
<h3>What Now?</h3>
<p>So what do all these changes mean for you?</p>
<p>First, you should stay aware. So much development is happening outside of the core Android libraries that critical APIs are now coming from outside the core Android team and release cycle. So keep an eye on places like the <a href="http://android-developers.blogspot.com/">Android Developers Blog</a>, the <a href="http://corner.squareup.com/">Square blog</a>, and <a href="http://androiddevweekly.com/">#AndroidDev Weekly</a> to find out about the latest and greatest goings on.</p>
<p>And what about Android Studio? Well, don&#8217;t jump just yet. As of today, everything in our Android Programming Guide is still the right way to go. Android Studio is 0.1, so it&#8217;s not stable enough for day-to-day development. If you want to go ahead and switch to IntelliJ, go ahead and switch to the current community edition with Android support, but don&#8217;t feel compelled to do so. Eclipse support hasn&#8217;t been discontinued.</p>
<p>As small as these developments seem to a user, they are very exciting to me as a developer. Developing Android is steadily growing into its own peculiarly pleasant experience. Maybe for our next edition of our guide, we&#8217;ll have to replace our cover photo with one of those self-balancing unicycles.</p>
<p>The post <a href="http://blog.bignerdranch.com/2732-google-io-lots-of-android-love/">Google I/O: Lots Of Android Love</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2732-google-io-lots-of-android-love/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails Girls ATL: Building ideas</title>
		<link>http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/</link>
		<comments>http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/#comments</comments>
		<pubDate>Thu, 16 May 2013 00:43:32 +0000</pubDate>
		<dc:creator>Tasha Schroeder</dc:creator>
				<category><![CDATA[Atlanta]]></category>
		<category><![CDATA[Community]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=1302</guid>
		<description><![CDATA[<p><p>Last weekend, we hosted our second Rails Girls workshop, inviting 50 women to come to our office to learn more about web development through the lens of Ruby on Rails.</p>
<p>There were balloons.</p>
<p><a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/balloons/" rel="attachment wp-att-2716"></a></p>
<p>And there was coffee.</p>
<p><a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/coffee-2/" rel="attachment wp-att-2713"></a></p>
<p>But mostly, what we found was a group of smart, talented women.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/">Rails Girls ATL: Building ideas</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>Last weekend, we hosted our second Rails Girls workshop, inviting 50 women to come to our office to learn more about web development through the lens of Ruby on Rails.</p>
<p>There were balloons.</p>
<p><a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/balloons/" rel="attachment wp-att-2716"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/balloons.jpg" alt="" title="balloons" width= 80% height=80% class="aligncenter size-full wp-image-2716" /></a></p>
<p>And there was coffee.</p>
<p><a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/coffee-2/" rel="attachment wp-att-2713"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/coffee1.jpg" alt="" title="coffee" width=80% height=80% class="aligncenter size-full wp-image-2713" /></a></p>
<p>But mostly, what we found was a group of smart, talented women. Though the day is challenging, full of learning new concepts and trying new things, the workshop participants rose to the challenge and learned designing, prototyping and coding of their own web apps.</p>
<p>They also learned from the lightning talks given by members of the Ruby community, including one from Blithe Rocher, who attended our first Rails Girls workshop just last December and is now not only a coach, but also a Big Nerd Ranch intern.</p>
<p><a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/blithe/" rel="attachment wp-att-2723"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/Blithe.jpg" alt="" title="Blithe" width="529" height="397" class="aligncenter size-full wp-image-2723" /></a></p>
<p>We are grateful to be part of a community committed to helping others succeed. In addition to our volunteer speakers and coaches, we couldn&#8217;t have done it without our sponsors:</p>
<ul>
<li><a href="http://thephuse.com/">The Phuse</a> sponsored the installation party on Friday.</li>
<li><a href="http://www.backbonerails.com/">BackboneRails.com</a> treated our coaches to dinner.</li>
<li><a href="https://www.engineyard.com/">Engine Yard</a> was our materials sponsor, covering the costs of printed items and our mugs.</li>
<li><a href="http://rocketwhale.com/">Rocket Whale</a> provided Saturday&#8217;s breakfast.</li>
<li><a href="http://mailchimp.com/">MailChimp</a> sponsored lunch.</li>
<li><a href="http://octanecoffee.com/">Octane</a> donated espresso beans to keep us caffeinated.</li>
<li>Big Nerd Ranch not only hosted the event, but also sponsored the after-party.</li>
</ul>
<p><a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/ruby-girls-best-friend/" rel="attachment wp-att-2720"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/Ruby-girls-best-friend.jpg" alt="" title="Ruby-girls-best-friend" width=80% height=80% class="aligncenter size-full wp-image-2720" /></a></p>
<p>Want to be a part of our next workshop? Follow <a href="http://twitter.com/railsgirlsatl">@RailsGirlsATL</a> on Twitter and keep an eye on the Rails Girls ATL <a href="http://railsgirls.com/atl">website</a>.</p>
<p>The post <a href="http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/">Rails Girls ATL: Building ideas</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/1302-rails-girls-atl-building-ideas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design, Dignity and Doughnuts: My First 3 Months at the Ranch</title>
		<link>http://blog.bignerdranch.com/2699-design-dignity-and-doughnuts-my-first-three-months-at-the-ranch/</link>
		<comments>http://blog.bignerdranch.com/2699-design-dignity-and-doughnuts-my-first-three-months-at-the-ranch/#comments</comments>
		<pubDate>Tue, 14 May 2013 22:46:33 +0000</pubDate>
		<dc:creator>Jeff Heaton</dc:creator>
				<category><![CDATA[Culture]]></category>
		<category><![CDATA[Design]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2699</guid>
		<description><![CDATA[<p><p>My interview at Big Nerd Ranch was intense. I was in a room with glass on two sides, and anybody could look in. It quickly became crowded, with eight people in a room that fits four comfortably—and all focus was on me.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2699-design-dignity-and-doughnuts-my-first-three-months-at-the-ranch/">Design, Dignity and Doughnuts: My First 3 Months at the Ranch</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>My interview at Big Nerd Ranch was intense. I was in a room with glass on two sides, and anybody could look in. It quickly became crowded, with eight people in a room that fits four comfortably—and all focus was on me.</p>
<p>The interview was admittedly nerve wracking, as most are, but it is rare that the CEO drops in to ask a question or two. Or that candidates are evaluated for culture fit as well as their credentials. But afterward, I found this reassuring. I knew that that being a Nerd was taken seriously, because so many people took an interest.</p>
<p>I got the job as a mobile UX designer, and ninety days of design, dignity and doughnuts have flown by.</p>
<h3>Design</h3>
<p>While I had done design before starting at Big Nerd Ranch, it was never like this. The design team at Big Nerd Ranch is small but growing, so there’s a ton of flexibility as to what projects we’re on and what we get to delve into. We’re surrounded by extremely sharp developers who aren’t afraid to share their knowledge in order to make projects better. It&#8217;s been incredibly satisfying to combine UX, UI and visual principles with an agile approach to give deep consideration to everything we touch. We get to shape what design at Big Nerd Ranch means and spread the word that we’re open for business.</p>
<h3>Dignity</h3>
<p>We get our hands on amazing projects with customers who understand what it takes to make great products. A bias toward action and experimentation means that we can contribute to whatever we’re interested in, without fear. In fact, I think that’s part of the genius of Big Nerd Ranch: the removal of distractions. That focus enables people to establish flow in their lives.</p>
<p>As soon as I was made part of the team, I was trusted with responsibility and given the tools and time to rise to the occasion. I’ve been treated like an adult. I can work wherever and whenever I want as long as I get it done, and this has freed me to figure out how I work best. It’s fostered more experimentation in my life, and it’s inspiring.</p>
<h3>Doughnuts</h3>
<p>Doughnuts are simple pleasures: single-serving snacks in chewy yeast or crumbly cake. A dreary, rain-soaked Friday morning in April is no special occasion, but a few of us found reason to drive down the street and bring back a dozen or so doughnuts. And sharing little unexpected pleasures has pervaded my experience here. I can think of no better way to explain all the touches that make working here genuinely great. This level of comfort is hard won by those who have worked and continue to work to make Big Nerd Ranch what it is. I can only say thank you and do my best to contribute.</p>
<p>Three months has flown by. I left a group of friends to join Big Nerd Ranch and found so many new ones. I have a faint idea of what the future holds, but I’m confident that whatever it is will be faced properly, and with a bit of icing. Hopefully strawberry.</p>
<p>The post <a href="http://blog.bignerdranch.com/2699-design-dignity-and-doughnuts-my-first-three-months-at-the-ranch/">Design, Dignity and Doughnuts: My First 3 Months at the Ranch</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2699-design-dignity-and-doughnuts-my-first-three-months-at-the-ranch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Clash of the Coders 2013: Winners Announced</title>
		<link>http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/</link>
		<comments>http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/#comments</comments>
		<pubDate>Fri, 10 May 2013 19:00:22 +0000</pubDate>
		<dc:creator>Tasha Schroeder</dc:creator>
				<category><![CDATA[Clash of the Coders]]></category>
		<category><![CDATA[Craftsmanship]]></category>
		<category><![CDATA[Culture]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2650</guid>
		<description><![CDATA[<p><p>We recently held our second annual Clash of the Coders, a 72-hour app-building marathon where we test our technical prowess and compete for glory. &#8220;The winners are dangerously capable,&#8221; as Chief Learning Officer Aaron Hillegass says.</p>
<p>It was a very tough call, but Raisin&#8217; Elevens was the top team, with a project they named <a href="http://www.krendler.com/">Krëndler</a>.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/">Clash of the Coders 2013: Winners Announced</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>We recently held our second annual Clash of the Coders, a 72-hour app-building marathon where we test our technical prowess and compete for glory. &#8220;The winners are dangerously capable,&#8221; as Chief Learning Officer Aaron Hillegass says.</p>
<p>It was a very tough call, but Raisin&#8217; Elevens was the top team, with a project they named <a href="http://www.krendler.com/">Krëndler</a>. Team members <a href="http://www.bignerdranch.com/about_us/nerds/mark_dalrymple">Mark Dalrymple</a>, <a href="http://www.bignerdranch.com/about_us/nerds/gregg_rothmeier">Gregg Rothmeier</a> and <a href="http://www.bignerdranch.com/about_us/nerds/steve_sparks">Steve Sparks</a> took home the trophy and some pretty sweet prizes. They were followed by team Daedalus (Eric Jeffers, Darren Pottinger and Chris Stewart) and The Wynners (the prescient Brian Hardy, Zac Stewart and Paul Turner).</p>
<p>We knew you&#8217;d want the nitty-gritty from the top team, so we asked them a few questions.</p>
<hr />
<p><strong>NerdBlog: What did you build?</strong> <br />Raisin&#8217; Elevens: We built a toolkit that developers can drop into their applications and invoke on demand to help explore their application as it is running. Kind of like do-it-yourself endoscopic surgery. It&#8217;s a generic framework upon which we built some specific tools:</p>
<ul>
<li>View hierarchy visualization </li>
<li>Built-in console viewer </li>
<li>Tap/screenshot recording and playback (You can see what the user is doing to your app, not only where they&#8217;re tapping and dragging, but how quickly—or slowly—they&#8217;re doing it.) </li>
<li>Forced memory warnings</li>
<li>App kill</li>
<li>Cloud support: Data is sent to a web service for archiving, processing and analysis off the device. The device log, notifications and touch tracks are correlated, letting you see where real users are having difficulty with your app.</li>
</ul>
<p>We had a lot of ideas for features, the end result of which is essentially a web-based remote debugger for developers.</p>
<p><strong>NB: That&#8217;s really impressive! Where did the idea come from?</strong><br />RE: Chris Aquino showed us a feature in Firefox that allows you to visualize HTML layers in 3D, which is a really cool developer tool. Steve of course wanted it in his own apps. A few weeks later, he was working on a client app that required view scaling and discovered the CATransform3D API. Immediately the visual hack jumped to mind.</p>
<p>He created a test project, morphed some views and knew he&#8217;d found his Clash project. He immediately turned to Mark, and we came up with the team name effortlessly and right away.</p>
<p><strong>NB: We&#8217;ll bite. What&#8217;s the story behind the team name?</strong><br />RE: As part of the ground rules, Aaron stipulated, &#8220;Your team will need an amusing or terrifying name.&#8221;</p>
<p>We&#8217;re not much for self-aggrandizement, feeling that actions speak louder than words ever can, so we wanted something beyond &#8220;CODE KRUSHERS.&#8221; We also like self-deprecation, so we were thinking something along the lines of &#8220;We are Team Adequate and we crash a lot.&#8221; Then Steve made the connection between the Unix signal for a segmentation violation (signal 11), which you can send to yourself by using the raise function. So Raisin&#8217; Elevens is basically us crashing due to pointer errors. Also, eleven is a magic number thanks to Spinal Tap, so the team name was born.</p>
<p>In the course of making Krëndler, we raised a lot of elevens, and not all intentionally. In fact, our &#8220;terminate the program rather than background it&#8221; feature raises eleven:</p>
<p><a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/raise-11/" rel="attachment wp-att-2655"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/raise-11.png" alt="" title="raise 11" width="466" height="86" class="aligncenter size-full wp-image-2655" /></a></p>
<p><strong>NB: You&#8217;re two iOS developers and a Ruby developer. Why did you team up?</strong><br />RE: Mark and Steve were giddy about having web-based recording and playback of touches in iOS, so they reached out to Gregg. He had great ideas and suggestions, as well as thoughts about how stuff on the iOS side could be transmitted to the Rails side. He had a JSON schema already sketched out before we wrote a single line of code, so we hit the ground running.</p>
<p><strong>How did you overcome the challenges of being in different locations?</strong><br />RE: We were aided by a few things. Working remotely is already such a core part of our workflow that we were used to using technology to bridge the distance. Before we started, we created a Google doc for our list of ideas and had our goals and expectations clearly laid out. We used Google hangouts for face-to-face meetings, and our Campfire room was the war room. Campfire maintains a transcript even when you&#8217;re not signed on, so we could leave questions for another who might be offline.</p>
<p>To celebrate major milestones, we sent images and screen recordings, like this morph of <a href="http://eclicker.com">eClicker</a>:</p>
<p><a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/krendler/" rel="attachment wp-att-2662"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/krendler.png" alt="" title="krendler" width="70%" height="70%" class="aligncenter wp-image-2662" /></a></p>
<p>And most importantly, we trusted one another. This is a huge part of the work we already do at Big Nerd Ranch, but it was key for a hackathon like this. We each needed to be able to trust that the others would go off and do their thing, and come back with good, working code. We could make big changes and add features without micromanagement, because we trusted one another and knew each others&#8217; expectations.</p>
<p><strong>NB: What put you ahead of the other teams?</strong><br />RE: We were ruthless. Got a feature to do and you&#8217;re not sure how long it&#8217;ll take? Do a 30-minute attempt and see how it goes. If it looks like it&#8217;ll take a long time, jettison it for something easier.</p>
<p>Being so focused meant a lot of sleep loss. We all wrote code until we dropped. Steve crashed at 3 a.m. on Thursday morning and slept four hours, worked until 1 a.m. on Friday and slept two hours, then caught a two-hour nap before the party. The others didn&#8217;t sleep much more.</p>
<p>With a few exceptions, we shot right through our technical challenges and wrote pretty bug-free code. And having a killer presentation didn&#8217;t hurt—Steve even channeled his inner Billy Mays a little.</p>
<hr />
<p>So there you have it. A solid plan, deep expertise and a great presentation of your app will help you rise to the top at Clash of the Coders.</p>
<p>Want more coverage? TUAW reporter Erica Sadun joined us for the event and wrote <a href="http://www.tuaw.com/tag/clashofthecoders">a series of articles</a> about her experience. For a retrospective of the first Clash of the Coders, check out Bill Phillips&#8217; <a href="http://bit.ly/15Y0aNb">post</a> on his big win with Chris Stewart.</p>
<div id="attachment_2670" class="wp-caption aligncenter" style="width: 605px"><a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/photo-background-copy/" rel="attachment wp-att-2670"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/photo-background-copy.jpg" alt="Nerds hard at work, and a collection of caricatures from the event." title="Clash" width="595" height="536" class="size-full wp-image-2670" /></a><p class="wp-caption-text">Photos courtesy of our Birmingham office, Chris Kelly (ckdake.com) and our Netherlands office.</p></div>
<p>The post <a href="http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/">Clash of the Coders 2013: Winners Announced</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2650-clash-of-the-coders-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Healthy Programmer</title>
		<link>http://blog.bignerdranch.com/2645-the-healthy-programmer/</link>
		<comments>http://blog.bignerdranch.com/2645-the-healthy-programmer/#comments</comments>
		<pubDate>Wed, 08 May 2013 18:11:45 +0000</pubDate>
		<dc:creator>Tasha Schroeder</dc:creator>
				<category><![CDATA[Tech Talks]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2645</guid>
		<description><![CDATA[<p><p><a href="http://bit.ly/ZHZmF0"></a></p>
<p>To keep doing what you love, you must maintain your own systems—not just the ones you write code for.</p>
<p>In order to concentrate, learn and remember (all of which are important for programmers), you need exercise and a healthy diet. In <a href="http://bit.ly/ZHZmF0">this talk</a> from <a href="http://jkutner.github.io/">Joe Kutner</a>, you&#8217;ll learn exercises that will make working at a computer more comfortable, as well as how to change your work habits and develop a plan to stay fit.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2645-the-healthy-programmer/">The Healthy Programmer</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://bit.ly/ZHZmF0"><img src="http://blog.bignerdranch.com/wp-content/uploads/2013/05/healthy-programmer.jpg" alt="" title="healthy programmer" width="595" height="362" class="aligncenter size-full wp-image-2646" /></a></p>
<p>To keep doing what you love, you must maintain your own systems—not just the ones you write code for.</p>
<p>In order to concentrate, learn and remember (all of which are important for programmers), you need exercise and a healthy diet. In <a href="http://bit.ly/ZHZmF0">this talk</a> from <a href="http://jkutner.github.io/">Joe Kutner</a>, you&#8217;ll learn exercises that will make working at a computer more comfortable, as well as how to change your work habits and develop a plan to stay fit.</p>
<p>The post <a href="http://blog.bignerdranch.com/2645-the-healthy-programmer/">The Healthy Programmer</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2645-the-healthy-programmer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Railsberry: A Different Kind of Conference</title>
		<link>http://blog.bignerdranch.com/2631-railsberry-a-different-kind-of-conference/</link>
		<comments>http://blog.bignerdranch.com/2631-railsberry-a-different-kind-of-conference/#comments</comments>
		<pubDate>Tue, 07 May 2013 20:35:17 +0000</pubDate>
		<dc:creator>Dan Rice</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://blog.bignerdranch.com/?p=2631</guid>
		<description><![CDATA[<p><p>Big Nerd Ranch recently sent <a href="http://www.bignerdranch.com/about_us/nerds/brian_gardner">Brian Gardner</a> and me to the <a href="http://www.railsberry.com/">Railsberry</a> Conference in Krakow, Poland. Having been to several Rails conferences already, I expected some technical talks, Agile process talks, and the requisite talk on refactoring.</p>
<p>What I found at Railsberry, which is advertised as the conference for &#8220;curious&#8221; Ruby on Rails developers, was far from formulaic and typical.&#8230;</p></p><p>The post <a href="http://blog.bignerdranch.com/2631-railsberry-a-different-kind-of-conference/">Railsberry: A Different Kind of Conference</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></description>
			<content:encoded><![CDATA[<p>Big Nerd Ranch recently sent <a href="http://www.bignerdranch.com/about_us/nerds/brian_gardner">Brian Gardner</a> and me to the <a href="http://www.railsberry.com/">Railsberry</a> Conference in Krakow, Poland. Having been to several Rails conferences already, I expected some technical talks, Agile process talks, and the requisite talk on refactoring.</p>
<p>What I found at Railsberry, which is advertised as the conference for &#8220;curious&#8221; Ruby on Rails developers, was far from formulaic and typical. It was one of the most unique, fun and well-organized conferences I’ve attended in my career as a developer.</p>
<h3>A different kind of conference</h3>
<p>So how did Railsberry show me a different kind of conference experience? First off, ask yourself this question: Have you ever been invited to attend a contemporary dance performance by the conference organizers? Odds are that you haven’t, unless you’ve attended Railsberry.</p>
<p>Have you been able to swing back and forth while watching a lightning talk? Odds are, again, that you’ll have to say no. But this is what the modus operandi is at Railsberry; in fact, upon arrival at the conference, you’re inundated with a different look and feel. The conference itself is an experiment, meaning that the organizers try different, new ideas and see if they work. They embody a curiosity towards everything that permeates the entire two-day, single-track event. I was actually initially greeted and welcomed by conference staff wearing laboratory coats! (Were they experimenting on <em>me</em>?) When a conference speaker wasn’t able to attend the conference, it was no big deal. The conference organizers simply opened the floor for more lightning talks.</p>
<h3>Learning something new</h3>
<p>Let’s not forget the reasons we attend conferences: to learn something new. And there was a slew of great talks by a variety of speakers from various professional positions. We listened to <a href="https://twitter.com/greggpollack">Gregg Pollack</a> walk us through the current state of the online education business as it pertains to learning code. We were enlightened by <a href="https://twitter.com/fgeorge52">Fred George</a>’s talk on implementing Agile methodology for any development team. As a 40-year industry veteran, his insight into how a company “should” do Agile was eye-opening, to say the least. He even called out some of the practices that we currently use at Big Nerd Ranch (our ego is not damaged; indeed, we love learning from others as much as we love teaching). The most outstanding and thought-provoking presentation was <a href="http://blog.josephwilk.net/">Joseph Wilk</a>&#8216;s talk called &#8220;Creative Machines,&#8221; where he explored the ways that computers can produce music.</p>
<p>All in all, this event is a standout amongst the global collection of technical conferences a Ruby on Rails developer could attend. It was entertaining, thought-provoking and fun. I can’t recommend this conference more highly.</p>
<p>The post <a href="http://blog.bignerdranch.com/2631-railsberry-a-different-kind-of-conference/">Railsberry: A Different Kind of Conference</a> appeared first on <a href="http://blog.bignerdranch.com">Big Nerd Ranch Blog</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.bignerdranch.com/2631-railsberry-a-different-kind-of-conference/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
