Read the code to benefit so big, so bring you 7 ways to improve code reading capability

7 ways to improve code reading capability

1. Run the code - this is the first step in reading the code. It may not give you too many details about the project, however, you will know how to build it and run it, you will learn about the use of its library, it depends on the development framework and so on, which is to improve you for a particular a good way to understand the project. If you want to write to a specific project you are exploring similar to your own software, you might be using a framework or library you should have some idea.

 

2. Find high-level logic - when you start reading the code of a project, you might fall into every detail of them. This is problematic, on the contrary, you should focus on high-level structure. To find the entry point, and from there, most of the major software projects have a way to start from there. In addition, if this is a web application, start looking at different packages, such as business logic stored where, UI code is stored where, where the controller and so on. Generally speaking, the entire project is to browse and get a basic idea, then ask what they want to focus on, I start reading from that part. You can not read the entire code base, but only read part of it may cause your interest. When you find your entry point, you can call the method, see where it leads you to in order to understand the business logic of the project.

 

3. Use the / tools to understand - there are many tools that can be used to read and explore the source code that helps to visualize the code. For example, IntelliJIdea navigation tool has the function of the source code, allowing you to pass part of the word, the word, the word is an abbreviation or even to search. You should also learn the keyboard shortcuts. Use the mouse to navigate the source code can be quite boring and slow, use keyboard shortcuts to jump faster. You can quickly jump from one part to another part of the source code.

After reading the code there is a good software, called Sourcegraph, which was created by two Stanford University graduate, who is Quinn Slack and Beyang Liu, they spend time looking at the lack of documentation of the code, we decided to develop a tool to help them better read and understand the code.

 

 

4.了解语言/约定——深入了解某个特定语言有助于提高代码阅读技能。每种语言都有自己的一套约定、样式和语法。这些知识帮助你快速地熟悉一个特定的代码。例如,在java语言中,方法名以小写字母开头,而在C#语言中,方法名以一个大写字母开头。知道这个区别可以帮助你从源代码中识别方法。

 

 

5.阅读最佳实践/设计模式——你正在阅读的代码,或者它的某个结构,可能看起来很晦涩,或者你可能不熟悉它,这是很自然的。有许多良好的实践和设计模式,人们用它来正确地和最佳地做事。例如,有一种模式称为Singleton,它的构造函数保持私有。你可能会问,究竟为什么有人想保持构造函数私有呢。我一直认为它是公有的,否则,我如何创建一个类的实例。嗯,这背后有一个原因。Singleton模式防止你不止一次地实例化一个类,其中有许多实际的应用案例。如果你了解这种模式,你就不会为此而头撞南墙了。因此,对于某些模式的了解,例如,Gang of Four(Erich Gamma, Richard Helm, Ralph Johnson,John Vlissides软件设计领域的四位世界顶级大师.)有23种有文档说明的设计模式,可以显著地帮助你提高代码阅读能力。

 

6.代码审查——软件开发是一个非常讲究协作的工作。没有人可以单独构建一个大型的或重要的软件。每个软件都是由一个团队构建的。在一个团队中,每个人都贡献自己的一份力量去塑造这个项目。在项目结束的那一天,每个人的贡献都会合并成一份对用户真正有价值的工作。除了做实际的编码以外,现在每一个团队都有另外一种做法,那就是在进行观察、建议和相互学习时,互相审查对方的代码。这是一个构建代码库知识的强有力的工具,在团队中建立牢固的纽带,提高代码质量,从而减少系统中的错误,并使客户满意。

做代码检查,你不得不阅读团队中其他人的代码,最终会提高你的代码阅读能力。

 

 

7.临时重构——临时重构也可以帮助您提高代码阅读技能。你可以找取一段长的方法代码,然后不断地把方法细分成多个部分。持续分解,直到你了解这一大段方法代码背后真正的意义。之后,你可以对这些方法做些注释,然后回滚这些更改。

这可以帮助你理解方法的架构,也可以增加你代码重构的知识。

Guess you like

Origin www.cnblogs.com/qingdeng123/p/11247089.html