Dogs bark for a variety of reasons, some good, some not so good. Sometimes barking is a welcoming signal, other times not. Sometimes dogs bark briefly, and other times they just won't quit. And therein lies a problem.
By nature, some breeds tend to bark more than others. Beagles and Shetland sheepdogs, for instance, tend to be very vocal. Greyhounds and basenjis, by contrast, rarely bark.
Barking is a form of communication. When people or other dogs are around, barking can be a statement intended specifically for them. When a sound is used as a means of communication from one creature to another, the rudiments of language exist. Language after all is just a complicated arrangement of verbal/vocal cues. We can communicate with dogs by means of our language, but we are often rather poor at understanding their requests. Phrases such as "come here," "leave it," "stop it," inform the trained dog what must be done, but their barking often leaves us stymied.
Barking serves different purposes. Sometimes it is used to repel and sometimes to attract. Some barking tones indicate, "stay away," whereas others (particularly in the appropriate context) can be interpreted to mean, "I'm over here, where the heck are you?" Even the most inexperienced of dog watchers will notice that dogs have a variety of different types of barking ranging from the muted "woof" of appreciation or alarm to loud angry series of barks indicating aggression.
Barking often serves as an alarm call. Many owners appreciate such alarm barking and some domestic dog breeds
have been selected for an enhanced warning system of this nature. When the barking produces the desired result, the "language" is reinforced and perpetuated. But not all of this "language" is wanted or appreciated by friends or family (let alone the neighbors). The key to dealing with barking is to be able to turn it off.