What's the right length for a model rail yard? Well...
How long is your layout room?
Is it hidden staging or part of the visible scenicked 'theatre stage'?
Is it a classification, division, or industry support yard?
Are you modeling one particular location, such as downtown Foameropolis, or do you want to capture the look and feel of a railroad line connecting two or more communities?
If it's a classification or division yard, how long are your longest sidings and trains?
Will it have engine service facilities adjacent, and if so, how big are they?
How big do you want it to be, relative to any other planned scenes/sections of the layout?
How much selective compression are you using? For example, if you're modeling multiple towns, how many linear feet are you allowing for each, or for the largest one?
What era are you modeling? What is your average/typical freight car length?
And finally - how long is your layout room again?
There's no one 'correct' or 'best' answer, because it's all part of a complex web where everything has to fit together in - as others have quite rightly said - a balanced way that looks right to your eye. But of course, as with curve radius, bigger is always better. Make it as long as you possibly can without upsetting the balance and forcing you to make a whole bunch of other compromises and sacrifices.
My longest layout scene is a 22' straight stretch of benchwork containing a single track running through the countryside between towns. My longest trains top out at thirty or so 40'-50' cars with 2-3 locos. They pretty much fill that scene and are longer than my 15-20' small town scene. That max length is dictated by my sidings and the two longest staging yard tracks (I don't have a visible scenicked yard). I'm very pleased with the result - it looks right to me. But that doesn't mean these are the 'right' or 'best' dimensions for everyone.
My son's 4'x6' layout (all HO here), features an intermodal yard with a single 4' track that comfortably holds 4 stand-alone well cars - or 5 if you block the entrance road. It works surprisingly well because it takes up more than half the length of the city scene which occupies that whole side of the layout. (The other side, separated by a hardboard backdrop, features a country scene.) This is a good example of balance at work, within variable amounts of selective compression. I'm using 15' to model a small rural town, he's packed a medium-sized city into 6'. Because he has a great eye for composition, he's got the balance right and pulled it off. That's probably nearing the extreme end of what's possible in HO, but it shows how everything is relative.