It's a matter of angles.
Also, it depends on the reader's sight and the font size.
The line length should be such that it didn't require the readers to move their eyes sideways too much. This is the natural constraint.
There is also a bottom limit in that lines shouldn't be too short as to require too much eye movement.
When reading a book we adopt a position so that a line that's perpendicular to the paper at the middle of the line intersects our face between our eyes. The lines that run from between-out-eyes to the ends of the line form a isosceles triangle.
This angle is what has to be controlled. I don't mean measured except by trying to read the text and checking if too long a line produces eye strain by forcing the readers to sweep too much width, with the addition of the parallax issue of returning to the start of the wrong line. Something between 30° and 45° is OK.
The top angle of the isosceles triangle depends both on the line width and on the reading distance.
The reading distance, assuming that the readers can control it, depends on the reader's sight and the font size. For example elder people usually need bigger fonts to be able to read with total comfort.
In desktop or notebook screens, with the current widescreens and default configurations, we tend to sit so that the angle to the sides of the screen is too much. Half that width would be a reasonable line length.
Elder readers set bigger fonts but should still sweep the same angle, so the lines would end up containing less words.
Such readers might not be able to read from the same distance a younger guy does, in this case the page should be made wider.
You can try it. Open a book in Acrobat Reader and set the zoom to fit width.
Then maximize the window: you need to increase the reading distance. On the other hand, if you reduce the window width you'll want to be closer.
As you can learn from the HFI research cited by user 17... there is another factor: the font design.
Some fonts are more readable than others. This seems to be related to the font's xHeight.