Contemporary science fiction is so full of aliens, zombies and apocalypses, the science sometimes gets lost amid the fiction -- which may help to explain why Andy Weir's "The Martian" stands out in the crowd.

Weir's novel, a gripping tale of survival in space, harkens back to the early days of science fiction by masters such as Robert Heinlein, Isaac Asimov and Arthur C. Clarke -- authors Weir has revered since he was a young reader.

If the book's style recalls an earlier time, though, its author says the details are up to the minute.

"All of the science is real," says Weir, an easygoing "space nerd" whose hobbies include relativistic physics and orbital mechanics. "All of the technology exists today, although a lot of it is next generation." Weir, 41, wrote the book as a "what-if scenario," imagining the worst that could happen on a manned mission to Mars.

"The Martian" begins on Ares 3, the third such mission to the Red Planet. Astronaut Mark Watney and his team are on a two-month assignment, but their plans go awry when a dust storm hits. The crew, thinking Mark is dead, returns to Earth without him.

Stranded on a hostile planet with damaged equipment, few supplies and no way to message home, Mark decides to survive. Weir uses a mix of first-person narrative and log entries to tell his story.

Mark is a resourceful protagonist, and "The Martian" benefits from his problem-solving abilities and his breezy, wisecracking point of view.

"He's basically my personality," Weir says. "I'm a smartass like that, but he has all of my strong points and none of my flaws. He's kind of what I wish I were -- smart, cool-headed in stressful situations and really good at handling anxiety."

Weir, who was born in Davis and grew up in Livermore, has a strong science background. He started learning about computers when he was still in high school; at age 15, he got a job at Sandia Labs in Livermore. "They said 'We need you to learn how to program a computer for data analysis,' " he recalls. "I already knew a fair bit about computer programming, because I was a nerd and that was my hobby. But that's where I got kind of good at it."

He studied computer science at UC San Diego and has worked for numerous software companies, including AOL and Blizzard (he was one of the programmers of "Warcraft 2"). Currently based in Mountain View, he works for the mobile device management firm MobileIron.

Writing's always been his hobby; in between jobs in his 20s, he started publishing some of his work on a blog. Along with his first book, "Theft of Pride" -- a space opera peopled by aliens -- he posted short stories, Web comics and other narrative fiction. His readers were "geeks like me," he says, and he amassed a few thousand regular followers.

Everything he published was free, and Weir says he never made an effort to recruit readers -- he didn't advertise, didn't even have a Facebook page. But when he published a short story called "The Egg," his readership mushroomed. The story still gets thousands of hits every day.

Intrigued by the idea of disaster scenarios, he started writing "The Martian" in 2009. Once he had the initial story line, he says, "I started running my poor hapless character through everything that could go wrong."

Weir says he enjoyed researching the book -- subjects such as radiation, botany (Mark is forced to grow potatoes) and fuel systems. "Their big ship, the Hermes, for instance, is powered by ion engines," he explains. "That's technology we have today, but they're nowhere near as large scale as what's depicted in the book. You could make them, and they're working on that, because one of the big problems with going to Mars is that you need so much fuel. Using ion engines, you need much less."

When the book was finished, he posted it on his blog. From there, it went to e-reader format. In 2012, Amazon picked it up as a Kindle book. The response was huge. "Amazon has an amazing reach," says Weir. "A lot more people bought it than read it on my site for free." It made Amazon's top 200 overall list, and got the attention of Random House, which published it in hardcover last month. Since then, it has already made its appearance on the New York Times list of fiction best-sellers and on the Bay Area list published by the Northern California independent booksellers.

Now it appears "The Martian" may launch on another level: 20th Century Fox has optioned the film rights. Weir estimates there's "a single-digit-percent chance" the movie will be made. "But I'll be stoked if it is."