Git Bisect and Why it is Amazing

Had a client email me recently, mildly concerned, as an update to WP eCommerce broken his search layout. I told him that I couldn’t think of anything between the latest version and the prior version that would have caused any such thing, but I’d be more than happy to check it out.

Initially, if I’m being quite honest, I just assumed it was user error.  It’s easy to mis-configure things, set up a theme wrong, etc. Any number of things can go wrong. But, I dug in and in fact, we had broken it.  I didn’t recall any changes in the 913 commits between the two changes.

With nothing obvious, and 913 commits between release – what was a developer to do?  Enter, git bisect.

Git bisect is amazing. Prior to using it, you might think to yourself,

“Hmm, self, I suppose I can checkout a few different commits, figure out a commit where it works, and one where it doesn’t, and sort of narrow down a range until I find it.”

And that would be a really good thought.  But it would take you, a human, waaaaaaay longer than git would take.  That very thought you had? That’s what git bisect does.  Imagine you have the master branch, latest commit checked out.  You know that a previous version branch worked fine.  Check this out.

git bisect start
git bisect good
git bisect bad branch-3.8.14.4

And boom, you’ve started down the path. Git will analyze how many revisions exist between good and bad, split the difference, and checkout that commit. Then, test to see if the bug still exists. If it does, git bisect bad. If not, git bisect good. It will keep narrowing down the commits until it finds the precise commit that caused the issue.

In case you remain unconvinced – remember – I was able to wade through 913 commits to find the single commit that caused a bug in a piece of software that spans hundreds of files and over 150,000 lines of code.

It took about three minutes.

Git bisect is amazing.

Thoughts on College

College isn’t something that I’m particularly well-qualified to address.  I dropped out of high school at 18 years old, got my GED, and started my business.  I did go to a semester of bible college, but that hardly qualifies as higher education.

Even though I didn’t find college to be something that was part of my long-term goal – I’m actually not 100% opposed to schooling.  I think it works fine for a fair amount of people.  This post was inspired by a conversation between my friends Cory and Chris on Twitter.  I tweeted something as part of that conversation that I do actually believe with significant conviction:

See,  I’m not anti-college.  I think it can be a great experience that provides necessary training for certain walks of life.  I’m 100% against two things that often come with college: 1) Lack of direction 2) Debt.

Over the past decade or so, the usefulness of a 4-year degree has been challenged by an ever-changing economy.  I feel like starting my company back in 2005 with no college education was a bit more of a leap of faith than it might be today.  I actually believe that anyone can be successful at working for themselves.  It’s a matter of hard work, sacrifice and discipline – but I think living life well requires those things of everyone.  Because of that conviction, I do question the general assumption held by my parent’s generation, that is: Everyone should go to college.

Lack of Direction

I can think of nearly a dozen people in my close circle of family and friends that were (or are) 5th-year seniors.  They went to college, because that’s what normal people do. They had no idea what they wanted to do next week, let alone for the rest of their lives.  For some reason, though, it was important to go to a 40K/year school for 4-6 years to end up with an English degree and working at a Starbucks.  Again – I think college works for some people.  But if you’re using it as an excuse to figure out what you want to do with your life – there are FAR cheaper ways of doing that.  I realize that I’m a bit of an anomaly – I knew I could run a business building software by the time I was 15.  I don’t think everyone has (or needs to have) that kind of direction at that age.  That said – if you’re 15-17 years old and have no idea what you want to do, DON’T GO TO COLLEGE!

That’s right.  Bold, italicized and underlined.  All caps, too, because I’m shouting.  There’s no reason to spend tens (if not hundreds) of thousands of dollars at school to figure out what you want to do. Don’t go to school, go to work!   Find something you love to do and do it.  Heck, even if you don’t love it, just go make some money.  Life will never be as inexpensive for you as it is right now – go earn and save a ton of money!   Hustle, hustle, hustle and make the life you want.   Along the way, you’ll figure out what it is you want to do.  There’s life in the doing.

Debt

No me gusta debt.  Je n’aime pas debt.  Ich hasse debt.  我討厭的債務. Seriously.  I hate debt.  I can’t say it in enough languages.  It’s a scourge to personal finances and businesses alike.   Like the ancient proverb says, The borrower is slave to the lender. Debt causes you to miss the mark, to be shackled to things you were never meant to be shackled to.  One of the biggest areas of indebtedness today is student loan debt.  Student loan debt has nearly quadrupled in the last 10 years.  In 2010, for the first time this century, student loan debt was greater than both auto and credit card debt.  It’s a big deal and it’s weighing my generation down.  I know too many people who are working in dead-end jobs for “job security” for no other reason than their student loans.  I have personal friends whose student loan payments are bigger than their rent checks. 

Having two kids (and one on the way…and who knows after that!), has caused me to think about this often.  I am absolutely saving money for my kids to go to school, if they want to go.  If they’re going to become doctors or lawyers or certain kind of engineers – of course, they’ll have to go to college.  But what if they don’t?  What if they get married at 20 years old to some trust fund kid?  What if they start a business?  What if they take over my business?  What if the best thing for them is to go work at an orphanage in Tanzania after high school?  There are so many unknowns in life that I can’t imagine forcing my children on one certain path, boxing them into an academic world that may just not be their calling in life.

Again – if you don’t have to go into debt for it and you know why you are going – absolutely go to college.  Go to the best college you can afford that makes the most sense for the path in life you want to take.  But please, for the sake of your future self – don’t go to college just because normal people go to college.  I know normal.  Normal is broke.

Building REST APIs

Building APIs is hard.  Period.  Building RESTful APIs is a bit different, and requires in some cases more thought than generic internal APIs.  All it takes is mentioning PayPal and Stripe together in the same conversation to realize that building RESTful APIs is not child’s play.  When it’s executed well, it becomes an evangelistic tool, a delight for developers everywhere.  When executed poorly, well, just ask PayPal.

I bring all of this up because we’re in the process of building out a RESTful API for WP e-Commerce.  When I say “we”, I really mean that my friend, Pippin, is doing 99% of the work and I’m coming in and taking most of the credit.  #BOOM

But in all seriousness, he’s built a fantastic REST API for EDD and he’s being incredibly generous in porting a lot of it over to WPeC.  My hope is that by working together, both plugins end up with better APIs all around.  Collaboration is always greater than competition, and he understands that better than almost anyone I know.

Back to REST APIs though.  This post is really just me, thinking out loud, researching slowly.  I know some things that I don’t like, and I know some things that I do like.  I don’t like when endpoints include version numbers (use HTTP headers for this), verbs or query strings.  I do like when you only have to authenticate for private data; not all endpoints should require authentication.  I prefer HTTP response codes over random error codes, or at least in conjunction, when possible.  I hate SOAP and XML.  I love JSON.  Everything else is irrelevant (seriously).

Enough jibba-jabba.  Here’s some resources I’m mulling over as I prepare to work on our REST API.  I’d love to hear from you in the comments if you have experience building REST APIs or have found other helpful resources:

  • Intro to REST (Great primer, technical overview of what constitutes a strictly RESTful API)
  • High Performance APIs (A presentation from some of the guys behind LinkedIn’s API)
  • Creating an efficient REST API (A very practical look at creating an API based on the basic principles of REST.  Note: I don’t agree with everything in this.)
  • RESTful API Design, 2nd ed.
  • RESTful Best Practices ( A presentation on building REST APIs in Ruby on Rails.  Ruby has some slick stuff for REST API implementation.  It kind of blows PHP away in that regard.  Regardless, it’s helpful for patterns and concepts. )
  • RESTful Web Services (It’s a book.  Buy it if you build this stuff.)
  • What Makes a Great Open API? (Great presentation, less technical, more high-level, business logic, concepts.  The whys, not the hows or whats.)

Using Custom jQuery events in WP eCommerce

Custom events in jQuery are super simple, and really neat to use.  Unless and until a javascript framework like this ends up in core, they are probably the best way to allow for a nice degree of extensibility in your javascript for other developers.

For the 3.8.11 release of WP eCommerce, we did a massive overhaul of our JavaScript.  To give an idea of the scope, we ended up removing 20,000 lines of code.  That’s right, bold and italicized – it was that awesome.

One of the elements we added were a few custom events.  For example, we had a particularly nasty action hook in our add_to_cart() function.  It essentially encouraged developers to hook in and echo out some eval()’d javascript, so that when something was added to the cart, they could override our default javascript mechanism that does, well, stuff.

Not only is this equally insecure and lame – it’s actually a fantastic use case for a custom event.  Rather than insecurely eval()ing javascript here like we were before*, we have a sexy new custom event for plugins to use.  Here’s a really basic overview of how you might use it.  As a plugin author or theme author, you’d likely put the following code in a javascript file, properly enqueued and such.  For my example, I’m just outputting it to wp_head.  For an exercise in futility, check out our veritably imperfect attempt at backwards compatibility.

// This is the code that actually hooks into the custom event.
function zao_update_cart_item_count() {
    ?>
    <script>// <![CDATA[
    jQuery( document ).on( 'wpsc_fancy_notification', function( response ){
        jQuery('#cart-top a span.cartcount').html( response.response.item_count );
    });
    // ]]></script>
    <?php
}

add_action( 'wp_head', 'zao_update_cart_item_count' );

// This adds custom data to the response object, accessible in the custom JS event.
function zao_add_json( $response ) {
    $response['item_count'] = sprintf( _n( '%d item', '%d items', wpsc_cart_item_count(), 'wpsc' ), wpsc_cart_item_count() );
    return $response;
}

add_filter( 'wpsc_add_to_cart_json_response', 'zao_add_json' );

And voila, lovely custom JS events for everyone.  A fantastic and incredibly useful development concept.

Three Things I Learned from Chris Lema

food1I had a great opportunity to spend time with Chris Lema and Josh Eaton the other night.  We had some of the most fantastic food I’ve enjoyed in awhile at this fabulous restaurant called Urban Farmer.  If you’re ever in Portland and have the chance to go, I’d highly recommend it – everything was exquisite.

It was a real treat to meet Josh – he and I are in very similar places in life.  20-something  WordPress developers with young families, working hard and doing well.  Josh has accomplished some incredibly fascinating things over the last few years – he and his wife blog about it at Traveling 9 to 5.  tl;dr – they got a free Galapagos cruise!   Ridiculous.  He has also spent some time recently becoming a bit more active on the WP e-Commerce GitHub issue tracker, so it’s been great to get to know him at the development level.  He’s a smart developer and he’s working with Andrew Norcross at Reaktiv Studios – fantastic guys who I can’t recommend highly enough.

That all said – spending time with these guys further cemented a realization I’ve had about myself:

Folks like us are not normal.  

“Us”, in this case, includes many of you reading this.  Spending the time it takes to work hard, build businesses, work in the trenches doing the hard yards of entrepreneurship – that’s frankly rare.  It’s the reality of life for Josh and myself, and it’s Chris’ reality as well.  Spending time with a guy like Chris – who is doing what we’re doing, except he’s been doing it for 20+ years – was a phenomenally valuable time of learning and gleaning.  And it wasn’t just valuable because he picked up the check. :)

Here’s what I learned (Disclaimer: after reading this post, you’ll think I’ve fallen in love with Chris Lema.  Almost, but I’m happily married.  I learned a lot in a short amount of time with him – this post, like all my posts, is primarily for myself, so I don’t forget lessons learned.):

Doing > Talking

We had some really interesting conversations about the freelance life, different victories and challenges we face alongside our colleagues.  One of the primary pain points we recognized is health care – freelancers, in general, either have no health care coverage or minimal coverage.  Speaking for me personally – I have great health care on my wife and kids, but nothing on myself.  There are simply too few options that make the right amount of sense.  It would be easy to sit and complain about how annoying that is, blame Obama, blame Republicans, blame Chris Lema. It’s easy to play the blame game when you have limited vision and feel the problem is insurmountable and you’re condemned to the status quo.

That’s not what Chris did.  Instead, one of the first statements out of his mouth was, “Hmm, I think I know a guy.  Let me see what I can do.”

He wasn’t saying, “Oh, I have a great agent, let me grab you his number.

And he certainly wasn’t saying, “Yeah, that sucks for freelancers.  Bummer.

What he was actually doing is way better than that.  He recognized a systemic problem that affects a lot of people.  He decided to put on his thinking cap and put feet to the problem. I don’t know what the end result will be, the problem has only been stewing in that magic space between his ears for a few days – but I won’t be surprised at all if something incredibly interesting and beneficial comes from  this conversation.  In large part, that’s because Chris recognizes that doing is better than talking – he is, after all, the done done guy.  Him deciding to simply “see what he could do” inspired me to take a look at the things I simply talk about, and see instead what I can do about them.

Giving > Getting

Want in on a little secret?  There are few things more fun in life than being extravagantly generous.  I can’t imagine any greater reward for generating obscene amounts of wealth than the joy of giving it all away.  I believe, beyond a shadow of a doubt, that we were born to be generous people.  All of us, you included. Chris is a brilliant example of this.  As I mentioned, naturally, he picked up the check.  It wasn’t a small check, I promise you.  Less than four digits, more than three.  But that’s not even the primary example of Chris being a generous dude.

He has a generous spirit.  Do you know how refreshing and rare it is that you can go out to dinner with a business executive-type person, period?  Not common, unless you yourself are also a business executive.  Time is the most precious resource you or I can offer someone; and Chris is beyond generous with his.  #boom.

Also, say you do find yourself in a dinner meeting like that.  Do you realize how uncommon it is that these types of people speak kindly and with great love about everyone that might come up in discussion?  There wasn’t a single negative comment about anyone that came out of Chris’ mouth.  Most notably, his wife.  It is maddeningly common in these types of meetings to have spouses referred to with disdain, annoyance, or worse.  It was refreshing for Chris’ love for his wife to be unmistakably and irrevocably obvious.  That, for me, is the definition of generosity; it’s not about writing a big check, it’s about authentically sharing your heart with people.

Consistency

Lastly, Chris is a man who is nothing if not consistent.  I’m not entirely sure how long he’s been blogging daily for, but it feels like a long time.  He’ll be the first to tell you (in a long line of others) that consistent blogging with valuable content is a huge key to having a great blog that gets the results you want.  But that’s easy, anyone can write a valuable article with interesting, engaging content, every day.

No, what’s impressive about Chris Lema’s level of consistency isn’t what he’s been doing on a blog over the last year or two – it’s what he has been doing over the past decade or two.  In a few brief hours with him, it was easily discernable that his current state in life (which is pretty awesome, by all accounts) is a direct result of making smart decisions – small decisions – every day, consistently.  Like a good investment vehicle, investment in wise decision-making compounds exponentially over time.  To see where he’s been makes one incredibly excited to envision where he’s going.  Beyond that, it give me confidence in my current direction and the decisions I am making, as well as giving me a glimpse of what 20 years from now might look like.

So – Josh and Chris – thank you guys both for a fantastic evening.  Great food and conversation, and obviously, I learned a lot.

#BeachPress 2013!

Beach House + WordPress + Co-working awesome dev sauce.

Ever wondered how fun it would be to have a bunch of WordPress developers co-working together at the beach? Me too!

Join us from May 27th through May 30th in beautiful Rockaway Beach, OR for a couple of days of pure, unadulterated WordPress goodness.

Have a plugin you’re working on? A new theme? Maybe a SAAS or a client project? My core belief with this experiment is that when we gather different people with different areas of knowledge together in an incredible setting – only good things can come of it.

Granted, it’s Oregon – so the weather could be crazy – but I think if you’re from the Pacific Northwest, you’re probably kind of used to that already :) I think it will be worth the awesome camaraderie and awesome dev time together to give it a go.  We have a magnificent beach house tentatively lined up (seriously, check out the photos), home-cooked meals and decent WiFi and beer. Can’t ask for much more.

Did I mention that it’s donation-based?  If you can’t afford to spend a dime, but still want the awesomeness that will most certainly come with the environment – no worries, you’re still welcome!  Naturally, if you can give any amount at all – that’s totally appreciated and will help offset the costs of the event.  The cost per person is about $170 for those wanting to know a suggested donation amount.