Wednesday, February 11, 2015

Hello, Startup

Today, I'm excited to announce the early release of my book, Hello, Startup: A Programmer's Guide to Building Products, Technologies, and Teams.
This is the book that I wish I had when I was in college. By the time I graduated, I had a BS, a Masters, a bunch of internships—and absolutely no idea what I was doing.

I remember one of the first big projects I built by myself was a desktop application for performance testing at Thomson Financial. I had no idea how to create a user interface, so I randomly sprinkled text fields, menus, and buttons across the screen. I had no idea how to reason about performance, so I randomly sprinkled caches and thread pools across the code. And I had no idea how to think about code maintenance, so I didn't bother with tests, comments, or documentation, but I did manage to cram several thousand lines of multi-threaded Java code into one gigantic class.

I remember my first project at TripAdvisor was to add new sort options to the webpage that listed all the hotels in a city. It was a quick task, just enough to become familiar with the code base, and I was able to get it done and pushed to production in my first week. Shortly after, I was in my manager's office for our first one-on-one meeting, and I watched as he clicked on the hotel listings for Paris, selected the new sort option, and then waited. And waited. And waited. It took nearly two hours for the page to load. Well, it was probably closer to two minutes, but I'm pretty sure there is a law of special relativity that causes time to dilate when you're sweating that profusely and just hoping you can melt through the floor and disappear. Later that night—much later—I figured out that my fancy new code was making two database calls every time it compared hotels during the sorting process. It takes on the order of n log n comparisons to sort n items, so for Paris, which has roughly n = 2,000 hotels, that works out to roughly 40,000 database calls for a single page load. I may not have melted that day, but our database server nearly did.

I remember lots of other nasty bugs, ugly code, uglier user interfaces, site outages, and late nights. But mostly, I remember having tons of questions, and no easy way to find an answer. What technologies should I learn and use? Why should I bother with automated tests? How do I build a product that doesn't look terrible? How do I get people to use my product? How do I negotiate a job offer? Should I negotiate for more salary or more equity? What is equity, anyway? Should I work at a large company or join a startup?

I learned the answers to these questions, and many others, the hard way. I tried to capture what I learned, much of it the result of painful trial and error, in blog posts and talks, but after
realizing that thousands of other developers were going through the same trial and error process, making the same mistakes, and still having nowhere to turn with the same questions, I decided it was time to do something more substantial. This book is the result. Of course, some lessons you can only learn by making your own mistakes, but for the rest, I hope Hello, Startup will save you a lot of pain by letting you learn from the mistakes of others.

My goal with the book was to create a practical, actionable, how-to guide—a "Hello, World" tutorial, so to speak—for building products, technologies, and teams in a startup environment. The material is based on my own experiences, as well as interviews with programmers from some of the most successful startups of the last decade, including Google, Facebook, LinkedIn, Twitter, GitHub, Stripe, Instagram, AdMob, Pinterest, and many others.

If you're at all interested in startups—whether you're a programmer at the beginning of your career, a seasoned developer bored with the politics of large companies, a manager trying to figure out how to motivate your engineers, or just someone trying to figure out what this startup thing is all about—this book is for you.

Learn more about Hello, Startup and get yourself an early release copy of the book at

Friday, February 6, 2015

Are static typing and functional programming winning?

Inspired by a reddit discussion, I decided to create short blog post to ask two questions:
  1. Is static typing winning?
  2. Is functional programming winning?
In other words, are we at a turning point where most modern languages are moving towards static typing and functional programming? Let's consider the evidence.

Static typing

Some of the most popular dynamic languages are considering some form of static typing:
  1. Ruby: Matz announced that Ruby 3.0 may have type annotations.
  2. Python: Guido van Rossum sent out a proposal to add type annotations to Python.
  3. PHP: Facebook has released Hack, which supports type annotations on top of the PHP syntax. Moreover, PHP itself already has Type Hinting and may add return type declarations.
  4. JavaScript: Facebook has released Flow, Microsoft has released TypeScript, Google has released Dart and AtScript, and there are many statically typed languages that compile to JavaScript, including GWT (Java to JavaScript), Scala.js (Scala to JavaScript), Haste (Haskell to JavaScript), and purescript (Haskell-ish to JavaScript).
Of course, most of these type systems are not as strict as, say, Haskell, but whether you call it static typing, gradual typing, type hinting, type inference, or type annotations, the goal everywhere seems to be the same: try to catch more errors at compile time instead of run time

Functional programming

Similarly, some of the most popular imperative languages are adding features from functional programming:
  1. Java: version 8 added lambdas, functional interfaces (i.e. functions, almost), method references (i.e. first class functions, almost), and the stream API.
  2. C++: version 11 and version 14 added support for functional programming features.
  3. C#: there is a book and several guides on functional programming in C#.
  4. Swift: Apple's new language for iOS and OS X has many functional programming features.
  5. JavaScript: I'm seeing more and more functional JavaScript these days thanks to things like underscore.js, promises (ie, monads), react.jsbacon.js, and compile-to-JS languages like ClojureScript.
Of course, tossing in a few functional features does not a functional programming language make, but still, the trend is encouraging. Moreover, languages that are functional at their core seem to be growing in popularity too: 
What's the future?

There is some research that shows that static typing and functional programming are modestly better than dynamic typing and imperative programming, respectively (albeit it's far from air tight). That said, I've been hearing this sort of hype for a long time, and only in the last year or two do I feel like it's finally starting to make a noticeable dent in the industry.

Are you noticing the same trends? Do you like seeing more static typing and functional programming? Will we all be Haskell programmers soon?

Leave your thoughts as a comment or discuss this post on reddit and Hacker News.

Monday, September 29, 2014

Node.js vs Play Framework

Here's the showdown you've been waiting for: Node.js vs Play Framework. Both are popular open source web frameworks that are built for developer productivity, asynchronous I/O, and the real time web. But which one is easier to learn, test, deploy, debug, and scale? Should you pick Javascript or Scala? The Google v8 engine or the JVM? NPM or Ivy? Grunt or SBT?

Two frameworks enter, one framework leaves.

This was my presentation from the 2014 Scala Matsuri Conference in Japan. My hope is that the talk is useful not only as a comparison between these two specific frameworks, but also as a model for how to evaluate other web frameworks in the future:
  1. Learn: getting started, ramp up, overall learning curve.
  2. Develop: routing, templates, i18n, forms, json, xml, data store access, real time web.
  3. Test: unit tests, functional tests, integration tests, test coverage.
  4. Secure: CSRF, XSS, code injection, headers, authentication, security advisories.
  5. Build: compile, run tests, preprocess static content (sass/less/CoffeScript), package.
  6. Deploy: hosting, monitoring, configuration.
  7. Debug: step by step debugger, profilers, logging, 
  8. Scale: throughput, latency, concurrency.
  9. Maintain: code reuse, stability, maturity, type safety, IDEs.
  10. Share: open source activity, mailing lists, popularity, plugins, commercial support, jobs.
The next time a hot new framework pops up on Hacker News or Reddit, before betting your company's future on it, use this checklist to see how it stacks up against the more mature (and boring) options. Also, if you've got a Node.js or Play Framework story to share, leave a comment!

(Discussion on HN)

Sunday, August 10, 2014

The best minds of my generation are thinking about how to make people click ads - and that's ok.

"The best minds of my generation are thinking about how to make people click ads. That sucks." - Jeff Hammerbacher
There is a meme going around that too many programmers are wasting their careers working on meaningless software: they spend all their time trying to get people to click on ads, they aren't tackling the important stuff, and they aren't solving the biggest problems of today. It's as if all programmers should drop what they are doing and instead try to cure cancer, end world hunger, and generally save the world.

I'm going to call bullshit.

First of all, don't knock ads--or, to be more accurate, don't not knock making money. The most well intentioned company in the world can't accomplish any of its lofty goals if it has no money, and for many companies, ads are the best way to earn that money.

For example, you are probably one of the billion plus people who search Google over 100 billion times per month (!) to help plan your day, learn new information, and answer questions. It's hard to imagine life without it.
Google also builds maps, videoemailphones, and even more recently, they are trying to provide Internet access for everyone in the world, define what it means to be a healthy human, and to create self-driving cars. And all of this is powered by ads: more than 90% of Google's revenue comes from advertising.

If you kept in touch with your friends and family, read the news, or even followed a link to this blog post, it was probably through Twitter or Facebook. Twitter has played a part in starting revolutions in several countries; so has Facebook. In fact, almost everyone with Internet access has been touched by Facebook (they have 1.32 billion active monthly users) and for those without Internet access, Facebook is trying to help. And just like Google, 90% of Twitter's revenue and nearly 90% of Facebook's revenue comes from ads.

Many talented engineers spent enormous amounts of time at these companies getting you to click on those ads. The result, I'd argue, has been remarkably world changing: three companies, driven primarily by ad clicks, have connected us to information and to each other like never before. It's almost as if Adam Smith was on to something with the whole invisible hand idea.

But this debate isn't really about ads. I'm guessing what people are actually upset about is that so many talented developers are working on products that are not "important". That is, they are building software for their own personal amusement or financial gain instead of working for the benefit of us all.

Well, here's a question: how do we determine which companies or ideas will most benefit the world?

In a remarkable talk called The Importance of Mathematics, Timothy Gowers tackles this same question with regards to mathematics:

Gowers claims that most mathematicians are drawn to intellectually interesting problems rather than practical ones. In fact, he talks about the famous Cambridge mathematician G. H. Hardy, who was "perfectly content, indeed almost proud, that his chosen field, Number Theory, had no applications, either then or in the foreseeable future. For him, the main criterion of mathematical worth was beauty."

Many mathematicians prefer problems that are beautiful to those that are useful. Despite that, mathematics has been the basis for countless discoveries of immense practical value: physicists, chemists, engineers, programmers, and countless others use math on a daily basis to build all the tools and technology of modern society. Even Number Theory, which seems entirely like math for math's sake, turns out to have many practical applications, including RSA encryption, the basis of all Internet security, and the reason you can use passwords, credit card numbers, and exchange other information online securely. Hardy would've been disappointed.
Gower's diagram of math knowledge: there is no way to separate the "useful" and the "useless"
Math is deeply interconnected and unpredictable: there is simply no way to know which parts of it will turn out to be important in the real world and which parts won't. The world of companies and products is similar: there is simply no way to know what companies or ideas will end up being a huge benefit to the world and which ones won't.

For example, it would've been hard to argue an algorithm inspired by citation analysis could change the world so profoundly--even Larry Page was not convinced as, in the late 90's, he offered to sell the company to Excite for just $1.6M (today, Google is worth around $400B). Many people would scoff at the idea of starting a company to share podcasts, but this is actually the origin of Twitter. As many as 50% of all scientific discoveries may happen by accident and many of the most world-changing ones were not the result of an explicit effort to save humanity (examples). Even the porn industry has had a profound impact on technology. You never know what will change the world.

There is an old Soviet joke my dad used to tell:

Stalin asks his staff, "how many movies do we make per year?"
"100 movies, Comrade Stalin."
"And how many of them turn out good?"
"10, Comrade Stalin."
"Alright, next year, only make the 10 good ones."

Of course, this isn't a justification to blindly build dumb crap, JerkTech, or anything actively harmful. This is not an excuse to work on projects you don't care about nor a reason to put up with Dilbert-like jobs. This post is a call for moderation: it would be impractical for everyone to try to work on projects that obviously change the world; it would be misguided to abandon all projects that change the world, but not obviously.

If you've got the passion and the skills to cure cancer or take on world hunger, then by all means, do it. But if you don't--and many people don't--it's perfectly fine to work on something else you're passionate about. If you can build something people want, you have a chance to make the world a better place. Even if it involves ads.

Tuesday, July 15, 2014

The Saga Of The Stank

My hand is over my mouth, my eyes are watering, and I'm trying to hold my breath, but every few seconds, my throat tries to turn itself inside out. Most smells, after a little while, fade into the background -- you become desensitized and can no longer detect them. But not this smell. You remember the sloth scene from Se7en? The one where the cops, handkerchiefs over their mouths, walk into a room that has hundreds of Little Tree car air fresheners hanging from the ceiling and find a guy who has been chained to a bed for a year, living in his own waste while his body rotted away? It was like that. Minus the air fresheners.

A week ago, Molly and I had entered our apartment for the first time after a month and a half of traveling. We had been to the Philippines, Thailand, Boston, and were finally home, after a long flight. It was nearly midnight and all I wanted to do was bury my face in a pillow, cocoon myself in a blanket, and breath in my bed, which smells like sleep. Instead, I found myself breathing in noxious fumes. Which smell like noxious fumes.

Molly's first guess was that we had forgotten to take out the trash, but when we checked, it was empty. I looked for anything rotting in the sink, but it was spotless. Molly cracked open the fridge -- also empty. However, as she closed the refrigerator door, it pushed some air out of the fridge and in our direction. A second later, a wave of warm, putrid shit smelling foulness washed over us.

"Oh dear, we've got to deal with this", I said. Or maybe it was something more along the lines of "Oh Jesus fuck what the shit is that???"

I readied myself and peeled the fridge door open again and peered around. We had eaten or thrown out all the food before leaving on vacation, so the shelves were empty. All that remained were a few crumbs and stains. And yet, a cloud of corruption was flooding out of the fridge -- I swear I could see green stink lines.

"We've got to clean this up", I said. Molly suggests it was more like "Oh come on! Why the... what is the... what the fuck is that goddamn smell???" It was go time.

Approximate re-enactment of me approaching the fridge
Molly and I began pulling out the shelves and drawers and washing them. The fumes of -- what was it? Rotten eggs and a dead skunk floating in a bath of spoiled milk? -- continued to waft through the apartment. We were finally on the last shelf when I randomly decided to peer into the freezer. Although the fridge was empty, we had left the freezer running to preserve frozen goods and various condiments. I peered around and saw a package of ravioli, a bag of Ikea meatballs, a bottle of maple syrup, some pink liquid, and then, wait a second, on the door... Oh god, what the hell was that??

I slammed the freezer door shut.

The creature I thought I had seen on my freezer door
My brain was still processing what I had seen. Unfortunately, shutting the freezer door had pushed out a new cloud of noxious gas that nearly knocked me unconscious. As I came to, I began to wonder: why did the freezer smell worse than the fridge? Why was there an Alien facehugger on my freezer door? But most of all, I couldn't get out of my mind the pink liquid in the freezer.

Wait a minute, why was there liquid in my freezer?

I took a peek at the controls in the fridge:

Pop quiz: what happens if you leave the freezer setting at "4", but turn the refrigerator setting to "off"? Did you say that both the freezer and refrigerator shut off? Because that's exactly what happened. For the entire time we were traveling. That's 1.5 months.

For six weeks, some monstrosity had been stewing, growing, incubating in my freezer. We had been scrubbing the refrigerator shelves, but all this time, the real evil lay quietly above. But what was it? What fiend lay in waiting?

I had to know. But I didn't want to know. Molly and I stared at each other. Our imaginations danced. Within the freezer, there lurked unknown dangers, and I felt naked. Actually, I was mostly naked, because I had stripped down after noticing that the putrid smell was getting in my clothes. I searched the house for some protection and found... a single glove. Not zero, not two, but one glove. Seriously, I don't understand why you would have just a single rubber glove, but there you have it. It was purple.

I also found a bottle of Lysol, but it was almost empty. So there I was, wearing a pair of boxers and a single rubber glove, holding a bottle of Lysol, heading into the den of a dragon that could peel the armor off an Abrams tank with a single breath.

I closed my eyes and pulled at the freezer door. As it swung open, I caught sight of a pint of Ben and Jerry's ice cream that had transformed into a Xenomorph egg. No, that's not right. The ice cream had spawned a huge blob of mold that tore through the lid and crawled, stretched, and oozed its fuzzy blue green body up the freezer door. I brought the lysol up, took aim... but I was too late. As the door swung a bit further, the full power of the smell hit me.

Later, when I told this story to my sister, she asked why I didn't take a picture of the mold. The answer is that this was not mold. This was biological warfare, a weapon of mass destruction, the poison gas from the Hunger Games that causes your skin to burst into boils on contact. As the toxic cloud washed over me, it was as if millions of voices suddenly cried out in terror... and then farted. A smell so foul that we gave it a name: it became known as The Stank. This was no time for selfies.

My senses returned to me and I went to war. With one hand, I shoveled all the food left in the freezer into the trash. With the other, I began spraying with lysol. And I kept spraying. And spraying. And spraying. And spraying some more.

A reenactment of our battle against The Stank.
Finally, the bottle was empty. Now, the hard part. I had to wipe it all down. That meant reaching my hand - the one gloved hand - into The Stank. This had all the appeal of reaching straight into Satan's asshole.

I don't really remember what happened next. Somehow, hours later, I was huddled in corner of the shower, knees pressed to my chest. No amount of soap could wash out The Stank.

But our battle was not finished. The next day, the freezer still smelled horrible. We washed everything with soap and water. Then we tried baking soda and water. Then vinegar and water. Then we realized it isn't a great idea to mix baking soda and vinegar, unless, of course, you're trying to create a volcano for your 4th grade science fair.

The next day, the smell was still there. We went out and bought an anti-mold spray that contained bleach. We filled the fridge and freezer with the stuff and let the chlorine gas waft through it. It didn't help.

Then we filled the fridge with smell absorbers: baking soda, charcoal, coffee grinds, oatmeal. We packed plates, bowls, and cookie trays full of the stuff and arranged it in the fridge. It looked like an altar of offerings to a vengeful god. It was our tribute to The Stank. It was not enough.

Worse yet, The Stank followed us. A smell that powerful doesn't just go away when you leave the house. You begin to imagine The Stank everywhere you go. The funky cheese at the fancy restaurant reminds you of The Stank; the bathroom at the library smells of Stank; does that guy on the treadmill have terrible body odor or is that The Stank too? Wait, do I smell like The Stank? Have I become The Stank?

We spent a full week trying every remedy imaginable. We took out shelves, we unscrewed panels, we scrubbed, wiped, sprayed, brushed, and polished every surface. Every visible inch of the fridge became a shiny, unnatural white. But despite it all, The Stank remained.

Finally, today, we ordered a new fridge. The Stank won.

So, kids, here's the moral of the story:
  1. Fuck the environment. We tried to be green -- to save a little energy by shutting off the fridge during our trip. In return, we got The Stank. In fact, once you factor in all the chemical cleaning products, the rolls of paper towels, the years of our lives lost breathing in spores and cleaning agents, and the need to buy and ship a new fridge, I'm not entirely convinced our conservation efforts paid off.
  2. Fuck bad design. If your fridge has separate control knobs for the fridge and freezer, perhaps they should really be separate? Learn design, learn the principle of least surprise, and don't make me think.