问题描述
如果我有一系列方法调用,每个用于下一次调用的值,我应该将它们存储在局部变量中,例如:
DynamicForm filledForm = Form.form()。bindFromRequest();
String shareIdStr = filledForm.get(data [shareId]);
UUID shareId = UUID.fromString(shareIdStr);
Share share = Share.find.byId(shareId);
或作为单个调用链,如下所示:
分享share = Share.find.byId(UUID.fromString(Form.form()。bindFromRequest()。get(data [shareId])))
在这种情况下,再次使用的唯一值是 code>。也许答案是在中间的某个地方,或者是完全不同的东西。
ADV
-
提高可读性。 / p>
-
提供重新使用的机会。
-
调试变得更容易,即在特定调用时设置断点很容易。
DisADV
-
增加代码的长度
-
减少创建多个temp的需要。
-
是
-
减少要写入的行数。
-
降低代码的可读性。
-
调试整个调用链非常困难。
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.
Increases length( I wont say size :) ) of code.
IDE warnings (if any).
Reduces the need for creating multiple temp. variables.
Is a syntactic sugar
Reduces the number of lines to be written.
Reduces readability of code.
Commenting becomes difficult (if any) for particular methods called.
Debugging the whole chain of invocation becomes very difficult.
blockquote>
链接方法
ADV
DisADV
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?
ADV
DisADV
ADV
DisADV
这篇关于是更好地使用局部变量或链方法内联吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!