强制编码风格 [英] Enforcing a coding style

查看:102
本文介绍了强制编码风格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多年前,当我开始一个小型开发项目时,其他开发人员和我坐下,商定了一个妥协的大括号和缩进样式。这不是任何人的最爱,但它是一个没有人真正讨厌的东西。我写了一个.indentrc配置文件的样式,并有一个检入触发器,将运行缩进每个文件,因为它被签入。这使得它无关你写什么样式的代码,它将最终成为组标准,之前任何人都看到它。这具有一致性的优点。但我从来没有见过任何人这样做之前或之后。



那么你说的其他人呢?好主意还是可憎?

解决方案

采用中性编码风格绝对是个好主意。但是,只有在检查源时强制实施编码风格可能是或不是一个好主意(参见 Bill的 Elie'的答案如下)

允许编码者随意编写,因此他们不必考虑标准或改变编写代码的方式。



Con:您的代码可能只有一个通过熟悉中性风格,所以你没有得到所有使用相同的风格的所有利益。如果你的程序员必须在配对编程设置中一起工作,他们仍然会在屏幕上受到彼此的编程风格,这将是不同于自己的风格或中性风格。



更进一步,在开发过程中使用中性风格:



/ strong>鼓励流畅的中性风格,每个人都可以在签到前后阅读所有人的代码。



Con:会遇到更多的阻力从你的开发者这样做。根据你的文化,它可能会比它的价值更麻烦。


Years ago when I was starting a small development project, the other developers and I sat down and agreed on a compromise brace and indentation style. It wasn't anybody's favourite, but it was something that nobody really hated. I wrote a .indentrc configuration file to that style, and had a check-in trigger that would run indent on every file as it was being checked in. That made it so that it didn't matter what style you wrote your code in, it would end up being the group standard before anybody else saw it. This had the advantage of consistency. But I've never seen anybody else do it this way before or since.

So what say the rest of you? Great idea, or abomination?

解决方案

Adopting a neutral coding style is definitely a good idea. However, only enforcing the coding style when the source is checked in may or may not be a good idea (see also Bill's and Elie's answers below).

Using the check-in hook:

Pro: Allows coders to write however they wish, so they don't have to think about the standard or change the way they write code. This minimizes resistance to the policy, and won't negatively impact their productivity when writing code.

Con: Your coders may have only a passing familiarity with the neutral style, so you aren't getting the full benefit of everyone using "the same" style. If your programmers ever have to work together in a pair programming setup, they are still going to be subjected to one another's programming style on the screen, which is going to be different from their own style or the neutral style.

Going one step further, using the neutral style during development:

Pro: Encourages fluency in the neutral style, everyone can always read everyone else's code before and after it's checked in.

Con: You'll encounter more resistance from your developers doing it this way. Depending on your culture, it could be more trouble than it is worth.

这篇关于强制编码风格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆