I first read Louis Sachar’s Wayside School books in second grade, and I felt as if I’d been psychologically recognized, like a neon fetishist discovering Dan Flavin, or a millennial stoner happening upon “Broad City.” The first in the trilogy, “Sideways Stories from Wayside School,” was published in 1978. Like its sequels, the book revolves around a teacher named Mrs. Jewls, a recess supervisor named Louis, and a gang of sensitive and unruly students. With their clipped, manic chapters, the books, which have sold roughly nine million copies, satisfied an early literary attraction toward absurdity and irregular rhythms; Sachar’s presence as the author was so conspicuous and deliciously idiosyncratic that the trilogy served as my functional introduction to style. Sachar is kind to his characters, but in a way that involves letting them be extremely rude to one another. I had never read anything that had both a surfeit of heart and an absence of sentiment.

I’ve revisited the trilogy fairly often as an adult, but not out of nostalgia: the books are lovely little lessons in craft, structured as neatly as a Rubik’s Cube. Each book has thirty chapters, and Wayside School is thirty stories tall. There’s one classroom on each story, and a Schrödinger-esque situation on floor nineteen. (The nineteenth chapter of the first book, titled “Miss Zarves,” reads, “There is no Miss Zarves. There is no nineteenth story. Sorry.”) It’s high-concept, slightly menacing world-building—Shel Silverstein with hints of Barthelme and Borges. In one chapter of “Sideways Stories,” the children swap names and lose the ability to tell one another apart. In another, a new kid turns out to be a dead rat wearing a dozen raincoats. A ball is tossed up and doesn’t come down; three bald men with briefcases materialize out of the air.

Beneath the madcap storytelling, there is an elusive coherence: the seventeenth chapter of each book is told backward, and the last lines in all three books rhyme. Like fables, the stories make a peculiar kind of sense. A boy named Paul is so enamored of a girl named Leslie’s pigtails that he falls out of a window in a daze of excitement, and Leslie grudgingly lowers her pigtails to help him up. In the third book, Chapter 19 explains, again, that Miss Zarves teaches on the nineteenth story, which does not exist. “And there is no Miss Zarves. You already know all that. But how do you explain the cow in her classroom?” Sachar builds kid-logic jokes into his stories—in 1989, he published a book of absurdist math problems called “Sideways Arithmetic from Wayside School,” in which, for example, a girl named Sue proves that her dog Fangs is a good dog by the equation “good” + “dog” = “fangs.” The letters correspond to numbers, and all the equations work—though I’ve yet to solve one.

That knack for pattern and recurrence, plus Sachar’s ability to fit odd pieces together, make possible the central mechanism of his best-known book, “Holes,” which won a Newbery Medal, in 1999, and was later made into a movie, starring Shia LaBeouf. (Sachar wrote the screenplay.) “Holes” is set at a black-site boot camp for troubled children, who must, as punishment, dig holes in the desert for months on end. The protagonist is a boy named Stanley, who has a misfit friend named Zero. Scenes of their hard labor give way to stories about how each of the kids ended up in the clink. There’s another plot, set in the eighteen-eighties, about a white teacher who falls in love with a black onion seller; and there’s a country legend concerning an outlaw who leaves lipstick kisses on her murder victims; and a tale from eighteen-fifties Latvia involving a marriage, a pig, and a curse that ties all the stories together. It took Sachar several full revisions to make all the strands feel connected, he told me recently. By the end, every detail is intertwined. The old curse threading the motley stories is broken, and rain falls on the desert for the first time in a hundred and ten years.

I met Sachar at an Indian restaurant next to his bridge club on a hot day in Austin, Texas, last fall. Sachar, in jeans and a dark polo shirt, resembled a friendlier and more athletic Larry David: warm brown eyes, a balding crown, and a big, tentative smile. We ordered iced tea and filled our plates from the lunch buffet. He told me about writing his first children’s story, in high school, in Orange County, California, for English class. It was about an evil teacher named Mrs. Gorf. She would later make it into Wayside School, turning students into apples at the beginning of the first book. (Louis “saw twenty-four apples on Mrs. Gorf’s desk. There were only three children left in the class. ‘She must be the best teacher in the world,’ he thought.”)

Mrs. Jewls, the main teacher in the Wayside stories, is based on a teacher named Mrs. Jukes, whom Sachar worked under as a part-time teacher’s aide while he was in college at Berkeley. Sachar started writing about Hillside Elementary, which he renamed Wayside, after finishing college. During the day, he worked at a sweater warehouse. He was fired, for insufficient commitment. He applied to law school, and during his first week of class the “Sideways Stories from Wayside School” manuscript was accepted for publication.

The company that bought the book had spotty distribution, and it folded within a few years, putting Sachar temporarily out of print. (The Wayside School books are now published by Scholastic and HarperCollins, which recently released them as e-books for the first time.) Kids, nonetheless, found his address and wrote him fan letters, which encouraged him to keep working on the sequels. One day, a bundle arrived from an elementary school in Plano, Texas. “Five or six girls included the fact that their teacher was single, and that she thought I was really great,” Sachar said. “I figured I’d embarrass the teacher a little bit, knowing she’d have to read my letter out loud to the class. I wrote back and said, ‘Wow, your teacher sounds really hot.’ ” That teacher eventually invited him to Plano, and a friend of Sachar’s who lived in Dallas insisted that they go. On that visit, during a night out at a country-and-Western bar with school employees, Sachar met a guidance counsellor named Carla, whom he would marry five years later. They had a daughter named Sherre, who now works as a zookeeper, running nighttime tours at Disney’s Animal Kingdom.

When Sherre was eleven, she contributed an essay about her father to a children’s-book trade publication, noting his fondness for helping her with math homework. In a separate essay, Carla described her husband’s daily routine: he wrote every morning, for just a few hours. “The only others allowed in the office with him are our two dogs.” Sachar has more or less stuck to that practice. He never shows anyone what he’s working on until he’s done five or six full revisions, changing the story significantly each time; in the afternoons, he answers fan mail and reads. (When we talked, he’d just finished Jill Leovy’s “Ghettoside.”) He plays bridge three or four times a week, occasionally going out of town for a tournament. (He’s a Sapphire Life Master, in bridge terminology; in March, he played Bill Gates, in a two-day national event.) “I waste a lot of time, too,” Sachar said. “I’ve always wasted a lot of time. In my twenties, I had some angst about this—about not having a real job, or really wanting one. I would play solitaire, and of course this wasn’t even on the computer, and I’d think, One day I’ll regret all this wasted time.” He put down his napkin and gestured toward the tablecloth, the Austin sun blazing through the windows. “But no, I don’t regret it at all!”