Tim Tripcony used to be a big fan of chaining as well. But it's bad practice when you start testing complex code because it hides the point of failure in execution. If we take your last example, and that line resulted in a NullPointerException, how would you know whether it was the constructor, .setTitle(), or .show() that failed to return the correct object?
Restricting individual lines to single operation may bulk your code up a bit, but it makes it MUCH easier for a maintenance developer to come behind and diagnose a runtime error.
Tim Tripcony used to be a big fan of chaining as well. But it's bad practice when you start testing complex code because it hides the point of failure in execution. If we take your last example, and that line resulted in a NullPointerException, how would you know whether it was the constructor, .setTitle(), or .show() that failed to return the correct object?
Restricting individual lines to single operation may bulk your code up a bit, but it makes it MUCH easier for a maintenance developer to come behind and diagnose a runtime error.