At my dojo punishment is almost always dealt out in good spirits. One Sempai is quite strict and militaristic, and is very much into everyone doing everything properly and 100% every time.
You will usually be punished if you're not following the dojo kun. Things such as yawning, being late, not paying attention, standing with your arms crossed, etc. will usually get you 20 pushups
However Sempai's attitude towards this is, that we shouldn't think of it as punishment (and therefore something negative), we should think of it as training. So when being punished we should actually be happy that we're getting an extra workout.
This may be a bit of a stretch, but I do see his point. And I do appreciate his quite hard style, as it keeps the class concentrated and gets things done. I also appreciate his ability to make us push ourselves and do our best every time.
Only thing is, that if you're having a bit of an off day, it can get annoying, since he's full on all the time, so you really gotta be in the mood for it.
Contrasting to this is another Sempai, who's just a really nice guy, sometimes too much so. He will dish out punishment as well, but he's a lot more leanient about it. Unfortunately at times this will lead to the class being a bit too loose and people are distracted, because there isn't enough discipline.
In a perfect world, punishment shouldn't be necessary, as everyone are of course 100% concentrated all the time, doing their very best every time and interested in every minute detail of their martial art.
Back in the real world there are a lot of different people coming to a dojo, some people who cant keep concentrated and are easily distracted, not everyone's interested in some of the Kihon, etc.
I think that discipline in a class with a lot of people is essential to keep the class effective, and one of the means of achieving this is punishment.