StyleCop 与 ReSharper 以及一般编码风格问题

发布于 2024-08-06 19:29:07 字数 568 浏览 9 评论 0原文

刚刚发现 StyleCop,看起来值得在我的项目中使用。然后我发现你可以将它与 ReSharper(我也从未使用过的工具)一起使用。所以我下载了 ReSharper 以及 StyleCop for ReSharper。不过,我对此有点困惑:

  1. 只安装了 StyleCop(没有 ReSharper),我就因为直接引用代码隐藏中的私有变量而被骂。它希望我改为执行 this.variable。好吧,很好。

  2. 如果我只使用 ReSharper,它会告诉我删除刚刚添加的所有“this”调用。哪一个更好?

  3. 如果我对 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:

  1. 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.

  2. If I use just ReSharper, it tells me to remove all of the 'this' calls I just added. Which one is better?

  3. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

养猫人 2024-08-13 19:29:07

关键点是一致性。您在这一点上的特定格式取决于个人喜好。

额外的冗长是否使您引用的变量更加清晰,或者是否通过在页面中充斥额外的文本而模糊了含义?

这是一个判断。他们确实执行其他有意义的规则;然而,他们所做的很大一部分工作是强制一致性。正如@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.

哽咽笑 2024-08-13 19:29:07

抱歉,在团队中工作时,一切都取决于对政治的理解;毕竟,我们工作是为了获得报酬!

如果决定你下一个的人
加薪使用 StyleCop,那么你
应始终包含“this”。
同样,如果老板使用 ReSharper
你应该按照 ReSharper 所说的去做。

要赢得这场胜利,还有很多更重要的战争,例如 10,000 行类、超大方法

如果您足够幸运,可以自己决定使用哪些工具(和编码标准),那么我会选择 ReSharper并阅读“干净的代码”一书。

Sorry when working on a team it all comes down to understanding the politics; after all, we work to get paid!

If the person that decided your next
pay raise uses StyleCop, then you
should always include the “this.”
likewise if the boss uses ReSharper
you should do what ReSharper says.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文