简体   繁体   English

提高代码质量?

[英]Improving the quality of code?

So, in reading this site, it seems that the shop in which I work does a lot of things wrong and some things right. 因此,在阅读本网站时,似乎我在其中工作的商店做错了很多事情,而有些事情做对了。 How can I improve the code that I work with from my colleagues? 如何改善与同事一起工作的代码? The only thing I can think of is to lead by example - start using Boost, etc. Any other thoughts? 我唯一能想到的就是以身作则-开始使用Boost等。还有其他想法吗?

You probably have to look more closely at what it is your shop does wrong and what they do right. 您可能必须更仔细地了解您的商店做错了什么,以及他们做对了什么。 What can you actually change there? 您在那里实际可以更改什么? What can you change about your own practices that will improve your skills or that of your team? 您可以改变自己的实践以提高您或团队的技能吗? It can be difficult to realize change in an entrenched shop. 在根深蒂固的商店中实现变革可能很困难。 Try proposing code reviews (on your code first), which could lead to discussion. 尝试提出代码审查(首先在您的代码上),这可能导致讨论。

For tangible items, I'd look at Scott Meyers ' Effective C++, etc. Develop your skillset and you will either help improve others around you or move on to a shop that will. 对于有形项目,我将看一下Scott Meyers的Effective C ++等。发展您的技能,您将帮助改善周围的人,或者转向一家会这样做的商店。 Also, look at the Gang of Four's Design Patterns book. 另外,请参阅《四人帮的设计模式》一书。

Code reviews are the best way I found to improve code quality overall. 代码审查是我发现总体上提高代码质量的最佳方法。 Reviewing code from different individuals helping each other increases general awareness of different techniques and help propagate best practices. 回顾互助的不同个人的代码可以提高人们对不同技术的认识,并有助于传播最佳实践。 Hire a person more experienced than you are is also a good tool but it is a bit more tedious to implement. 雇用比您经验更丰富的人也是一个很好的工具,但是实施起来有点繁琐。

  • Reading good programming books 阅读优秀的编程书籍
  • Learning from other's code - Open source projects are the best place to start 向他人的代码学习-开源项目是最佳起点
  • Read good blogs and forums regularly - Sutter mill, Coding Horror, Martin fowler etc 定期阅读优秀的博客和论坛-Sutter mill,Coding Horror,Martin fowler等
  • Code reviews 代码审查
  • Unit tests 单元测试
  • Using good libraries like Boost, STL. 使用Boost,STL等良好的库。 Also understanding their implementation 也了解其实施

Leading by example is always a good thing, though convincing others that your example is better than however they're currently doing it is not so easy. 以身作则始终是一件好事,尽管要说服他人您的榜样比他们目前正在做的事要好,这并不是一件容易的事。 Constructive criticism through code review is probably your best bet for gently suggesting alternative approaches to how your colleagues work. 通过代码审查进行建设性的批评可能是最好的选择,它是温和地建议同事工作方式的替代方法。 The key point is to convince others that what you're proposing really is better in a tangible way that they can appreciate. 关键是要说服他人,您提出的建议确实会以一种切实的方式更好,让他人欣赏。

Sometimes folks have to see that your way is working better than their way. 有时人们不得不看到您的方式比他们的方式更好。 It is often difficult to make people change. 人们常常很难改变。

Have you considered unit test writing if you don't do that already? 您是否考虑过单元测试写作? I've found it to really improve my production code and give me more confidence that what I'm writing is what I'm supposed to be writing. 我发现它确实可以改善我的生产代码,并使我更有信心,我正在写的东西应该是我应该写的东西。

I like Jason's idea about code reviews. 我喜欢Jason关于代码审查的想法。 They can be helpful or they can be a place for arguing - really depends on how you set the tone. 它们可能会有所帮助,也可以成为争论的场所-实际取决于您如何设置基调。

Architect and design the project well so that none of the developers will be able to take a different route to violate the quality. 对项目进行良好的架构和设计,以便所有开发人员都无法采用其他方法来破坏质量。 If you set a great design, people will just follow the route and they will automatically learn 如果您设定了出色的设计,人们将只会遵循路线,他们会自动学习

要尝试的其他事情是添加单元 测试文档

Although this probably isn't as direct of an answer, I recommend you pick up the book Code Complete . 尽管这可能不是直接答案,但我还是建议您拿起Code Complete一书。 I find it to be the best resource for learning how to be a better programmer. 我发现它是学习如何成为更好的程序员的最佳资源。 If you read through the whole book and understand what it talks about, you'll really learn how to better yourself, and your code. 如果您通读了整本书并理解了其中的内容,您将真正学习如何改善自己和代码。

I find writing unit tests helps code quality a lot - it means you have to think about how your code will interact with the tests and other parts of the code. 我发现编写单元测试对提高代码质量有很大帮助-这意味着您必须考虑代码将如何与测试以及代码的其他部分进行交互。

Peer code-review: Checking quality of code will also make the programmers think about how they write the code. 同行代码审阅:检查代码质量还将使程序员考虑如何编写代码。

It's great that you recognize that there's room for improvement and have the desire to try to enact some change. 很高兴您认识到还有改进的空间,并且渴望尝试进行一些更改。 I suggest reading James Shore's 19-week diary where he documents the steps that he went through to enact agile development at his company. 我建议阅读James Shore的19周日记 ,在日记中记录他为实现公司敏捷开发所采取的步骤。 It's a hard fight, but his experience shows that you can make a difference. 这是一场艰苦的战斗,但他的经验表明您可以有所作为。

Just asking the question is a good start. 仅问一个问题是一个好的开始。

Specifically you can: 具体来说,您可以:

  • Admit that your code sucks 承认你的代码很烂
  • Start asking others, preferably others with more experience, to review your code 开始要求其他人(最好是有更多经验的人)检查您的代码
  • Implement a continuous build server - you have to be the one who uses this first 实施连续构建服务器-您必须首先使用该服务器
  • Have courage because this can be difficult 有勇气,因为这可能很难
  • Be humble 要谦虚
  • Read Code Complete 读取代码完成
  • Use a software development methodology that encourages team work. 使用鼓励团队合作的软件开发方法。 Some of the agile methodologies are really good at this 一些敏捷方法真的很擅长
  • Read development blogs 阅读开发博客
  • Get involved in a user group 参与用户组

Change is hard and you have to be the one who changes first. 改变是困难的,您必须是最先改变的人。

If you are working in an environment where others are happy the way it is you are going to have rough going. 如果您在别人满意的环境中工作,那您将遇到困难。 Be persistent about wanting to improve code quality. 坚持要提高代码质量。

I am biased (as a result of my work), but depending on your budget (if it exists) static analysis is a possible option. 我有偏见(由于我的工作),但是根据您的预算(如果有),静态分析是一种可能的选择。 There are lots of different types of tools, some of which also include coding standard enforcement checking.. 有很多不同类型的工具,其中一些还包括编码标准执行检查。

If you use g++, you might be able to get a basic amount of help from the -Weffc++ option. 如果使用g ++,则可以从-Weffc ++选项中获得基本的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM