We brought our child up exactly how we were brought up ourselves.
No slapping or other "physical" punishments, ever.
We "rationalised" and "explained" things, rules, etc., right from the earliest time of him understanding. Told him in advance of expected behaviour, what to expect, etc., and consequences for if he didn't. Right from the earliest of ages.
Explanation and pre-planning, pre-warning etc., is essential so that he knew what to expect, both in terms of what we were doing, where we were going, etc., but also in terms of sanctions for any misbehaving (which was never physical punishment).
Start early and keep up with it consistently.
He never got in trouble at school, not a single detention or other punishment - at parents' evenings we were consistently told he was a "model" pupil. Yet he still had a childhood and teenage years full of fun.
When he started socialising as a teenager, we made our expectations absolutely crystal clear, i.e. specific time to be home by! Amazingly he never once missed our (entirely reasonable) deadlines. Likewise we drummed it into him to tell us where he was, what he was doing, and to let us know if plans changed. Not micro-managing, we weren't expecting a text every 10 minutes, but he knew we were expecting a quick text every couple of hours.
A lot of it is basic/mutual respect. We respected him, gave him enough freedom, and mostly allowed him to do his own thing, but at the same time, he knew our standards of discipline and behaviour.
All that continued in his 3 years at University and even during the latter 2 years since Uni whilst working in a different city and living independently. There's still mutual respect and he still keeps us updated with "most" of what he's doing, and remains happy to give us 2 or 3 texts a day when abroad on holiday with friends, etc. Even on occasional home visits when he goes out socialising with his old friends, he'll still make sure he gets home at a sensible hour rather than bumbling in and waking us up in the early hours - obviously it's up to him how long he stays out when he's living in his own flat in his work city, as it was when he was at Uni, but he knows that when he's staying in our home, his childhood home, he complies with our house rules even as an adult.