Is it better to use local variables or chain methods inline?
coding-style, java
Solution
Not chaining Methods :
ADV
Enhances readability.
Gives an opportunity for re-usage.
Pin pointing exceptions (if any) becomes easier.
Debugging becomes easier, i.e. setting breakpoints on specific invocation is easy.
DisADV
Increases length( I wont say size :) ) of code.
IDE warnings (if any).
Chaining Methods
ADV
Reduces the need for creating multiple temp. variables.
Is a syntactic sugar
Reduces the number of lines to be written.
DisADV
Reduces readability of code.
Commenting becomes difficult (if any) for particular methods called.
Debugging the whole chain of invocation becomes very difficult.
Problem
If I have a series of method invocations, the value of each used for the next call, should I store them in local variables, like so: ``` DynamicForm filledForm = Form.form().bindFromRequest(); String shareIdStr = filledForm.get("data[shareId]"); UUID shareId = UUID.fromString(shareIdStr); Share share = Share.find.byId(shareId); ``` or as a single invocation chain, like so: ``` Share share = Share.find.byId(UUID.fromString(Form.form().bindFromRequest().get("data[shareId]"))); ``` In this case, the only value that is used again is `share`. Perhaps the answer is somewhere in-between, or is something completely different. What's your opinion?