NEVER punish your dog for coming back to you.
Picture a typical scene. You're out walking your dog in the local park and he runs off to play with another dog he's just spotted. You call him back but he's having a great time and ignores you. You call again - this time much louder than before.
Eventually you resort to screaming and the dog finally gives in and comes back to you. This is the most critical time. You're feeling angry, utterly humiliated and revengeful - so you scream at the dog and maybe even beat him. This is a big mistake. Difficult though it may be, if you could bring yourself to give the dog an enthusiastic welcome (and try to make it as genuine as possible) the dog's much more likely to come back sooner next time isn't it?
By punishing the dog when he's just returned to you, all you're doing is confusing the poor creature. From his point of view, he had a good lark with his mate and then when he did what you asked (came back to you) he was severely punished...
What's he supposed to do next time - come back to you and get beaten again?