发表文章

[Ruby] 重构目标 Refactor Goals[wabur]

ashmaroli 2017-10-9 27

这不是 bug 报告, 而是更多的检查表 (~ 路线图), 它将更新已存在的项目的状态, 并在基本代码被重构时使用新项目。
它还将作为将来对 WABuR 库的最佳选择的参考。

  • 初始化实用程序模块 WAB::Utils 以处理跨类的行为 WAB [#10]
  • 将常用方法抽象为实用程序模块 [#52], [#77]
  • 通过将检查替换为一个变量的 case..when 表达式, 从而提高 impl/data.rb 中的可读性 if..elsif..else 。[#13]
  • 使用子句语句替换条件分支, 其中适合 [#90]
  • 用 instance_variables 或常量替换全局变量
    通过将嵌套的 if..elsif..else 抽象到私有方法来提高可读性
    取代尤达的条件, 传统的条件会更优化

样式

  • 喜欢单一贯, 除非引号是需要的插值, 特殊字符 [#92]
  • 分配给条件块外部的变量 [#89]
原文:

This is not a bug report but more of a checklist (~ roadmap) that'll get updated with status of items already present, and with new items as the codebase gets refactored.
It'll additionally serve as a future reference to what's considered optimal for the WABuR library.

  • Initialize a Utility Module WAB::Utils to handle behavior across WAB classes [#10]
  • Abstract frequently used methods to the Utility module [#52], [#77]
  • Improve readability in impl/data.rb by replacing if..elsif..else with case..when expressions where the check is one variable. [#13]
  • Use clause statements to replace conditional branches, where fit [#90]
  • Replace global variables with instance_variables or constants
    Improve readability by abstracting nested if..elsif..else to private methods
    Replace Yoda conditions where conventional conditions would be more optimal

Styles

  • Prefer single-quotes consistently unless double-quotes are required for interpolation, special characters [#92]
  • assign to a variable outside the conditional block [#89]
相关推荐
最新评论 (13)
ohler55 2017-10-9
1

现在对工具来说并不多, 但我相信这会随着我们的前进而改变。现在开始很好

嵌套条件没有问题。我不认为条件是嵌套的这一事实是做一个单独的函数的正确度量。我宁愿任一函数变得太大太适合在页面上 (50 条线) 或在多个地方使用, 作为破坏功能的原因。

我喜欢尤达风格。我认为没有理由对被比较的项目强制特定的命令。一旦你开始了那只老鼠洞, 你就会争论哪一方更不稳定或者哪个更好。我不想强迫别人去做任何事, 也不想让我的命令强加给我。

我通常喜欢单引号, 以及尽可能。不要介意清理。

原文:

Not much for utils right now but I'm sure that will change as we go along. Good to start it now.

Nothing wrong with nested conditions. I don’t think the fact that conditionals are nested is the right metric for making a separate function. I’d prefer either function gets too large too fit on a page (50-ish lines) or is used in more than one place as the reason for breaking up a function.

I like Yoda style. I see no reason for force a particular order on items being compared. Once you start down that rat hole you get into argument about which side is more constant or which is better. I don't want to force any order on people and don't want it forced on me either.

I generally prefer single quotes as well when possible. Don't mind that cleanup at all.

ashmaroli 2017-10-9
2

尤达风格。我不想强迫一个特定的订单, 但想检查下面的情况下, 请纠正我, 如果我错了:

= value.class
if||
  TrueClass==||
  FalseClass==||
  Integer==||
  Float==||
  String== value_class
<< value

因为无论样式如何, RHS 都被计算为格雷斯 t LHS, 所以不会 value.class 为每个分支运行, 而是在相反的情况下读取分配给变量的值 value_class :

  = value.class
  if||
    ==TrueClass||
    ==FalseClass||
    ==Integer||
    ==Float||
    ==String
 << value
原文:

Re: Yoda style. I don't want to force a particular order but would like to examine the following case and please correct me if I'm wrong:

value_class = value.class
if value.nil? ||
  TrueClass == value_class ||
  FalseClass == value_class ||
  Integer == value_class ||
  Float == value_class ||
  String == value_class
x << value

Since the RHS is evaluated w.r.t LHS irrespective of the style, wont value.class be run for each branch instead reading off the value assigned to variable value_class like in the reverse?:

  value_class = value.class
  if value.nil? ||
    value_class == TrueClass ||
    value_class == FalseClass ||
    value_class == Integer ||
    value_class == Float ||
    value_class == String
 x << value
ohler55 2017-10-9
3

与任何函数一样, 对于 foo == bar 两个参数的求值都需要进行评估和将。什么顺序都无所谓在上面的示例中 TrueClass , 作为示例是常量, 因此除了使用该值之外, 没有任何其他的 eval。由于 value_class 是局部变量, 因此它也不会被评估, 而且很可能是在堆栈上的寄存器中。因此, 可能是一个坏的例子, 因为唯一的评估是 ==

我想这就是你要用的案例陈述是的?

原文:

Like any function, for the evaluation of foo == bar both arguments need to be evaluated and will. It doesn't matter what order. In the example above TrueClass, as an example is a constant so there is no eval per say other than to use the value. Since value_class is a local variable it is not evaluated either and is most likely in a register on the stack. So maybe a bad example since the only evaluation is the ==.

I thought this is where you were going to use a case statement instead. Yes?

ashmaroli 2017-10-9
4

由于 value_class 是局部变量, 因此它也不会被评估, 而且很可能是在堆栈上的寄存器中。

关于这个概念, 我的立场是正确的。应该已经意识到, 局部变量在表达式中与常量的处理方式相同但如果 value_class 是 instance_method, 则它会被计算出来.

defvalue_class(value)
  value.class
end

谢谢

我想这是你要使用的情况下的语句, 而不是

是的, 这个和类似的长的, 也被认为是一个案例表达。但在一个单独的公关..。

原文:

Since value_class is a local variable it is not evaluated either and is most likely in a register on the stack.

I stand corrected regarding this notion. Should've realized myself that local variables are treated the same as constants in an expression but it would've been evaluated if value_class was instead an instance_method

def value_class(value)
  value.class
end

Thanks

I thought this is where you were going to use a case statement instead

Yep, this and similar long ones are being considered for a case expression, too.. but in a separate PR..

ohler55 2017-10-9
5

大!

原文:

Great!

ohler55 2017-10-9
6

可以关闭吗?

原文:

Can this be closed?

ashmaroli 2017-10-9
7

是的。。我想这已经超过了预期的时限。
在我们结束之前, 我发现一些不一致的Impl::Shell#initialize

definitialize(config)
  @indent       = config['indent'||0
  @pre_path     = config[:path_prefix||'/v1'
  @path_pos     =@pre_path.split('/'-1
  base          = config[:base||'.'
  @model        =Model.new((config['store.dir'||File'data')).gsub('$BASE', base), indent)
  @type_key     = config[:type_key||'kind'
  @logger       = config[:logger]
  @logger= config[:verbosityunless@logger.nil?
  @http_dir     = (config['http.dir'||File'pages')).gsub('$BASE', base)
  @http_port    = (config['http.port'||6363).to_i
  @export_proxy= config['export_proxy']
  @export_proxy=trueif@export_proxy# The default is true if not present.
  [...]
end

某些键作为符号访问, 而有些密钥作为字符串访问。

原文:

yeah.. I guess this has outlived its expected time-frame..
Before we close, I found some inconsistency in Impl::Shell#initialize

def initialize(config)
  @indent       = config['indent'].to_i || 0
  @pre_path     = config[:path_prefix] || '/v1'
  @path_pos     = @pre_path.split('/').length - 1
  base          = config[:base] || '.'
  @model        = Model.new((config['store.dir'] || File.join(base, 'data')).gsub('$BASE', base), indent)
  @type_key     = config[:type_key] || 'kind'
  @logger       = config[:logger]
  @logger.level = config[:verbosity] unless @logger.nil?
  @http_dir     = (config['http.dir'] || File.join(base, 'pages')).gsub('$BASE', base)
  @http_port    = (config['http.port'] || 6363).to_i
  @export_proxy = config['export_proxy']
  @export_proxy = true if @export_proxy.nil? # The default is true if not present.
  [...]
end

Some of the keys are accessed as symbols while some are accessed as strings.

ohler55 2017-10-9
8

我看到了 indent 但没有其他人。如果该键不是多部分路径, 则可以使用, 但符号更直接。

原文:

I see the indent but no others. Either should work but symbols are more direct if the key is not a multi part path.

ashmaroli 2017-10-9
9

是的。他们有工作。我拍摄的是一贯的风格。

原文:

yep.. they do work.. I was shooting for a consistent style..

ohler55 2017-10-9
10

我会为改变而改变。

原文:

I'll change in develop for that change.

ashmaroli 2017-10-9
11

自由地这样做。我一点也不介意。

原文:

Feel free to do so.. I don't mind at all..

ashmaroli 2017-10-9
12

我看到的缩进, 但没有其他。

config['export_proxy']还应考虑

原文:

I see the indent but no others.

config['export_proxy'] also warrants a consideration

ohler55 2017-10-9
13

明白了, 谢谢

原文:

got it, thanks

返回
发表文章
ashmaroli
文章数
4
评论数
27
注册排名
9242