Instagram Strikes a Sizable Blow in Silicon Valley’s Tabs Vs Spaces War
The latest season of Silicon Valley confronts one of the great questions of modern tech: tabs or spaces?
Richard Hendricks, the fictional startup founder at the heart of the HBO series, believes in tabs. That’s what he requires from his company’s coders—and the mother of his children. “I mean, like, what? We’re going to bring kids into the world with this hanging over their head?” he tells the Facebook coder he’s (sorta) dating, after she types a long row of spaces into her laptop.
“Kids?” she responds. “We haven’t even slept together.”
“And guess what? That’s never going to happen now,” he says. “Because there’s no way I’m going to be with someone who uses spaces over tabs.”
Per usual, the show exaggerates its portrait of the modern tech world—but only slightly. When writing software code, some people indent with tabs, because it’s quicker than typing a long string of spaces and it uses less digital storage space. But others indent with spaces, because different text editors format tabs in different ways, which changes how the code looks as it moves from machine to machine. And all this is more than mere trivia. In the real Silicon Valley, seemingly inconsequential technical choices play a sizeable role in the progress of Internet startups—if not the progress of semi-romantic relationships.
Take Instagram, the photo-happy social network owned by Facebook. Mike Krieger, the company’s co-founder and chief technology officer, believes in spaces. And that’s probably because he believes in a programming language called Python. Most people who believe in Python believe in spaces. They believe in aesthetics. They believe in clarity. They believe in a language that makes it as easy as possible for anyone to build a reliable piece of software—and for anyone else to modify and improve and expand that software. “We strive for simplicity,” Krieger says of Instagram.
This attitude comes with a cost. Richard Hendricks would surely scoff at Krieger’s choices, because, in a technical sense, they aren’t as efficient as others. But for Krieger and company, aesthetics outweigh raw efficiency. And they’ve shown that they’re right. At least in some ways. Today, they announced that Instagram is now used by over 500 million people each month, with over 300 million checking in each day. The aesthetic route is working just fine.
One of the chief benefits of Python, Krieger and others say, is that it’s so easy to read. Yes, read. Whereas other languages separate code with curly queues and the like, Python separates code with indentions or whitespace. This is required. Sure, you can make these indentions with tabs as well as spaces. But Krieger, like so many Python coders, prefers spaces. That means the code is just as readable on any machine.
But there’s a trade-off: Python doesn’t scale as well as other languages. In other words, if you build an online service with Python and it ends up reaching hundreds of million of people, you’ll need far more machines to keep it going. You can write code quickly in Python, but the code doesn’t execute as quickly as software built with some other languages, says Daniel Greenfield, a Python specialist with Internet consultancy Cartwheel Web. You need more computer servers to maintain the speed of your app or service.
Historically, this is a trade-off that characterized so much of the coding world. Either you chose a language that was easy to use, like Python, or you chose a language that was fast, like C++. Now, big name tech companies are working to create a new breed of languages that offer the best of both worlds: speed of development and speed of execution. This includes Google’s Go, Apple’s Swift, and Mozilla’s Rust. But at the same time, companies are finding ways of pushing existing languages past their traditional boundaries.
Facebook has done this with a language called PHP, showing that it could scale to over 1.5 billion people. And Instagram has done something (kinda) similar with Python. Its audience isn’t as large as the one over at Facebook. But 500 million is hardly a small number.
A Different Route
Krieger and company starting building the original Instagram in 2009, and Python was a natural way to go. It was a popular language in those days, because it was interpreted and dynamic. Basically, they didn’t need to be as careful—as exact—in building their code. They could move quickly, without worry.
Today, Python is still popular. According to coding consultant TIOBE, it’s the world’s fourth most popular option, behind Java, C, and C++. But on today’s Internet—where services reach hundreds of millions of people—it faces new obstacles. An interpreted, dynamic language doesn’t execute as quickly as compiled, static languages like C++. Instagram has seen this first hand.
The company could have switched to a different language. That’s what Twitter did. It could have tried to rebuild the very foundations of the language. That’s what Facebook did with PHP. But Instagram look a different route. Rather than really moving away from Python or really trying to change the language, it found all sorts of small ways to tweak its Python code so that it could efficiently serve those 500 million people.
Most notably, using a tool called cprofile, Krieger and company worked to identify their slowest pieces of Python code. “We believe in measuring first before taking action,” says head of infrastructure Hui Ding. Then, using a second tool called Cython, they converted these pockets of slow code into C or C++. According to the company, this allows Instagram to run with 10 to 15 percent less processing power.
Code You Can Read
Yes, by sprinkling C and C++ code into their Python, they lose some of those clean aesthetics that Krieger believes in. But across the much larger expanse of code, the elegance remains, spaces and all. And that crisp organization allows Instagram’s coders to update and expand and improve the service at speed—something that’s just as important on the modern Internet.
“Programmers spend a lot more time reading code than writing code,” Krieger says. “A lot of coding is understanding what has come before.”
That may seem a small thing. But Instagram is very big. And to get that big, you must scale in more ways than one. As Krieger points out, you can’t build a service like this on your own. You must share your work with so many others. And that’s where those aesthetics become so important. You want to write code that everyone else can easily read and understand—on any machine. Put like this, his choices seem quite sensible. Unless you’re a tabs person.
View original post here –