Sixth-grader Max has had it with the bullying tactics of the resident “cool guy” from his extended group of peers.

“F--- you Atticus!” he cries. “Everybody knows your mom …”

I’m not going to reveal the punchline here so as not to spoil the one-liner (it’s one of the best one-liners of the year) — but I will tell say it’s smarter and sharper than you might expect.

That’s “Good Boys” in a nutshell. Yes, it’s a raunchy, edgy, hard-R comedy about a trio of 12-year-old boys who drop the f-bomb every other sentence and get involved in all sorts of predicaments featuring sex toys and beer and molly — but even the most hardcore jokes have a good-natured and even sweet larger context.

Good Boys: 3 out of 4 CST_ CST_ CST_ CST_ CST_ CST_ CST_ CST_ Universal Pictures presents a film directed by Gene Stupnitsky and written by Stupnitsky and Lee Eisenberg. Rated R (for strong crude sexual content, drug and alcohol material, and language throughout — all involving tweens). Running time: 90 minutes. Opens Thursday at local theaters.

These kids are in an R-rated movie, but they’re living PG lives. Half the time they don’t even understand the true purpose of that particular device, or the real meaning of that particular word.

“She’s a nymphomaniac,” Max says to his best buddies, and then elaborates: “Someone who has sex on land AND sea.”

Jacob Tremblay (“Room”) plays Max, a 12-year-old who still has the high-pitched voice of a child but is starting to have certain, more mature feelings, as evidenced when he creates a video game character with oversized breasts and an undersized bra.

At just that moment, enter Max’s dad (Will Forte, hilarious), who thinks it’s just GREAT his son has reached this threshold, and in true movie-parent fashion embarrasses Max with a frank and open discussion.

Oh, and Max’s dad is about to leave town. He tells Max to not even think about touching his pricey and super-cool drone, which Dad uses for work.

The drone is the middle school equivalent of the Porsche in “Risky Business,” the red “Ferrari” in “Ferris Bueller’s Day Off.” We know Max is going to take that drone for a spin. And we know that decision will lead to nothing but trouble.

Max has two best buddies:

• Thor (Brady Noon), who talks a big game but is a sensitive kid with a beautiful voice who loves the musical theater. (He has an audition around the corner for the school production of “Rock of Ages,” a hilariously inappropriate choice of material for sixth-graders to perform).

• Lucas (Keith L. Williams) who is so oversized a frat boy mistakes him for an economics classmate but is the most naïve and innocent and emotionally youngest of the trio.

In the tradition of many a coming-of-age movie (most of which are about kids five or six years older than this bunch), “Good Boys” chronicles a brief but pivotal period in the lives of these kids, who have just entered the sixth grade and are determined to step up their game, whether it means taking multiple sips from a bottle of beer, doing battle with a bunch of dimwit bro frat brothers — or, most intimidating of all, one of them kissing a girl for the first time.

Director Gene Stupnitsky, a veteran of “The Office” who co-wrote the screenplay with fellow “Office” alum Lee Eisenberg, is well-versed in the art of delivering a comedic moment (many of them so “wrong” you alternate laughing and groaning) with a sharp payoff — and then immediately cutting to the setup for the next scene, giving us time to catch our breath and shake our heads because they went THERE yet again.

One running gag involves the boys careening about town while in possession of a bottle of vitamins that actually contains molly belonging to high school seniors Hannah (Molly Gordon) and Lily (Midori Francis) — or as Max refers to them, “those old girls.” Another bit revolves around Thor’s parents, who are REALLY into the kink, as evidenced by their collection of romance-enhancing equipment, which includes enough items to stock a Christian Grey garage sale.

At times the jokes depend on us believing three smart, Internet-savvy kids wouldn’t know how to do a Google search, or understand how to open a bottle with a child-proof cap — or realize how utterly insane it would be to run across a multiple-lane highway with traffic roaring by at deadly speeds in both directions. It’s a stretch. (Oddly enough, it’s not difficult to believe the boys would be constantly dropping f-bombs, as they deliver the expletive with the enthusiasm of kids who have only just broken in the word and will realize in a year or two, if not sooner, there’s actually nothing so cool about it).

Stephen Merchant scores big laughs as a creepy older guy interested in buying a rare trading card from the boys. Lil Rel Howery and Retta are so good in their few scenes as Lucas’ divorcing parents, we could go for an entire movie about those two.

Tremblay, Noon and Williams are terrific together as three loyal and true friends who are at that stage in life where they still have each other’s backs but are beginning to realize that despite their vows to remain this close for life, life might have other plans for them.

For all its wacky, gross-out, shock-ya humor, “Good Boys” has a lot of heart.