StyleCop 与 ReSharper 以及一般编码风格问题
刚刚发现 StyleCop,看起来值得在我的项目中使用。然后我发现你可以将它与 ReSharper(我也从未使用过的工具)一起使用。所以我下载了 ReSharper 以及 StyleCop for ReSharper。不过,我对此有点困惑:
只安装了 StyleCop(没有 ReSharper),我就因为直接引用代码隐藏中的私有变量而被骂。它希望我改为执行 this.variable。好吧,很好。
如果我只使用 ReSharper,它会告诉我删除刚刚添加的所有“this”调用。哪一个更好?
如果我对 ReSharper 使用 ReSharper + StyleCop,它现在会告诉我将“this”添加到所有私有成员引用中(就像 StyleCop 自己所做的那样)。但是,现在它还希望我将“this”添加到我从 .aspx 页面引用的所有控件中(即 Label.Text = this.variable -> this.Label.Text = this.variable)。
我很困惑。最好遵循的标准是什么?或者我可以像现在这样(Label.Text = 变量)吗?
Just found StyleCop, looks like something worth using for my projects. Then I found out you could use it with ReSharper (a tool I've also never used). So I downloaded ReSharper, as well as StyleCop for ReSharper. I'm just a bit confused about it, though:
With just StyleCop installed (no ReSharper), I get yelled at for referring directly to private variables in code-behind. It wants me to instead do this.variable. Alright, fine.
If I use just ReSharper, it tells me to remove all of the 'this' calls I just added. Which one is better?
If I use ReSharper + StyleCop for ReSharper, it now tells me to add 'this' to all private member references (just like StyleCop did all by itself). However, now it also wants me to add 'this' to all of the controls I'm referencing from the .aspx page (i.e., Label.Text = this.variable -> this.Label.Text = this.variable).
I'm so confused. What is the best standard to follow? Or am I just fine doing it the way I am now (Label.Text = variable)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
关键点是一致性。您在这一点上的特定格式取决于个人喜好。
额外的冗长是否使您引用的变量更加清晰,或者是否通过在页面中充斥额外的文本而模糊了含义?
这是一个判断。他们确实执行其他有意义的规则;然而,他们所做的很大一部分工作是强制一致性。正如@Martin 所说,请随意禁用对您的工作流程没有意义的规则。
The key point is consistency. Your particular formatting with regard to this point comes down to personal preference.
Does the extra wordiness provide additional clarity as to which variable you're referencing or does it obscure the meaning by flooding the page with extra text?
This is a judgment call. They do enforce other rules that make sense; however, a large part of what they do is enforce consistency. As @Martin said, feel free to disable rules that don't make sense for your workflow.
抱歉,在团队中工作时,一切都取决于对政治的理解;毕竟,我们工作是为了获得报酬!
要赢得这场胜利,还有很多更重要的战争,例如 10,000 行类、超大方法
如果您足够幸运,可以自己决定使用哪些工具(和编码标准),那么我会选择 ReSharper并阅读“干净的代码”一书。
Sorry when working on a team it all comes down to understanding the politics; after all, we work to get paid!
There are a lot more important wars to win this, e.g. 10,000 line classes, over sized method
If you are luckly enough to decide what tools (and coding standards) are used yourself, then I would just choose ReSharper and read the “clean code” book.