It's Not Refactoring, It's Untangling

| No TrackBacks
Recently, I was catching up with a former colleague.  He mentioned a service that I wrote years ago, and how it has since become known as the Career Killer.  Basically everyone who touched the Career Killer ended up leaving the company.  If the company wanted to have > 0 developers, the only solution at this point was to take a few months and refactor this service completely.

I have two things to say about this.  First, that code was at 85% unit test coverage when I left so don't go blaming me.  Second, this huge refactoring?  It's not going to work.

Every codebase has at least one component that is widely hated and feared.  It does too much, it has too many states, too many other entities call it.  When it comes time to pay down technical debt, you should definitely focus on this component.  However, if you have an incomplete understanding of this component and you stop everything to completely rewrite it, your odds of success are low.  That component, as scary and complex as it appears, is actually way more scary and complex than you think. 

How do you think that component got into this unfortunate shape?  Is it because the company hired a nincompoop and let him run wild in the codebase for years?  Or is it because the component was originally a sound abstraction, but its scope of responsibilities had grown over the years due to changing requirements?  (For the sake of my ego, I'm hoping the Career Killer is the latter.)  In all likelihood, this component arrived at its current, scary state via smart people with good intentions.  You know what you are right now?  Smart people with good intentions.  If you proceed with a big refactor, you'll trade one form of technical debt for another.

In order to truly pay this debt down, you need to untangle the complexity around the problem.  You need to spend time looking at all the clients calling this component.  You need to spend time talking with your colleagues, learning more about the component's history and how it's used.  You need to make a few simplifying changes around the periphery of the component and see what works.  Each week, you spend a little more time and untangle the problem just a little bit more.  Given a long enough timeframe, you'll eventually untangle all of the complexity and brought a teeny bit of order to the universe.

Practically speaking, what do you do here?  Rather than 3 full months on a complete refactor, spend 25% of your time over the next year.  It's the same time commitment either way, but with the 25% plan, you get time to analyze and plan.  You get time to untangle.

Ship It!

| No TrackBacks
Several years ago, I had a job that, at the time, seemed like heaven.  We were a new team building a new product.  We were using new technology: C# 2.0 (yes, people were once excited about major releases of C#).  We were using new techniques, like scrum and test-driven development.  It was greenfield development in every possible sense, except for the one where our desks would actually be situated in a green field.

I lived in this environment for a few years.  I learned a lot about software development, technical leadership, and how to build big systems.  Ultimately though, I think I wasted those years.  Why?  We never shipped.

Something magical happens when you ship software: your decisions suddenly have consequences.  You suddenly must consider trade-offs.  Hopefully, people suddenly care.  If they don't, you suddenly must correct that.

What's the big deal about decisions and consequences?  Any fool with a text editor can write code, but only an amazing few can code and make good choices around trade-offs.  That's the most valuable skill a developer can possess: the ability to make hard decisions.  (That's actually a great way to make career choices: opt for the place that'll let you make harder decisions.)  Like riding a bike or juggling chainsaws, the only way to get good at making hard decisions is by doing it a lot.  Each time you make one of these decisions, gather data and iterate accordingly.

When I was working on that project that never shipped, I felt like I was making hard decisions.  We had big meetings and loud arguments about things that seemed important at the time.  You can bet your sweet bippy that we came to conclusions on all sorts of things.  However, since we never shipped, we never got any data about any of the choices we made around things like architecture, code coverage, implementation decisions, featureset, and user interface.  Without that data, we had no way of knowing if we had chosen correctly.  Did we get better at making hard decisions?  Without users, how could you tell?

There was an easy solution to the problem I faced at that job: ship the dang thing.  That decision wasn't up to me, so I should've done the next best thing: join a different team, one that shipped a ton of code.  Even if the codebase is worse and the product is less interesting, find a role where you ship; it's the only way you get better.

Software Karma

| No TrackBacks
I make a lot of jokes at work about code review karma.  Here's the idea: each time a person volunteers to review others' code, that person build their code review karma.  Then, when it comes time for that person's own code to be reviewed, the reviews go smoothly due to the store of code review karma.

Build karma works the same way.  When someone jumps in to help fix the build, they're accruing build karma.  Thanks to build karma, the builds that kick off from that person's own commits are far more likely to be successful.

If you have a lot of time on your hands, you can actually see software karma all over the place: QA karma by helping out your testers, refactoring karma by cleaning up the scariest bits of the code base, planning karma by leading sprint planning, etc.  The more you help, the more the software gods reward you in the future.

I see two explanations behind software karma.  The first is that there actually are software gods who sit upon Mount Codelympus and keep a running tally of all these helpful acts.  They probably keep this tally in Emacs, since that was clearly not designed for mortals.  If there is any truth to this explanation, then let's all quickly sacrifice a 'PHP for Dummies' book to appease them.

The other explanation is less exciting, but slightly more practical.  By reviewing others' code, you build a mental model around what great code looks like.  When you go to write your own code, you apply your model and reap the rewards immediately.  By fixing broken builds, you build a mental model around the build process and how it can go wrong; your own builds are far less likely to go wrong thanks to that model.  Same thing goes for helping QA, refactoring, sprint planning, and so forth.

I'm not taking sides on which explanation is correct, since I don't want to get struck by a lightning bolt or incite a plague.  All I do know is this: if you want to get better as a developer, boost your karma.

The Start of a New Adventure

| No TrackBacks

Today is my last day as a full-timer at Famigo. It's been a great 2+ years, and I'm very grateful for all the things I've learned and all the friends I've made. However, it's time for my next adventure. Next week, we move to Seattle where new, big challenges await. (I'll go into more detail on my new job in a later post.)

Why are we leaving? We've built fabulous products at Famigo, raised VC money, had lots of cool stuff written about us, and the company continues to charge ahead. Not only that, we have great friends in this city and a wonderful house. Why go? Well, all of this startup stuff has been way more complicated than I expected. Allow me to explain.

You Can't Put Life On Hold
I joined Famigo at the ground-level as cofounder and CTO. My plan was to immerse myself in my work and make this company a great success. I knew that would probably take years, but I was ready to make the commitment. In true comedic fashion, we immediately found out that my wife was pregnant. All of a sudden, questions about user retention and referral mechanisms looked trivial compared to questions about diaper rash and tummy time.

My plan to put real life on hold and focus on the startup failed in a million different ways. We had health issues, car issues, house issues, and family issues. Not only was all of that stressful for our entire family on top of the startup rollercoaster, it was also expensive. And, unfortunately, I couldn't pay for any of these expenses with Famigo stock options, even if I offered them with no vesting and a ridiculously low strike price. (Note to American economy: come on, man!)

Even more than the issue of money, there's the issue of time. The idea of doing a startup is something that had appealed to me for a long time. It was my dream. After a couple of years, I began to realize that my dream was causing all other dreams to be deferred. We wanted more kids, my wife wanted to take some time to be a stay at home mom, we wanted to give my son a neat childhood with plenty of adventure. Slowly, I began to realize that pursuing this startup dream to the exclusion of everything else was a little bit selfish.

while(true) surprise();
The lifecycle of a startup wasn't what I was expecting. There's a lot written about huge successes like Instagram, where lots of good things happened. There's also a decent amount written about startup failures, where lots of bad things happen. There's not much written about all the startups in the middle, where you experience some success but Facebook isn't exactly shaking in its boots.

Everything was a surprise; that goes for just about every good and bad thing that happened to us. You can read about startups all day long, but ultimately, that's no preparation for the experience itself. Deals take way longer or way shorter than expected, helpful people appear or disappear as if by magic, and the key human relationships beneath the business can spontaneously combust. Not all of these surprises are bad, but they are a constant.

The tough part about all of the surprises is that it makes it impossible to plan anything. That's tough, because things like families, investors, and employees like to know what might happen next. Do the inherent surprises behind a startup ever end? I'd venture a guess, but then life would find a way to surprise me.

Do It Anyway, But Do It Right
Given what I've written thus far, would I do this again? Would I recommend this experience to others? Absolutely. I have had a blast, I've learned so much, and I have met some of my best friends this way. I am incredibly proud of the entire experience. I also discovered an unexpected benefit: if you're a technical person and you do it right, people notice.

When I say 'do it right', I mean build something fabulous that people know about. Both parts of that are equally important. As an introspective person, I feel weird drawing attention to the work I do, either here on this blog or on Twitter. (You probably would not guess this from the giant ego fest that is my website!) It simply must be done, though. If you don't do it, no one will, and then you run the risk of all your hard work never getting the notice it deserves.

If you do manage to build something fabulous that people know about, you will be inundated with incredible opportunities. Then, when you decide you need to find your own next adventure, you will quickly find something great. That's what I did. Onwards!

I think we can do mobile media better. Let me explain.

When I watch a movie, I'll often have the movie itself on our big TV and then the movie's IMDB page up on my iPad or Kindle Fire. When I watch a baseball game on TV, I'll also follow the game on MLB's website or its At Bat app so I can see the pitch tracker and look at stats (I'm slightly obsessed/infatuated with the pitch tracker). If I watch a live event, I'll often have Twitter up so I can see what my friends and other funny tweeters are saying about it.

This is now a pretty common use case: people watching something on one big device, then diving in deeper into that content on a smaller device. It's kind of weird though, isn't it? Why do we need multiple devices for this? It's inefficient, it's cumbersome, it looks weird (that's according to my wife, I personally think it's a very debonair look). Even more than that, it's hard to truly pay attention to anything when your head keeps swivelling back and forth. There's a completely new media usage pattern here, but we're not taking advantage of it yet.

Here's one way we could approach this: combine streaming and navigation on a mobile device.

I don't mean toggling back and forth between an app that is streaming and a web browser. I want to stream my TV show or album as I normally would, then I'd like to pull up a translucent browser window on top of that where I can navigate wherever I'd like. The user then isn't constantly switching apps and thus switching contexts; they can see and hear everything, while still having the freedom to browse. It's one big, glorious context that the user controls.

Would that experience work as well on a TV? I don't think so, given how hard it is to navigate with a remote control. (Seriously, you could watch the director's cut of Das Boot while I try to search for a YouTube video on my TV.) I'm not sure about a laptop or a desktop, either. The inputs are there, but the use case I described above really feels to me like a living room activity, not an office activity. That's why I think this is a distinctly mobile opportunity.

I am in favor of the navigation being totally free-form. As a user, let me decide where I want to navigate instead of locking me into an IMDB tab and a Twitter tab with a predetermined hashtag. There's a lot of neat content out there to supplement my media; let me go find it! Much of the time, I might not even want the option to navigate. When I do want it, I should be in charge.

I don't think this would be easy to implement. It'd take a lot of playing with window sizes, locations, and aspect ratios to get this right; a maximized browser window on top of a maximized streaming baseball game would be probably be disorienting. I bet we can find some ratios here that make sense, though, depending on the form factors involved.

There are a load of opportunities beyond this, in terms of mobile media and users joining the conversation. The first step is actually finding that conversation, though, and that's easiest done through this one big context.

(Many thanks to Carlo Longino for chatting through a lot of this with me at Uncle Billy's the other night. Also, many thanks to the brewmasters at Uncle Billy's; y'all do fine work.)

Can't Fix It? Go Home.

| No TrackBacks
We ran into a positively bewildering bug in our Android app last week.  It was the perfect storm of bug-dom: it looked incredibly simple, but actually debugging it was horrendous due to several threads, API calls, and strangely-timed UI events.  On top of everything, this bug didn't really affect any user; it just made the UI look slightly weird if you were paying a lot of attention.
famigo_sandbox_screenshot.png

If you look at the Famigo Sandbox app, you'll notice there's a scroller at top where we list app recommendations.  The issue we had was that the app scroller would occasionally list a blank app.  Instead of an an app title and an icon, we'd show TextView as the app name and no icon at all.  You can scroll through hundreds of app recommendations, but you'd only get the blank app once.  Sounds trivial, no?

Last week, we were readying a great new version of the app to push to Google Play.  We had one known issue left: the blank spot in the app scroller.  A few of us had actually spent a bit of time looking at this bug in the past, but no one had figured it out.  We had a bit of time in our schedule before we needed to push the app, and I thought it'd be great to finally nail that bug.  Fixing it would mean no known issues; hooray!  Also, even though the bug was largely harmless, I worried that it'd be a broken window that might lead us towards sloppiness in the future.  

I paired up with John, one of our developers, to squash that sucker.  When we sat down, we fully expected to fix the bug within the hour; I think I actually said that out loud.  (Sidenote: never do that on a weird bug.  If you do say something like that, the software gods might overhear and punish you for your hubris.)

We began creating breakpoints, logging everything, and stepping through the code.  Within a few minutes, I was baffled; this particular bit of functionality was far more complex than I thought.  Due to the number of threads, it was even hard to figure out if it was an issue with the rendering logic or with the underlying data structure.  Our joint mindset quickly went from "Haha, let's solve this silly bug" to "Hmm, interesting" to "I don't get it" to "Is there another line of work we're qualified for?  Maybe garbage men, or is that a union deal?"

After several hours, we literally had no idea what the problem might be.  The rest of the office seemed to really enjoy our sighs, profanity, and nonsensical ramblings as we talked through what might be happening.

It was tempting to stay at the office until we found the bug.  I have tried that before, and I found that, past a certain amount, my efforts become detrimental.  I get tired, I mess things up even worse, and I spend the entire next day just working my way back to the original bug.  We made a note of what we were last looking at, then we left the office broken and dejected.

That night, I actually dreamed about the bug.  Yep, I couldn't get away from it even in my sleep.  (Even worse, in the dream, I was pair programming with Dog the Bounty Hunter.  Let's all choose not to analyze that.)

Both John and I got back into the office early that next day.  I imagine we looked like a couple of grizzled, old soldiers headed into battle, since no one dared to joke about the bug or even make eye contact with us.  As we sat down together, I thought it made sense to put a time limit on our debugging.  If we couldn't fix this ridiculous, silly bug in 90 minutes, then it was a sign from the cosmos that the app was destined to ship with one empty app in the app scroller.

We referred to the note we made last night on where to pick back up and we jumped back into code.  About 10 lines below, we saw something very, very strange.  If we got a certain response from the API, we would insert a blank app into the app scroller to keep the numbering even across our paged requests.  "That's... weird," we both said, trying not to sound optimistic.

We deleted that chunk of code, tested the app, and saw that everything now worked great.  We had 72 minutes left on the timer, and we had actually broke for 5 minutes for our standup!  We had been looking right at that function the night before, and we missed the issue entirely.

The lesson?  When you've stared at something for hours and still don't get it, go home. You'll see the problem with new eyes tomorrow.

The first week of a new development job is usually a sludge pit of paperwork, orientation, and environment configuration. Often, it's the worst week you'll have at that job. We recently had two interns join the Famigo development team for the summer, which led to an interesting question: is there a better way to do all that?

As soon as the interns arrived, I set out a goal for them: push code to production on your first day. While you can't avoid the paperwork and orientation part of a new job, at least they'd be contributing from the very beginning. Why is that important?

  • In order to push to production, you'll need a development environment set up.
  • You'll also need a bit of understanding about the codebase.
  • You'll need to understand some of the core concepts behind our process: unit testing, continuous deployment, etc.
  • It sets a good precedent. We're a startup here; we're allowed to move fast.

Is it reasonable to expect an intern to handle all of that on their first day? No, not on their own. Rather, each intern paired up with an experienced developer. The catch: the intern did the typing. I think that works pretty well, for a few reasons.

  • The new person gets firsthand experience with the environment and dev tools. It's incredibly helpful to actually hit the keys yourself.
  • If an error pops up (spoiler alert: it totally will), there's an experienced person right there to help.
  • The new person gets a guided tour of the codebase, but they're the ones doing the navigation, so they're more likely to remember what's where.

This process actually worked a little too well. With the experienced person guiding the process and the new person doing the typing, we actually had both interns push quality code before lunch. Unfortunately for them, that meant they then had to dive into paperwork. Oh well, that's employment for you.

We try to have fun together at Famigo.  Every Wednesday we have Taco Twednesday, in which we all leave the office to eat at and review various taco establishments.  (We're also logging these reviews, taking steps towards the world's first big taco data powerhouse.)  I also regularly invite everybody over to my house to make homebrew beer. (Ask about our not-quite-award-winning ale, Electric Brewgaloo.)  Finally, we devote one afternoon a month to Mandatory Fun Day, where one rotating employee plans an afternoon of fun for the rest of the company.

What's the point of all this camaraderie?  Sure, it's fun to get out of the office, it's great for retention, and it helps with recruiting.  We're doing something more important than all of that though when we're having fun, though.  We're doing something that every software organization needs help with: we're learning to listen to each other.

Writing software is an isolating experience.  Many years ago**, I had a job where I'd sit down, I'd put on my headphones, I'd bang away at the keyboard, and I'd go home 10 hours later.  That was all day, every day, for a few years.  Actually, there was an occasional exception.  Sometimes, I'd hit a hard problem and I'd spend 20 or 30 hours at the keyboard before I went home.  I wasn't the exception; the rest of the team was like that too.  And let me tell you, we made some crappy, crappy software.

It was a little surprising at the time, because, individually, we were all smart.  As a group then, shouldn't we have been very smart, making very good software?  Spoiler alert: no.  No one listened to anyone else, and so each person on the team was left on his own to make crucial mistakes.  These mistakes compounded over the years until the product crashed.

Why weren't we talking?  I can only speak anecdotally here.  My teammates were friendly enough, but there were differences when it came to age, outside interests, background, and politics.  All we had to discuss were the typical programming debates (vim vs. emacs, etc.) or company rumors, both of which were charged conversation topics.  In short order, everyone was still talking, but no one was listening.

We had important questions for each other, things like "What do you think of Feature X?", "Do these requirements make sense?", and "What the hell is it we're actually building?"  Even at the time, I knew I should be asking them, but not enough to get me to participate in an awkward conversation with people I didn't know very well.  Collectively, we could've answered those and built something important.  Instead, each of us charged ahead with a deeply flawed idea of what we were building.

Would tacos, beer making, or a go cart outing have fixed that?  Maybe so!  At the very least, it's a shared experience.  It's a starting point.  We could begin having agreeable conversations, starting with questions like "How about these tacos?"  or "Wow, we made some crappy beer, didn't we?" These simple conversations build rapport, and I would now trust my teammate's opinion on something.  All of that is crucial if I want to feel comfortable asking harder questions like, "I can't figure this out; will you help me?" or "Are we building the right thing?"  That is why it's only partly a joke when I say we practice taco-driven development.

**The job in question is wayyyy back in time, and has nothing to do with any recent employers.

I was recently at the DevOpsDays conference, where I got into a conversation about build automation. I mentioned how we practice continuous deployment, so we may deploy to production 20 times a day. The guy replied, "That sounds great for some tiny startup, but what would happen if you had actual users?"

Allow me to respond in 2 parts. First, ouch. Second, continuous deployment is not at odds with a great user experience or high uptime requirements.

Between our website and our API at Famigo, we handle hundreds of thousands of HTTP calls every day. We've practiced continuous deployment for 2 years. You know how many complaints we've had about a cruddy user experience due to frequent deployments? Zero. Why were these deployments essentially transparent to all of our users? That's a requirement for our build process, and so we've focused on that part as much as the actual act of building and deploying.

How Does It Work?
First, let's talk about what our production environment looks like. We have a few different VMs hosting our web app; these are all based off of the same original image. Our load balancer distributes traffic across these instances evenly. Since all of our web and API is based upon Django, we use virtualenv to manage all of our Python dependencies on each instance. Each instance also runs Jenkins, which does the heavy duty work of building and deploying.

All of the important data comes from MongoDB or Redis. I point that out to just to note that, with this backend, we rarely do schema migrations. Big honking ALTER TABLE statements can cause serious downtime; just ask the guy in the Oracle shirt crying into his keyboard right now.

How Do We Build?
We have one instance that's constantly polling our github repo for changes. When a change is found, it pulls down the repo. Our environment dependencies are part of that repo, so we make a call to virtualenv to ensure the environment is up to date. Then we run all of our tests; there are around 900 of these. When that's done, we rsync the files over to our production directories and restart our fcgi process. We then make a call to the next instance's Jenkins remote access API to kick off a build, and the whole process starts again.

Downtime?
The only portion of the build process that involves any downtime is when we rsync and then restart fcgi. Those steps take maybe a second or two. Since we build and deploy one instance at a time, that second of downtime rolls from machine to machine; in other words, we never have one second of downtime for all users on all instances.

One thing to keep in mind here is that our load balancer constantly pings our instances to ensure they're up. (After all, that's the whole point of these load balancer thingies.) If, for whatever reason, our downtime is longer than a few seconds, the load balancer will stop distributing traffic to that instance until it's back up.

As you can see, you have to be a little bit lucky (unlucky, rather) to ever see downtime here. You need to hit one particular instance with a request during its 1 second of downtime while the load balancer is sending traffic there with the load balancer not having realized the instance is down.

Does That Downtime Even Matter?
Please break out your slide rule, as we're going to do some math. Per instance, if we do 20 deployments with 1 second of downtime for each, that's 20 seconds. There are 86400 seconds in a day. 20/86200 is, in purely mathematical terms, teensy weensy. (I don't know how to calculate downtime across all instances because of the load balancer and its outage detection, so I'm just sticking with one instance here.)

Now, if we were processing credit cards or something like that, 20 seconds of downtime per day due to deployments would be unacceptable. (Note: we don't do that.) On the contrary, if your traffic is largely mobile, as ours is, then 20 seconds a day is nothing. In fact, we expect far worse. The reason is that, in the land of mobile, you get in the habit of trying and retrying everything related to the network, because the coverage can be so spotty.

Conclusion
Continuous deployment does not necessarily mean giant swaths of downtime throughout the day. In fact, as you scale up in environment infrastructure, deployment smarts, and hopefully users, you gain tools that can make this downtime negligible. Now, back to my actual users.

Code Like Clarkson

| No TrackBacks
Like anyone else with a brain and a heart, I love Top Gear.  In fact, I love it so much that I find myself borrowing wisdom from the show and applying it other domains entirely.

As you may know, there's a portion of show where they put a celebrity in a reasonably priced car, which the celebrity then races around the Top Gear track.  We then watch the celebrity watch their lap.  Often, the celebrity will say something how it looks as if they're going really slow.  Jeremy Clarkson always has the same retort: if you look like you're going slow, you're probably going quite fast.

This idea maps nicely to software.  To the uninformed, it looks like we're going slow when we write tests.  It looks like we're going slow when we learn and utilize new tools like Hadoop or Cassandra.  It looks like we're going slow when we perform A/B tests.  It looks like we're going slow when we pair program.  And yet, all of these "slow" activities are tremendously helpful to going fast in the long run.

Conversely, if it looks like you're writing software quickly, you're probably not.  Yes, you can get all cranked up on caffeine, code for 20 hours, and write a thousand lines of code.  You can do that day after day, just coding, releasing gigantic features constantly.  I think you'd quickly encounter a day of reckoning.  Things would burst into flames, and you'd realize it's more trouble than it's worth to fix this mountain of code.  You'd realize that it looked as you were going fast, but you were really going slow.

About the Author

The Art of Delightful Software is written by Cody Powell. I'm a dev manager at Amazon, where I lead the Instant Video for Kindle team. Before that, I was CTO at Famigo, a venture-funded startup that helps families find and manage mobile content.

Twitter: @codypo
LinkedIn: codypo's profile
Personal blog: Goulash
Email: firstname + firstname lastname dot com

Recent Comments

  • Theodore Brisentine: I am selling the domain and site www.microscopiccolitis.org, please visit read more
  • Joe User: I tend to agree with avoiding indentation, though I'm not read more
  • Leif Mortensen: I'm reminded of a technique we frequently used in my read more
  • Cody: Right now, we're storing around 5000 documents per day and read more
  • Tom: Can you give some specifics. Like how many objects did read more
  • Daniel Molina Wegener: Writing documentation sometimes is a boring task, but it's read more
  • Cody: Murph, you're probably right that you can't get quite this read more
  • murph: this is rad. what if you work in a place read more
  • Cody: Definitely. I think the reasons for rolling my own app read more
  • DasIch: You do realize that Sphinx exists? read more

Categories