1 Make it a habit to spend time reading high-quality code that others have written
.
2 Being able to rapidly differentiate good code from bad code is a valuable skil
You can easily discern code of low quality by the following signs:
- An inconsistent coding style
- A gratuitously complicated or unreadable structure
- Obvious logical errors or omissions
- Overuse of nonportable constructs
- Lack of maintenance
3 Read code selectively and with a goal in your mind
.
Are you trying to learn new patterns, a coding style, a way to satisfy some requirements? Alternatively, you may find yourself browsing code to pick up random gems. In that case, be ready to study in detail interesting parts you don't know: language features (even if you know a language in depth, modern languages evolve with new features),
API s, algorithms, data structures, architectures, and design patterns.
4 Notice and appreciate the code's particular nonfunctional requirements that might give rise to a specific implementation style
.
Requirements for portability, time or space efficiency, readability, or even obfuscation can result in code with very peculiar characteristics.
5 Sometimes you may find yourself reading code from an environment completely foreign to you
(computer language, operating system, or
API ). Given a basic familiarity with programming and the underlying computer science concepts, you can in many cases use source codeas a way to teach yourself the basics of the new environment. However, start your reading with small programs
; do not immediately dive into the study of a large system. Build the programs you study and run them.
This will provide you with both immediate feedback on the way the code is supposed to work and a sense of achievement. The next step involves actively changing the code to test your understanding
. Again, begin with small changes and gradually increase their scope.
Your active involvement with real code can quickly teach you the basics of the new environment
.
Once you think you have mastered them, consider investing some effort (and possibly
some cash) to learn the environment in a more structured way. Read related books, documentation, or manual pages, or attend training
6 The key concept when you are using code as exemplar is to be flexible
.
Be prepared to use a number of different strategies and approaches to understand how the code works. Start with any documentation you might find (see Chapter 8 ). A formal software design document would be ideal, but even user documentation can be helpful. Actually use the system to get a feeling of its external interfaces.
Understand what exactly are you actually looking for: a system call, an algorithm, a code sequence, an architecture? Devise a strategy that will uncover your target.
Different search strategies are effective for different purposes.
You may need to trace through the instruction execution sequence, run the program and place a breakpoint in a strategic location, or textually search through the code to find some specific code or data elements
。
7 Once you locate the desired code, study it, ignoring irrelevant elements
.
This is a skill you will have to learn.If you find it difficult to understand the code in its original context, copy it into a temporary file and remove all irrelevant parts
. The formal name of this procedure is slicing but you can get the idea by examining how we have informally applied it in the book's annotated code examples.
8 In other cases code, rather than being an exemplar, may actually need fixing
.
If you think you have found a bug in a large system, you need strategies and tactics to let you read the code at increasing levels of detail until you have found the problem. The key concept in this case is to use tools . Use the debugger, the compiler's warnings or symbolic code output, a system call tracer, your database's this case is to use tools Structured Query Language ( SQL ) logging facility, packet dump tools, and Windows message spy programs to locate a bug's location.
.Examine the code from the problem manifestation to the problem source. Do not follow unrelated paths.
9
分享到:
相关推荐
本文将针对《reading-code-of-nginx-1.9.2_y123456yz.tar.gz》这个压缩包中的内容,对Nginx 1.9.2的源码进行深入解读,旨在帮助读者理解其内部机制和工作原理。 一、Nginx架构概述 Nginx采用模块化设计,主要分为...
热更新时,我们执行命令 npm install -g cordova-hot-code-push-cli安装插件,但运行cordova-hcp server会报错,如:Could not create tunnel: { Error: ngrok is not yet ready to start tunnels...,这时我们找到...
Exploiting Software - How to Break Code.rar
<br/>Code-reading requires its own set of skills, and the ability to determine which technique you use when is crucial. In this indispensable book, Diomidis Spinellis uses more than 600 real-...
code-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zipcode-server-4.92.2.zip...
VB-Code-教育-学生考试系统-源代码全VB-Code-教育-学生考试系统-源代码全VB-Code-教育-学生考试系统-源代码全VB-Code-教育-学生考试系统-源代码全VB-Code-教育-学生考试系统-源代码全VB-Code-教育-学生考试系统-源...
code-server-4.93.1-rc.1-linux-amd64.tar.gz code-server-4.93.1-rc.1-linux-amd64.tar.gz code-server-4.93.1-rc.1-linux-amd64.tar.gz code-server-4.93.1-rc.1-linux-amd64.tar.gz code-server-4.93.1-rc.1-...
启动cordova-hcp server报错 Could not create tunnel: { Error: ngrok is not yet ready to start tunnels 时,将路径 下的cordova-hot-code-push-cli文件下用下载的文件替换就可以了
需要注意的是,`googlecode` 已经在2015年停止服务,因此获取 `maven-db-plugin` 最新版本可能需要从其他源(如 Maven 中央仓库或 GitHub)查找。同时,随着 Maven 生态系统的不断发展,可能有其他更现代的、维护更...
linux版本的vscode,可直接安装,支持ubuntu,elementaryos,deepin,debian-----------------------------------------------
启动cordova-hcp server报错 Could not create tunnel: { Error: ngrok...时,将路径 我个人的是:(C:\Users\lenovo\AppData\Roaming\npm\node_modules)下的cordova-hot-code-push-cli文件下用下载的文件替换就可以了
vscode-配置文件.code-profilevscode-配置文件.code-profilevscode-配置文件.code-profilevscode-配置文件.code-profilevscode-配置文件.code-profilevscode-配置文件.code-profilevscode-配置文件.code-...
cocos-code-ide-win64-1.2.0
Cherny-Well-That-Escalated-Quickly-How-Abusing-The-Docker-API-Led-To-Remote-Code-Execution-Same-Origin-Bypass-And-Persistence
Offers seamlessly-integrated explanations of Java 5.0's key innovations, from generics to annotations Shows how TDD impacts system design, and vice versa Complements any agile or traditional ...
主要语言:TypeScript 项目分类:[AI] 项目标签:[深度学习] [图像工具箱] 推荐理由:一个支持拖拽屏幕截图并将其转换为干净的...这个工具可以帮助开发者快速地将设计图转化为可用的前端代码,提高开发效率。
us-17-Cherny-Well-That-Escalated-Quickly-How-Abusing-The-Docker-API-Led-To-Remote-Code-Execution-Same-Origin-Bypass-And-Persistence_wp