The Silicon Valley presented in the terrific new HBO comedy of the same name (it debuts Sunday night at 10) is a kind of Wild West for nerds: a lawless territory where they can be among their own kind rather than struggle to fit into a more structured world that doesn't understand them, and a place where they can seek massive fortune along the way. 

That vision of the Valley also fits HBO itself in a way, since it's long been a place where creative types with idiosyncratic personalities and specific, uncompromising creative visions could go to find success in a safer, more wide-open environment. It's where David Chase could go when he was on the verge of quitting the TV business altogether and tell the story of a wiseguy in therapy. It's where David Milch could go to be given the absolute freedom to succeed so beautifully with "Deadwood" (and then fail so impressively with "John from Cincinnati"). It's where the director and star of an incredibly obscure independent film could be given the chance to make "Girls" and become a cultural lightning rod.

And now it's the place where Mike Judge has happily found himself after several years in the wilderness, and with the best project he's been involved with in a very long time.

Judge had his time in the mainstream. "Beavis & Butt-Head" was a cultural phenomenon. "King of the Hill" ran forever on FOX and was wonderful for nearly all of that time. But 1999's "Office Space," which is revered today as the definitive film about the inhumanity of life in a cubicle, was a box office flop at the time, and there were long gaps before his next two films, 2006's "Idiocracy" (a disturbingly prophetic film about how we as a society are getting dumber) and 2009's "Extract" (a forgettable midlife crisis story). His ABC animated comedy "The Goode Family" was burned off in the summer, and even MTV's ballyhooed "Beavis & Butt-Head" revival only lasted a few months.

And now Judge has (with frequent collaborators John Altschuler and Dave Krinsky) found a home at HBO, and based on the first five episodes (out of eight in this season) of "Silicon Valley," it's a perfect marriage of creative team, channel and subject.

The show introduces us to Richard (Thomas Middleditch), a low-level coder at a fictionalized Google(*) called Hooli, who lives in an "incubator" house run by Erlich (T.J. Miller), a cocky stoner living off the money he made from selling a water fountain locator app and getting a 10% stake in all his tenants' creations on the off-chance they hit it big. And almost by accident, Richard's app — whose broad applications even he doesn't understand at first — becomes subject of a bidding war between Hooli's smug chairman Gavin (Matt Ross, Alby from "Big Love") and Gavin's eccentric ex-partner Peter Gregory (Christopher Evan Welch), and Richard has to choose between a one-time payment that will change his life or taking a bigger bet that could make him obscenely wealthy or make him yet another cautionary tale of the Valley.

(*) Between Hooli, ChumHum on "The Good Wife" and a great upcoming episode of this show's lead-out "Veep" set at a place called Clovis, this is truly a golden age for fake Googles.

There are some hints of "Entourage" in the DNA (perhaps cross-pollinated with some "Big Bang Theory"), but never the sense that things will always work out for Richard in the way they inevitably did for Vince and his boys. And even in the early episodes, "Silicon Valley" is already much funnier and smarter than "Entourage" was even in its better  days.

From minute one, Judge and company are making sharp observations about the rules and customs of this strange subculture. We begin, for instance, at a party for a start-up that has hit it big (with Kid Rock as entertainment, because why not?), and Richard's housemate Dinesh (Kumail Nanjiani) observes the rapid segregation between the male and female guests(**), noting that every party in the Valley "ends up like a Chasidic wedding." Even within this kingdom of nerds, there are social hierarchies. Richard is envious of Erlich's confidence, and gets taunted by the higher-ranking Hooli staffers, while the reserved Dinesh seems to be waging a constantly losing battle for coding and social superiority to Satanist ("with theistic tendencies," he explains) housemate Gilfoyle (Martin Starr). Richard is gawky and awkward, and yet so long as his company also employs business expert Jared (the perpetually self-deprecating Zach Woods) — who admits, "I know I have somewhat ghost-like features. My uncle always said, 'You look like you starved a virgin to death.'" — he will never be the gawkiest.  
 
(**) If the series has an obvious area for improvement, it's in its extreme gender imbalance. There's only one female castmember — Amanda Crew as Peter's assistant Monica — and while this may be a predominantly male world, just from a comic standpoint the show would benefit from an added voice. As Fienberg suggested on Firewall & Iceberg this week, have Felicia Day (or at least a Felicia Day type) move into the house and see what happens.   

In the battle between Gavin and Peter, the show explores contrasting management and personal styles. Both are geeks, but Gavin is one who has been able to shape himself into someone who moves comfortably in the world of both celebrities and fellow CEOs, while Peter remains isolated and inscrutable, speaking in an odd, clipped manner and never for a moment looking comfortable in his own skin. (Welch's performance is the best part of a show with a lot of great parts, and he unfortunately passed away midway through production of this first season. Judge has said this won't affect the stories for the first season, but it's a big loss.) And as Richard tries to get his company off the ground, he gets many pieces of conflicting advice about what sort of boss he should be. Erlich, for instance, makes the familiar argument that any successful manager has to be an asshole, because if you're not, "it creates a kind of asshole vacuum," and the show finds amusing ways to explore whether that's really true.

And yet in the middle of all the technobabble and social satire, "Silicon Valley" is also a show from the man who gave us "Beavis & Butt-Head," and like so many of Judge's later works, it deftly blends the highbrow with the lowbrow. The show features drug humor and fairly crude (if usually clever) sex jokes, and almost all of it flows in neatly with the headier stuff going on. When Erlich, for instance, commissions a Latino graffiti artist to design the company logo, it at once leads to a series of marvelously profane visual gags and to a commentary about both racism and the sameness of corporate branding. And there are elaborate comic set pieces about the ways in which technology that's supposed to make life simpler instead makes it more aggravating that function as both satire and slapstick at once. It's really impressive, and definitely the closest Judge has ever come to simply making "Office Space: The Series," in tone if not in specific target.

Judge isn't the only person involved in the show in need of an unconventional home like HBO. Most of the cast has experience playing nerds and outcasts, but usually as the token one in a larger ensemble, if that. (A sitcom producer I know said he was happy to see Middleditch as a series lead, because during pilot season, he's always "so funny but way too specific for almost any part.") Here, placed opposite each other, they get to reveal more facets of their default screen personas, becoming funnier and richer in the process.

There's a great gag in a later episode about Gavin trying to impress an employee with new communications device that is cool in theory but still a few upgrades away from working in practice. "Silicon Valley," on the other hand, is the right show in the right medium, on the right channel, at the right time.

Alan Sepinwall may be reached at sepinwall@hitfix.com