I'm talking about puppies because people carry them and hug them. Dogs on the other hand get stressed while getting hugged because they feel trapped.
It depends by the dog. There are dogs that love hugs and others that don't. You could know just if you understand the body language of your puppy. Is it a good behaviour? It depends!
The puppies need to be shaped
The dogs understand us really good so if when they are puppies we hugs them saying something with a little voice they will link it to an affectionate gesture (and of course it is).
Sometimes it's spontaneous to hug our puppy! You can do it when you want, but just don't do it too much because they have to learn to be independent.
In the opposite take them for a walk in the arms could compromise their growth. When you are holding your puppy in the arms, while for example other dogs bark to it or while they try to sniff it, you are not help it because the dog is feeling overprotected. The puppy will never integrate in a pack and will never understand what is the right behaviour of an adult dog and this could take it to become antisocial.
Just remember everytime you look in your best friend's eyes: it's a dog and not a baby.
My Labrador Retriever loved to be hugged as a puppy and still continues to love it as a 14 month old. It completely depends on the personality of your dog. Something that is unique and cute about our dog is that she initiates the hug herself by coming to you with her head down and pushes the back of her neck and upper back into your chest while you are sitting down on the floor. She literally wants the closeness and hug around her body and will stay in that position for 10-15 seconds.
After that she continues the motion and does a somersault forward into your lap and then it's "play time".
I'd say there is a significant difference between "hugging" a dog and "restraining/holding" them. The latter being the one that more dogs would not find to be comfortable.