These are all good answers, but I'd just add a historical note. Composers before the time of, say Beethoven, composers like Bach and Mozart, often did not publish all or even most of their musical works, either because no one wanted them, or because they wanted to keep the pieces for their own use. The vast majority of Bach's music was not published in his lifetime, so there was little need to "name" the compositions. Often the names we use (Brandenburg concerto; Jupiter Symphony) were added later, as nicknames.
Neither Bach nor Mozart left any definitive catalog of works (Mozart wrote up a list from memory late in life, as I recall, but he got things wrong). It was left to musicians and musicologists to find all the manuscripts, try to figure out what order they came in, give them some numbering system, and then publish them in large collected works editions. Most of this editorial work did not even start until well after the composers were gone, at the end of the 19th century.
(This is where the letters and numbers after many 18th-ct. works come from: they are catalog numbers, like Mozart's K numbers, K being Koechel, the editor of the first Mozart edition, or J.S. Bach's BWV numbers [standing for Bach Werk Verzeichnis, or Bach Work Catalog in German]. Even Beethoven left a bunch of works unpublished at his death; they are in his collected edition with W.o.O numbers, standing for "Werke ohne Opuszahl" ["works without opus number"].)
So, in his lifetime, Bach, like most composers, never needed to give distinctive names to most of his works, because most of them were never intended to be used by anyone but him. The full numbering of, say, Haydn symphonies was a real mess, because for most of his life, Haydn just wrote symphony after symphony for his patron(s), who owned them as absolutely as they owned paintings or sculptures they commissioned. When he got famous, some of "his" symphonies became well-known and published, but even those were likely to have been in short numbered sets of, say, six or twelve, like the so-called Paris (82-87) and London (92-104) symphonies. (I used to play four-hand arrangements of Haydn's late symphonies where the numbering started at 92, as if those were the only ones that mattered!) And, when I was a kid, there were supposed to be 104 Haydn symphonies; now we think he wrote at least 107, but do we renumber all the later ones to accommodate the very early ones we found? Heck no!
Even more recent composers run into this problem. Bruckner wrote and published nine symphonies. But then, after his death, they found an early trial-run symphony that he wrote but never published, so they decided to call it Symphony No. 0 ("Die Nullte"). Then they found another one, so they called it (not Symphony No. -1, that would have been awesome), but Symphony No. 00.
And so it goes...