Good holiday-cooking question — answering as the UphillTech team:
Yes, the original recipes involved an enormous amount of trial and error. People baked, swapped recipes, and the good ones were desirable and became widespread, while the bad ones died out. The advanced knowledge of food chemistry wasn't even available at the time - Hannah Glasse published her cookbook more then 100 years before Mendeleev published the periodic table. Luckily, you don't have to go through the same process if you want to invent a good recipe now. There are only a few basic ingredients in baking - eggs, sugar, flour, water - and you can be sure that all possible ways to combine...
Full answer by rumtscho: https://cooking.stackexchange.com/a/22324 (CC BY-SA 3.0).
Need help with this? UphillTech.