It's been pretty much covered above, so all I can really do is summarize.
All else being equal, the shorter tube will be more rigid, thus produce better accuracy.
Optimal barrel length, however, is dependent on cartridge and intended use. Remember, the faster the bullet, the less time there is for environment to act on it. As well, when bullets transition from supersonic to subsonic, there is a dramatic disruption in the airflow around that bullet, which has a negative effect on accuracy. This is why you see the latest purpose-built sniper cartridges using very low drag bullets fired at very high velocities. The 408 Chey-tac, while less powerful than the .50 BMG at the muzzle, has tremendous velocity combined with a very high B.C. bullet, which translates to better accuracy and more energy at extreme range.
Of course, there is the practicality end of it. You could build a .300 mag with a 3" profile barrel measuring 40 inches in length, and you'd have both the barrel rigidity and the increased velocity. You'd also have a 60 pound rifle.