Archive for the ‘briancrescimanno.com’ category

Pass that Interview 2: Understanding Recursion

March 1st, 2010

Recursion is one of the most misunderstood concepts in software development. Truthfully, in modern software development it has been almost completely replaced by iterative control structures (loops). In front-end UI-layer development, it is very rarely used. However, it's very common that you'll be asked questions about recursion during an interview. Why? I compare it to airlines hiring Air Force and Navy fighter pilots. No, they're never going to need to barrel roll a commercial jet-liner but the fact that they understand and know how to do it makes them more complete pilots. Similarly, understanding concepts such as recursion opens up new ways of thinking for engineers.

In its most simple terms, a recursive function is a function which returns a call to itself. Naturally, one has to be careful with this type of construct as it's easy to create an infinite loop. A typical recursive pattern involves breaking a problem into smaller pieces (such as searching a large data set) rather than performing a process multiple times as in iteration.

A common interview question may involve implementing a factorial function using recursion. Let's take a quick look at how we could do this:

function fact(x) {
    if(x > 1) {
        return x * fact(x-1);
    } else {
        return 1;
    }
}

By including a call to itself in the return, the program builds up and subsequently tears down a call stack. Rather than looping over an operation, we're breaking the problem into smaller pieces until it's simply returnin the value we passed in.

Drawbacks of Recursion

Now that we have an understanding of how to create a basic recursive function, we need to be able to discuss the drawbacks of this approach. First, in most programming language, the loop control structures (for, while, etc.) are optimized for speed and will (in the vast majority of cases) be faster.

Second, the memory overhead for allocating all of those functions can grow massively; especially in dynamic languages like Javascript. In our above example, if a user called fact(200) we would incur the overhead of creating 200 function instances in memory. You can see that for large operations this will get very heavy.

Stand Out

For the most part in front-end development, you won't be delving deeply into recursion; but armed with this basic understanding of the topic, you'll stand out from other candidates who aren't familiar with a wide array of software engineering concepts.

Hello Brightcove!

November 3rd, 2009

Monday was my first day in my new role as Prinicipal UI Engineer for Brightcove and I'm quite excited to begin this new chapter of not only my career, but my life as well.  Brightcove is headquartered in Cambridge, MA which means the first major physical relocation in over 20 years for me.  More importantly, it's the first time I'll be living outside of Atlanta as an adult.

There were may reasons I chose to accept this opportunity and uproot my life to come here. Most notably, I believe the word "opportunity" truly applies.  I spent a good portion of my half-day interview in Cambridge in early October talking about where I want my career to go; and not just anecdotally via the typical "Where do you see yourself in 5 years?" interview question.  We talked about how my desired path can fit into the Brightcove structure and culture and we talked about how to leverage my current skill sets to make those transitions possible. While I grew tremendously in my time at ATC, I believe I'll grow much more, and much more quickly, and Brightcove.

I also saw the opportunity to come to a company that sits on the leading edge of technology on the web; and a company where initiative would be embraced from engineers rather than stifled.  And the company showed tremendous faith in me throughout the whole Interview and Negotiation process.

The fact that they use the Scrum methodology certainly didn't hurt things either.  Oh, and they have some of the world's best Flex developers for me to learn from as well.  :)

All of these things, and the general feeling of excitement I had when I walked out of that interview, made it a very easy decision for me to pack up and move to New England.  When I arrived for my first day, I found that people know who I am, are happy I'm there, and are ready to look to me for leadership in the UI Engineering discipline.

I look forward to this adventure!

Goodbye ATC

October 23rd, 2009

Today is my last day at AutoTrader.com.  I've been here just shy of two years and it's been a fantastic experience. I've learned, grown, and met some wonderful people with whom I hope to remain friends for years.  At ATC, I was able to truly able to embrace the discipline of UI Engineering and learn so much from so many people that I'm ready to take that next step.

The first year was simply the best work experience I've had. I met people who twisted my mind in ways it'd never been twisted before. I learned about enterprise software architecture and the unique challenges faced in that type of environment as opposed to client work. I attended my first major web conference in nearly 10 years, and, of course, I made some fantastic friends along the way. I participated as a lead engineer in one of the greatest feats of enterprise web engineering ever accomplished; one that won't be talked about in engineering circles, but if you were there, you knew what we accomplished was truly incredible.

Over time, I came to the realization that despite my and others' efforts, the company would never shed it's very conservative nature.  And frankly, it's hard to argue that potentially putting off many millions of unique visitors a month by becoming more "cutting edge" is a great idea when revenues are at stake. But the inescapable fact, as famously explained by one of the executives, is that "AutoTrader.com is an advertising company," not an engineering company. As such, after a time, an engineer is going to begin to feel somewhat "stifled" in that environment. Once I began to feel as if it were sapping my motivation, I knew it was time to move on.

All that said, I did not look for a new opportunity; one fell into my lap at the right time and I've chosen to seize it.  I'll write about my new company in a separate post; and I'm very exciting about the whirlwind of change it means for my life!

Goodbye AutoTrader.com and the wonderful people I've met there along the way; you will very sincerely be missed.

Collected (abridged) thoughts on #jqcon

September 14th, 2009

I spent September 11-14 in Boston for jQuery Conference 2009.  For $150, this conference was probably the best value I've seen in a conference.  Packed with great speakers on great topics, it was more than I was expecting.

I spent most of my time tweeting the event using the #jQCon tag, but I wanted to collect some thought here in a slightly more robust way than I could using Twitter.  Here it goes:

  • jQuery 1.3.3 looks really sick; John and the whole core team have done some fantastic work.  I really appreciate that these guys are really committed to making jQuery competitive in the running for "fastest" JS library.  A 3.5x speed increase overall in 1.3.3 is nothing to sneeze at.  I can't wait for the release!
  • There are a lot more implications selectors being parsed right-to-left in jQuery than you might imagine.  As always, specificity plays a big role; but not necessarily in intuitive ways.  I'll probably write a more full post on this topic as my mind really got swirling around this one.
  • People are totally stoked about jQueryUI and jQueryUI Labs.  That's a good thing as I see absolutely huge potential for jQueryUI and I've been developing some widgets that I plan to release on github relatively soon.
  • The guys from JavascriptMVC are interesting characters.  And they get huge props for handling an attendee asking them to "fast forward" their presentation in a humorous way.
  • ARIA is fantastic technology that people should really, really be looking into.  An interesting project would be to make all jQueryUI widgets ARIA-compliant.
  • People who use and preach jQuery love Event Delegation.  I was in really good company with these guys and I was happy to see it getting so much press.  jQuery's $.live() handles delegation for you which is just slick.
  • TestSwarm, as I anticipated, is going to rock. Javascript testing got a lot of press too and I'm really stoked that it did.  I was a little disappointed that there wasn't much coverage of testing frameworks (not even qunit)
  • Steve Souders is even more passionate about front-end performance than I expected him to be.  Also, big ups for doing his presentation on less sleep than I had the night before.
  • There's a lot of talk about how to organize your code with jQuery.  It seems that the fact that jQuery doesn't enforce some type of structure is both a blessing and a curse.  I've often said that for ATC, a big barrier has been that prototype's class functionality gives us something that we haven't been able to replace in jQuery.  The good news is that a lot of people are thinking about it and there are some great solutions out there.

I also have some thoughts about the social aspects of the conference

  • The question I was asked most:  "how about the ratio?"  It had to be at least 25:1; but it could have been 30:1
  • There's an iPhone version of the drinking game "Circle of Death" out there.  That made for every bit as much fun as you might imagine.
  • After enough adult beverages, John Resig's "smooth-jazz" voice does lighten a bit. :)
  • It was great to find so many people there who were truly social.  I was expecting to have a harder time getting people to open up--but there were others there that shared my mindset.
  • Off the top of my head (and if you're not on the list, it's because I simply didn't think about it very long or we only talked briefly) it was great to meet and spend time with @bobholt, @jeresig, @voodootikigod, @rmurphey, @snookca, @bitofgrace, @bpartridge, @binary42, @Cowboy, @defunkt, @dainbrain
  • I still wish I'd met even more.

Great time; more to come from me on the conference.  But that's an early round-up!

For those that weren't there, @bobholt set up a site to aggregate the slides.

More on Keeping Track of Focus

July 10th, 2009

A bit over a year ago, I wrote a post on Keeping Track of Focus using Javascript.  Unfortunately, the code is severely flawed (though I haven't yet figured out why it continues to work where I implemented it--but that's a question for another day).

PPK points out that unlike most javascript events, focus does not bubble. He also offers a solution which uses event capturing to get around the problem.  I've taken that solution and modified it for use with Prototype.js as the original version was created that way.

var FocusReader = Class.create({

    initialize: function(){
	this.currentFocus = null;
        var focusRead = this.focusRead.bindAsEventListener(this);
        document.addEventListener("focus", focusRead, true);
        /* Also add the listener for IE which does not
            support capturing */
        document.onfocusin = focusRead;
    },

    focusRead: function(e){
        /* Need to force extending the event since
            it won't be extended by default */
        e = Event.extend(e);
        this.currentFocus = e.element();
    },

    getCurrentFocus: function(){
        return this.currentFocus;
    },

    getCurrentFocusId: function(){
	if(this.currentFocus.identify) return this.currentFocus.identify();
    }

});

Easing Equations in Scripty2

June 26th, 2009

Just a quick note here today--for those who aren't aware, Robert Penner's easing equations, which I ported to script.aculo.us several months ago have been merged into scripty2.  They exist in the s2.fx.transitions package and are available for use directly from the library.

I'm pleased to have contributed code to such a great project as scripty2.  Thanks to Thomas for including my work!  Head on over to the official scripty2 site and download the alpha or even just take a look at the demos.  He's got some great stuff going on in this release.

Using Sizzle with Prototype

March 24th, 2009

Recently, John Resig of jQuery fame released the selector engine used in the new version of jQuery called Sizzle.  Sizzle is a new take on using CSS selectors within Javascript and aims to be far more efficient than the methods commonly used by most current Javascript libraries.

Currently, I'm working on a large project that is nearly ready to deploy.  Most of the Javascript for this project has been written using the Prototype framework; however, we wanted to leverage the speed of the new Sizzle selectors engine in our project.  Given that we are deep in the QA process of the project, large code changes are discouraged to ensure code stability.  What we needed was a quick way to integrate Sizzle with Prototype.

The following code can be added to your Prototype 1.6.x file and will ensure that prototype's main element collection methods (Element#select and $$) both use Sizzle.  I've written before on how slow $$ can be, so these are two quick wins for Prototype performance.

//Overwrite findChildElements to use Sizzle http://sizzlejs.com
Selector.findChildElements = function(element, expression){
    expression = expression.join(", ");
    var results = Sizzle(expression, element);
    if(results.length > 0){
        for(var i=0; i < results.length; i++){
            results[i] = Element.extend(results[i]);
        }
    }
    return results;
};