【问题标题】:Which example of code is considered better (in terms of readability and support) and why?哪个代码示例被认为更好(在可读性和支持方面),为什么?
【发布时间】:2016-05-19 07:09:56
【问题描述】:

获取数据的方法使用延迟加载模式,所以多次调用是安全的。

第一个例子:

variable = large::method::to::get::data()
// some other code
variable.doStuff()
// some other code
variable.doMoreStuff()

第二个例子:

// some other code
large::method::to::get::data().doStuff()
// some other code
large::method::to::get::data().doMoreStuff()

【问题讨论】:

    标签: refactoring readability code-readability


    【解决方案1】:

    乍一看,第一种方法比第二种方法更具可读性和更易于维护。 如果你有这么长的大行代码,你会发现它可能更难理解,但支持它比简洁直接的选项更难。

    【讨论】:

      猜你喜欢
      • 2016-06-21
      • 2020-12-19
      • 1970-01-01
      • 1970-01-01
      • 2012-07-19
      • 1970-01-01
      • 2021-08-28
      • 2012-01-02
      • 2022-01-08
      相关资源
      最近更新 更多