Writing Good Code Is a Lot Like Making Beautiful Music
Richard Plom is a coder and a musician. He leads development of the iPhone app at Vine, after more than a decade of coding at Apple, and on the side, using a modular synthesizer, Apple’s Logic Pro software, and a classical Indian instrument called the sarod, he makes his own tunes.
This isn’t unusual. “Some of the best musicians I know are also engineers,” Plom says, pointing to various coders among the vast ranks at Apple. The two pastimes, you see, aren’t as different as they might seem. “Good code—when it’s written the right way—sings,” Plom explains. “It’s like constructing a song.”
‘When a coder has musical training, I can instantly tell when looking at their code. There’s a feeling to it. When you read it, it’s almost like poetry.’ Richard Plom, Vine
He isn’t alone in making the observation. Mike Hadlow, a freelance developer and an amateur guitarist in the UK, has written about this before. “Pretty much everywhere I go to work—and I work at a lot of places—you find people who are musicians,” he tells WIRED, in describing his coding gigs. “It does seem more preponderant than in the general population.” But recently, at Vine, Plom took the code-music relationship a bit further when he went to work on a new technology called “Snap to Beat.”
Vine, an outfit owned by Twitter, runs an online service for sharing 6.5-second videos that play in a loop. And Snap to Beat provides a way of adding music to these videos so that, when they loop, the music seems as if it’s never-ending—so that you can’t tell where it starts and where it finishes. Vine calls these “perfect loops” or “seamless loops.” Particularly skilled Viners have done this for a while, in an ad hoc way, but the company wanted to give everyone a set of tools that could pull the same trick.
“When the design and [UX] guys came up with the idea, I knew exactly what we needed to build.” Plom says, referring to Vine designer Ryan Swigart and the guy who oversaw the project, head of UX Jason Mante, both of whom, by the way, also are musicians.
Giving the iPhone Ears
What Plom did—with code—was teach a machine to understand music the way he understands music. Creating perfect loops is about finding a point in a song that can serve as the beginning and the end. “If you listen to the Vine and close your eyes,” Plom says, “it feels like an infinite song.” This requires an ear. So, in a way, Plom and the rest of the team gave the machine their ears. They built a way of converting a song into something the app could “hear.”
“A computer isn’t human. It doesn’t necessarily listen to music in the same way we do. It just interpolates bits and reconstructs a wave form from those bits. It doesn’t have any knowledge of what it’s playing,” Plom says. “We had to figure out how to detect, in the music, what naturally wants to repeat.”
That kind of listening isn’t easy, even for a human. And building a tool that mimics this is even harder. With Snap to Beat—built with Apple’s programming language Swift—Plom and Co. taught their app to identify those natural loop points by building a digital representation of the beats and measures in the music, as you can see this in the “visualization” that Snap to Beat creates for each song. Plus, they had to do this within Vine’s 6.5-second time limit. And they had to sync it with the images in the video. “You have to work really hard to make something so simple,” Plom says.
Concentration and Craft
In some ways, these loops are a mere curiosity, like so many Vine videos. In others, they’re quite fascinating, reminiscent of Shepard Scales, endless sound loops that seem to perpetually rise in tone. But as AI researcher Doug Lenat notes, Shepard Scales quickly become annoying. Perfect loops have more charm. And the technology Plom built to make them happen is both intriguing and useful in its own right. Twitter is seeking a patent on the technology (a patent that, through its Inventor’s Patent Agreement, will be shared with the developers at large).
What’s more, the technology underscores the connection between coding and making music. Hadlow sees the connection in simple terms: they both require a personality that is happy to concentrate deeply on something for a long period of time, puzzling things out. But Plom goes further. “When a coder has musical training, I can instantly tell when looking at their code,” Plom says. “There’s a feeling to it. When you read it, it’s almost like poetry.”
You get a glimpse of that watching a Vine video with a perfect loop. It’s music, driven by code. And in a way, it resembles code, which often include loops. But at the same time, to use Plom’s term, these Vine videos “sing”—in multiple ways. And reaching that point requires a quality found in coders and musicians and coder-musicians. As Plom describes it: “It’s a way of thinking.”