Wiki article link: Traditional versus Roth
Here are the general guidelines from that article (which also deals with the common choice between a traditional 401(k) and a Roth IRA if your employer doesn't offer a Roth 401(k).)
If your employer matches 401(k) contributions, put enough to get the maximum match in the 401(k) before contributing to any IRA.
If you have inferior options in the 401(k), prefer an IRA to the 401(k), even if the IRA must be Roth and you would prefer a traditional account.
Always prefer a Roth IRA over a non-deductible IRA.
If you are in the 15% tax bracket, prefer a Roth.
If you expect to be in a higher tax bracket than your current bracket for most of your career, prefer a Roth.
If you can max out a Roth account and will have a large traditional account or a pension, prefer a Roth.
Otherwise, prefer a traditional account.
In your example, in which Mr. X can max out a Roth 401(k), the Roth is likely to be better if he retires in an equal or nearly equal tax bracket; whether this happens depends on how much of his retirement income comes from already-made traditional contributions or pensions. (Note that the cost of the taxable investment is slightly more than the long-term capital gains, since dividends on the taxable invstment are taxed annually.)