Only if it's absolutely necessary, as a last resort. Same with people: don't hurt anyone unless you absolutely have no other choice.
Most dog owners won't like that at all, even if it's their fault, because they'll do anything for their spoiled dogs even if they're dangerous.
If I know that there are lots of dogs in an area, I would carry foldable sticks, like trekking poles, in a light bag where I also have some water and other essentials. That's how people in developing countries all deal with dogs: sticks and rocks.
Just wave the stick around or let the dog bite the stick. Again, hit it only as a last resort.
If people ask why you need a stick, you can say it's for doing gymnastic warmups or for going uphills, or some other random excuse.