advertisement
advertisement
advertisement
  • 11.12.10

Can Computer Code Be Greener? Facebook Thinks So

One of Facebook’s green initiatives involves converting their software from one language to another. What makes one code greener than another?

Facebook, which is getting some negative PR on environmental issues, recently announced several green initiatives. Some
of them are intuitive: getting employees to cut down on water
usage, a shuttle bus, composting. Most intriguing, though, is one initiative to ensure that the
very code written by Facebook’s programmers is itself as green as
possible, something achieved by converting Facebook’s code from one
language called PHP to another called C++.

advertisement

How can it be that one type of computer code is “greener” than another? And what is the greenest code?

Some
programming languages are more energy efficient than others because
they simply run faster. A program that can be executed faster reduces the load on a central processing unit, which in turn demands less energy from the massive data centers run by Facebook that pull electricity from the grid. The question, “Which programming languages are
greenest?” is actually just another way of asking which produces the
fastest code, says David Andersen, an assistant professor of computer
science at Carnegie Mellon. “That’s a question we computer geeks love to
fight about.”

For the most part, though, the computer geek
consensus is that the so-called “interpreted” languages like PHP are
slower than the “compiled” languages like C++. In general, interpreted
languages are easier to program in, but take longer to run. “If you
write the same program in PHP or C++ ,” says Andersen, “you’ll find the
C++ version takes ten times as many lines of code to write, making it
harder, but the program in C++ runs five times faster.”

It might seem counterintuitive that a program with more lines of code would run faster.
But since C++ is rawer, in a sense–closer to those ones and zeroes
that computers ultimately run on–it means there is less digestion, so
to speak, involved. “C++ is converted to machine code before being run,” says Joel
Ross, a Ph.D. student in UC Irvine’s Social Code Group, “whereas PHP,
every time you run it, it has to get converted.”

Is C++ always the fastest language? Not necessarily, says Ross: “Languages can have different strengths.” (And there are hundreds,
if not thousands, of them.) Kathleen Fiehrer, an Intel employee
affiliated with the Climate Savers Computing Initiative, explains that
in a personal computer, you want a language that will “race to
idle”–that is, finish a given job as fast as possible, then let the
computer rest. For servers, on the other hand, which are constantly
active, you just want to be assured that you are getting an optimal
performance/watt ratio.

So is there such a thing as the “greenest
code”? No. “In general, I would say there is no one language that is the
fastest–it’s application specific,” says Bill Tomlinson, Director of
the Social Code Group and author of the book Greening Through IT.

advertisement

Tomlinson further complicates matters by questioning the notion that an energy-efficient Facebook necessarily
translates into a greener–in the sense of more sustainable–world. If
Facebook halves its energy expenditure but doubles its size or its user
base, “that may not make the world more sustainable, but rather just make
more Facebook,” he says.

[Image: Flickr user n3wjack]

About the author

David Zax is a contributing writer for Fast Company. His writing has appeared in many publications, including Smithsonian, Slate, Wired, and The Wall Street Journal.

More