It is like you said. There are some beers that fermentation time is approximated due to style, ingedients, or gravity. However, this is always an approximation.
As home brewers, we simply do not have the technology, equipment, or resources that a major brewery has. These brewers can get fermentation times, lagering, etc, down to the day.
We hobbyists simply have "guidlines" based on the things you mentioned -style, O.G., ingredients, etc.
I prefer to use the term "experience", rather than "trial and error" here. I have found I can generally assume when a certain gravity/style beer brewed with a certain yeast will finish. Not to the day, but I can usually say, "this beer will probably finish in three weeks, but this one seems to need six." In addition, many kits/recipes will give an approximate ready time.
As far as best flavor goes, this is very subjective. I have found, however, that I have never had a bad experience giving beer additional time. for example, my English Pale Ale was finished at three weeks, but I have found that letting this beer sit another week in primary improved the taste, err...at least to me. Pez.