[译]阅读大型代码库的技巧
By robot-v1.0
本文链接 https://www.kyfws.com/best-practices/tips-and-tricks-for-navigating-large-codebases-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 20 分钟阅读 - 9758 个词[译]阅读大型代码库的技巧
原文地址:https://www.codeproject.com/Articles/1268669/Tips-and-tricks-for-navigating-large-codebases
原文作者:Mercantilo
译文由本站 robot-v1.0 翻译
前言
How to manage your way through a large and unfamiliar set of code files. 如何通过大量不熟悉的代码文件来管理自己的方式.
介绍(Introduction)
我认为大学现代CS教育中缺少的一件事是如何浏览非常大的代码库,以及如何快速理解它们.(One I thing I believe is lacking in modern CS education in universities is how to navigate extremely large code bases, and how to quickly make sense of them.) 可能没有讲到这一点的一个可能原因是,大多数CS学生最终将在中小型公司工作,在那里他们将专注于一个程序,一个代码库,而以前的员工将足够了解该程序的所有部分.对新来者有较高的要求.(One possible reason this is not taught is that the majority of CS students will end up working in small/medium sized companies where they will be focused on one program, one code base, which previous employees will know well enough to explain all parts of at a high level to the newcomer.) 另一个潜在的原因(可能是真实的原因,但其中一位大学教授不想承认)是,老师们自己从来不必处理任何大于10万行的代码库,而不必处理其他人编写的代码(他们自己的学生除外),但这是另一篇文章的讨论(Another potential reason (likely the real one, but the one university professors don’t want to admit) is that the teachers themselves have never had to deal with any code bases larger than 100K lines, much less had to deal with code written by others (besides their own students), but that’s a discussion for another article)☺
然而,回到我的观点,当一个人加入微软,亚马逊,谷歌,Facebook之类的公司或我真正认为是"大型科技公司"的少数公司中的任何一个时,很容易很快迷失和失败.富有成效.(Back to my point however, when one joins the likes of a Microsoft, Amazon, Google, Facebook or any one of a handful of what I truly consider to be “large tech companies”, it is easy to get lost very quickly and to fail to be productive.) 如果我过去曾指导过的实习生有任何证据,似乎没人会教他们如何处理突然指向他们的代码.因此,希望对以后的编码人员有所帮助,这就是我的看法.(If the interns I’ve mentored in the past are any evidence, no one seems to teach them how to deal with the firehose of code that suddenly gets pointed at them. So in the hopes this will help future generations of coders, here’s my take on it.)
遗失在代码(Lost in Code)
在许多情况下,您可能会发现自己不得不浏览大型外部代码库.一些例子:(There are many situations in which you may find yourself having to navigate a large foreign codebase. Some examples:)
- 您团队中最高级的人可能只待了不到一年,尤其是在流失率很高的公司中,他们自己可能不知道团队需要维护的大部分系统,因为他们只是没有还没有对付他们.现在需要将新功能添加到旧系统中,猜猜老板选择了谁做的?(The most senior person on your team may have just been around for less than a year, especially in a company with a high churn rate, and they themselves may not know large parts of the systems the team is tasked with maintaining because they just haven’t had to deal with them yet. Now that a new feature needs to be added to a legacy system, guess who the boss picked to do it?)
- 您正在与另一个团队的代码打交道,他们没有时间(或不想)向您解释代码,但是您想要/需要理解它.(You are dealing with another team’s code and they don’t have the time (or don’t want to) explain it to you, yet you want/need to understand it.)
- 您正在处理诸如性能或效率之类的跨领域工作,这需要您不断使用他人的代码并每周(或每天)跳动.(You are working on something that is cross-cutting like performance or efficiency which requires you to constantly be working in other people’s code and bouncing around on a weekly (or daily) basis.) 与长时间使用相同的代码相比,这通常会使您处于劣势.(This generally tends to leave you at a disadvantage when compared to working on the same code for a long time.) 那么,如何在不浪费大量时间的情况下简单地找到相关代码并浏览(理解)相同的代码呢?(So how does one go about simply finding relevant code and grokking (understanding) this same code without wasting a lot of time?) 这是如何做.(Here’s how.)
1.不要急(1. Don’t Panic)
每一位优秀的自然生存主义者都会告诉您,野外生存的首要原则是"不要惊慌".(Every good nature survivalist will tell you the first rule of survival in the wild is “Don’t Panic”.) 那么,现在是凌晨2点,服务器正在烧毁,您在浪费钱,而所有高级工程师都在公司每年一次的太浩湖之旅中,却被困在支持上?(So what it’s 2 am, the servers are burning, you’re bleeding money on the floor and all the senior engineers are out on the annual company trip to Lake Tahoe and you got stuck doing support instead?) 现在不是时候curl缩成一团,希望您已经辍学,和怀俄明州的嬉皮姐姐一起养山羊.山羊该死!有要阅读的代码.(Now is not the time to curl up in a ball and wish you had dropped out of college to raise goats with your hippie sister in Wyoming. Goats be damned! There’s code to be read.)
2.获取相关代码在您的面前.(2. Get the relevant code in front of your face.)
您需要擅长的第一件事就是迅速找到正确的代码,并将其摆在眼前.这听起来有些愚蠢,但是我浪费了很多时间(有时甚至更多)来阅读那些不是我感兴趣的代码的代码.(The first thing you need to be good at is quickly finding the right piece of code and getting it in front of your eyeballs. This may sound dumb, but I’ve wasted many minutes (and sometimes more) reading up on code that was not the piece of code I was interested in.) 在投入大量时间阅读大型程序的一部分之前,有两件事要做,首先(There are two things to do before investing a lot of time reading part of a large program, they are first)找到相关的代码(finding the code that is relevant)第二(and second)确保它是正确的代码(making sure it is the right piece of code)在深入潜水之前.(before deep diving in.)
在代码中识别奇数短语并为其进行grep(Identify odd phrases and grep for them in code)
找出是什么代码导致某种行为发生或促使某些UI出现的最简单但功能最强大的方法之一是grep输入您可以识别的奇数短语.(One of the most simple, yet most powerful ways of figuring out what piece of code is causing some behavior to happen or driving some piece of UI to show up is to grep for odd phrases you can identify.) 如果您不知道如何在回购中使用grep,建议您查找一下.如果您正在使用git this(If you don’t know how to grep inside a repo, I encourage you look it up. If you are using git this) 很棒的文章(great article) 应该为您提供一些有关这样做的好提示.不知道如何写正则表达式?你应该.这是另一项非常有价值的技能,网络上有很多很好的教程可以为您提供帮助.但是我离题了^(should give you some good tips on doing just that. Don’t know how to write regular expressions? You should. That’s another skill that is highly valuable and there are lots of good tutorials on the web to help you. But I digress…) “所有事件均记录在太平洋(PST)时区中.“我认为写在网页上的是纯金线.您认为在200万行代码库中重复了多少次具有特定大写字母的长短语?可能只有几个,但这至少可以将搜索范围缩小到几个文件(文件名应该是迅速丢弃不相关代码的第二个提示).(“All events are logged in the Pacific (PST) timezone.” written on a web page is a line of pure gold in my opinion. How many times do you think a long phrase with a specific capitalization like that is repeated in a 2 million line codebase? Probably a few, but that at least narrows down the search to a few files (and the file names should be your second clue to quickly discard unrelated code).) “(“)抛出CatShouldBeADogException(CatShouldBeADogException thrown)是另一块金子.自定义异常(尤其是在Java程序中)可能仅从4或5个地方抛出.在您要处理的内容上添加一点上下文,例如其余的堆栈跟踪,或者前两行日志表明您正在输入另一种方法,您可以非常迅速地缩小范围并获得相关行在你面前的代码.(” is another piece of gold. Custom exceptions (especially in Java programs) are likely only thrown from 4 or 5 places. With a little bit of added context on whatever you’re dealing with, like the rest of the stack trace, or the 2 preceding lines of log that say you’re entering another method, you can very quickly narrow down and have the relevant lines of code in front of your face.) 日志行消息是查找代码的另一个好方法. “(Log line messages are another good avenue for finding code. “)开始用x行处理日志行(Starting to process log lines with x lines)“是不太理想的短语.首先,x是动态的,这意味着您应该grep真正使用的是”(” is a less desirable phrase to search for. First of all the x is dynamic, meaning what you should grep for really is “)开始处理日志行(Starting to process log lines)".使用grep进行更多操作将毫无意义,因为该语句可能被引号和print语句包裹.(”. To grep for anything more will be pointless since the statement is likely wrapped with quotes and a print statement.) 通常,这些可以是一个很好的起点.但是,如果那不能使您到达想要去的地方怎么办?(In general these can be good starting points. But what if that doesn’t get you to where you want to go?)
责备缠扰(Blame stalking)
因此,您知道谁在使用功能,但是您不知道他们在使用什么代码?好吧,那很简单,只怪他们缠着他们!(So you know who is working on a feature, but you don’t know where the code is that they are working on? Well, that’s easy, just blame stalk them!) 我指责跟踪是什么意思?(What do I mean by blame stalking?) 每当有人在任何源代码控制存储库(git,mercurial,svn等)中提交一段代码时,其名称或登录名便与该提交相关联.(Whenever someone commits a piece of code in any source control repository (git, mercurial, svn, etc…) their name or login is associated with the commit.) 如果您知道谁在使用某个特定功能,则查找代码就像在仓库中查找他们触摸过的文件一样容易!(If you know who is working on a particular feature, finding the code becomes as easy as just looking for files they’ve touched in the repo!) 如果您对别人的工作感到好奇,或者您认为他们是热门话题,并且想看看一个真正的工作大师的榜样,那么这就是金矿.(嘿,这有时是学习的好方法!),这是适合您的方法.(This is a gold mine if you are curious about what someone else is working on, or if you think they are hot stuff and want to see an example of a true master at work (hey, that’s a great way to learn sometimes!), this is the method for you.) 做到这一点的方法取决于源代码控制,但是例如使用git可能会做到(Ways to do this depend on the source control, but for example with git one might do)**git log —仅名称— author =imperio59(git log —name-only —author=imperio59)**假设您想查看我的所有提交(包括修改的文件).(assuming you wanted to see all my commits (including modified files).) 从入口点开始(Start at the entry point) 有时没有知道去哪里的好方法.您尝试过拼写奇怪的词组,也曾尝试怪过头.你被困住了.现在可能是将其淘汰并从头开始的时候了.(Sometimes there is no good way of knowing where to go. You’ve tried to grep for odd phrases, you’ve tried blame stalking. You’re stuck. It might be time to slog it out and begin at the beginning.) 寻找该程序的切入点(出于其他原因,这可能还是有教育意义的),然后按照提示进行操作.不过,这可能会很长,因此请将此作为最后的手段.(Look for the program’s entry point (this can anyways be educational for other reasons) and follow the trail. This can be quite long though, so use this as a last resort.)
修改现在找到的代码并确保这是正确的代码(Modify the code now found and make sure that was the right piece of code)
在您花数分钟或数小时阅读此10,000行怪物(Before you invest minutes or hours reading this 10,000 line monster of a) 意大利面条和肉丸(spaghetti and meatball) 您刚刚找到的一门课,请确保它是正确的一个好主意.(class you just found, it might be a good idea to make sure it’s the right one.) 添加打印声明.运行代码,并确保打印出您的照片.最好的行是echo("").该程序不太可能已经打印出您的姓氏,因此在日志或输出中对其进行grepping十分容易.(Add a print statement. Run the code and make sure your print prints. The best line for this is echo(“”). It’s highly unlikely the program is already printing out your last name, so grepping for it in logs or output will be easy.) 或者,您也可以反复重复一些短语(复制/粘贴),例如” FOOFOOFOOFOOFOOFOOFOOFOO”.这是我朋友最喜欢打印的用于调试代码的行,并且在日志输出中也很出色(除非他幼稚地喜欢用P替换F.现在,孩子们,知道吗?)(Alternately you can also repeat some phrase over and over (copy/paste) like “FOOFOOFOOFOOFOOFOOFOOFOO”. This is my friend’s favorite line to print for debugging code and it stands out well in log output too (except he childishly likes to replace the F with a P. Kids these days, you know?))
3.阅读一些代码(3. Read some code)
好的,您已经找到了想要阅读的相关代码.怎么办?(Ok you’ve found relevant code you want to read up on. Now what?) 是时候读我的朋友了!但是不只是阅读,不是.我们将要阅读,以便可以了解正在阅读的内容.有所不同.愚蠢地逐行扫描,没有得到我们正在阅读的内容的一半,希望我们能获得某种神奇的理解,或者通过深入的反复阅读而只是"得到它”,这对我们没有好处.(Time to read my friend! But not just any reading, no. We are going to read so we can understand what we are reading. There is a difference see. It does us no good to stupidly scan line by line, not getting half of what we are reading, hoping we will come to some magical understanding, or through deep, repeated readings we will just “get it”.) 我认为有三件事可能会妨碍您对他人代码的理解:(There are in my opinion three main things which can impede your understanding of others’ code:)
- 您不了解代码的编写惯例. (命名约定,样式约定…)(You don’t understand some convention of how the code is written. (Naming conventions, style conventions…))
- 您不了解功能的作用,因为您之前从未接触过它.(You don’t understand what a function does because you’ve never come across it before.)
- 您不了解编码语言本身的某些知识.(You don’t understand something in the coding language itself.) 让我们来看看如何处理这些问题:(Let’s go over how to deal with each of these:)
1.编码约定,样式指南和发明自己的东西的人(1. Coding conventions, style guides and people inventing their own stuff)
人们在命名变量,类或方法时并没有使用很多约定.根据您使用的语言,某些命名约定可能是该语言本身的一部分(因为在变量或函数中必须使用该样式来命名).(There aren’t that many conventions people use when naming variables, classes or methods. Depending on the language you are dealing with, some naming conventions may be part of the language itself (as in the variable or function is named in that style because it has to be).) 对于命名约定,我发现人们通常会坚持基础知识.好老(For naming conventions I find people usually stick to the basics. Good old) 匈牙利文符号(Hungarian notation) 或其一部分仍在附近.有时人们添加小写字母(or a subset of it is still around. Sometimes people add a lowercase)米(m)对每个(to every)会员(member)类的变量,以区别于局部变量.有些人在local_variables_have_underscores时强制编写memberVariablesInCamelCase.有时私有函数在publicMethodsDont时命名为_startWithAnUnderscore.(variable of a class, to differentiate it from local variable. Some people enforce writing memberVariablesInCamelCase while local_variables_have_underscores. Sometimes private function names _startWithAnUnderscore while publicMethodsDont.) 无论采用哪种约定,都要迅速找出答案.如果幸运的话,内部Wiki上有已发布的代码样式指南.阅读.阅读代码.再次阅读样式指南.(Whatever the convention is, figure it out, and fast. If you’re lucky there’s a published code style guide on an internal wiki. Read it. Read the code. Read the style guide again.) 代码约定不是邪恶的,它们可以帮助您快速地对变量和函数的类型进行分类,从而帮助您更快地阅读和理解代码.但是他们只会加快你的速度(Code conventions aren’t evil, they’re there to help your reading and understanding of code speed up by helping you classify types of variables and functions quickly. But they only speed you up)**如果(if)**您对惯例非常了解,否则每次您碰到公约时,都会增加一些额外的摩擦,从而模糊您的理解. (“现在为什么他们为什么要调用此mServiceManager而不是serviceManager ?!")(you know the convention fairly well, otherwise they cloud your understanding by adding a bit of extra friction every time you come across it. (“Now why the heck did they call this mServiceManager instead of serviceManager?!” ).) 最后,有时人们会发明自己的样式指南,而不在任何地方发布.如果按照我的经验是这样,那么编写代码的人会很着急,没有回去写样式指南或在任何地方记录它(准备发现周围有一些小问题),或者这个人太过自我-重要的是编写样式指南或解释他们在做什么(这些"我的代码因为没有错误而无需进行单元测试"类型,是的!),在这种情况下,代码将被过度设计,肿和越野车.(Lastly, sometimes people invent their own style guide and don’t publish it anywhere. If that’s the case in my experience either the person who wrote the code was in a hurry and didn’t come back to write a style guide or document it anywhere (be prepared to find some dumb bugs laying around) or the person was too self-important to write a style guide or explain what they were doing (one of these “My code doesn’t need unit tests because it has no bugs” types, yea right!) in which case the code is going to be over-engineered, bloated and buggy.) 无论哪种方式,某些非标准,未记录的编码约定都可能表示地平线水手可能无法自酿啤酒,因此请戴上帽子.(Either way, some non-standard, non-documented coding convention is likely a sign there may be trouble brewing on the horizon sailor, so hang on to your hat.)
2.实用功能,随机方法和不良命名(2. Utility functions, random methods and bad naming)
在阅读代码时会使您减速的第二件事是您从未听说过的函数.(The next thing that will slow you down when reading code is functions you have never heard of.) 如果您退后一步,然后再看一门语言,它就是由您应该理解的简单构建块组成的:创建新变量,为其分配值,执行一些条件逻辑,可能执行一些循环以及如果您不太幸运使用一些二进制算术.但是,假设您对语言的了解很好,那么接下来要知道的是您所阅读的函数在做什么.(If you step back and look at a language, it is composed of simple building blocks which you should understand: creating new variables, assigning them values, doing some conditional logic, maybe a few loops and if you’re unlucky some binary arithmetic. But assuming you know your language well, the next thing to know is what function calls you read are doing.) 为了本文的方便,我们将它们分为两种类型的函数:(For the sake of this article let’s classify these into two types of functions:)
- 实用程序功能(也称为库功能)(Utility functions (also called library functions))
- “业务逻辑"功能.(“Business logic” functions.) 实用函数或库函数是一类函数,几乎所有东西都可以重复使用.需要格式化日期吗?有一个实用程序.解析一些JSON?还有另一种.(Utility functions or library functions are a class of function which are re-used by almost anything. Need to format a date? There’s a utility for that. Parsing some JSON? There’s another one for that.) 通常但并非总是如此,这些方法是该语言标准库集合的一部分.有时它们会成为某些第三方库的一部分(无论是否开放源代码).(Usually but not always, these methods are part of the standard set of libraries for the language. Sometimes they will be part of some 3rd party library (open source or not).) 如果您从未见过其中的任何一个,那么可以充分利用时间阅读其文档.它需要什么输入?它产生什么输出?它会改变输入还是仅使用输入?有没有(If you have never seen a particular one of these, it’s a good use of time to read its documentation. What input does it take? What output does it produce? Does it mutate the input or merely use it? Are there any) 副作用(side-effects) 调用函数?该功能将有多慢/快?(to calling the function? How slow/fast is the function going to be?) 实用程序函数的另一个子类是特定于您所使用的代码库的库函数.这是您正在阅读的代码中每第5行看到的函数之一,并且似乎可以用于所有代码.同样,花一些时间来理解它是明智的.(The other sub-class of utility functions is library functions specific to the codebase you’re in. This is one of those you are seeing every 5th line in the code you are reading, and that seems to be used for everything. Again, it’s wise to spend some time understanding it.) 接下来是业务逻辑功能.这些是代码土豆的肉.他们会做您来这里阅读的内容.(Next is business logic functions. These are the meat to your code’s potatoes. They do the stuff you came here to read about.) 阅读它们.但不是每一行.除非你需要.(Read them. But not every line. Unless you need to.) 让我解释.(Let me explain.) 每当我觉得需要阅读正在阅读的程序中包含的功能时,我都有两种选择.我可以决定深入了解它的每个部分,也可以从表面上看待它.(Whenever I feel I need to go read up on a function that is a part of the program I am reading, I have two choices. I can either decide to deeply understand every part of it, or take it at face value.) 从表面上看它意味着我将阅读函数的名称,输入变量的名称,扫描代码以对它的功能有一个高级的了解,弄清楚它返回或对程序的其他部分起作用(或两者,这是我心中的代码味道),然后继续.(Taking it at face value means I will read the name of the function, the name of the input variables, scan over the code to get a high level understanding of what it does, figure out what it returns or does to other parts of the program (or both, which is a code smell in my mind) and move on.) 除非我重构影响该功能的内容,否则我不会阅读每一行.我不需要!一切就绪,BOOM,我将继续前进到下一个!(Unless I am refactoring something that impacts this function, I will not read every line. I don’t need to! As soon as I get what it does, BOOM, I’m moving on to the next one!) 一天中我几乎没有时间知道这15,000行中的每一行的工作.我只是想知道书名并阅读书的背面,而不是阅读全文,非常感谢.(There is too little time in the day for me to know what every one of those 15,000 lines does. I just wanted to know the title and read the back of the book, not read the full story, thank you very much.) 对此有一个例外,那就是人们(根据他们编写的代码的证明)必须是猴子的人编写的代码.(There is one exception to this and that is code written by people who (by evidence of the code they wrote) must be monkeys.) 如果每个变量都被命名为” thingA,thingB,thingC”,或者更糟糕的是方法的一半在一个名为” util"的文件夹中,那么您将陷入困境.这些人通常不知道从一开始就如何专业地进行编码,或者如何很好地组织许多代码,因此一开始就不应该雇用他们.(If every variable is named “thingA, thingB, thingC”, or worse half of the methods are in a folder named “util”, you’re in for a rough ride. These people generally do not know how to code professionally to begin with, or how to organize lots of code well and should likely not have been hired in the first place.) 假设您正确命名,大多数情况下代码都是自我记录(Code is self documenting most of the time assuming you name things properly).如果您没有正确命名,那就太乱了.(. If you don’t name things properly, it’s a mess.) 这也可能是更新简历并开始写回您在LinkedIn上收到的所有招聘电子邮件的时候.如果您维护的代码中有30%以上是猴子代码,那么您一开始可能就无法获得足够的报酬来维护它. (毕竟,您正在阅读本文,这意味着您关心软件和您的工作.对于猴子来说,也是如此.猴子编写了您现在正试图在凌晨2点调试的那段代码,他数着羊在公司一角硬币上的太浩湖小木屋中)(This might also be the time to update your resume and start writing back to all those recruiter e-mails you’ve been getting on LinkedIn. If more than 30% of the code you maintain is monkey code, you’re probably not getting paid enough to maintain it to begin with. (After all you’re reading this article, which means you care about software and your job. The same can’t be said for the monkey who wrote that piece of code you’re now trying to debug at 2 am while he’s counting sheep in a cabin in Lake Tahoe on the company dime).) 最后,单元测试对于编写代码非常有帮助.(Finally, Unit tests can be very helpful to grokking code.) 如果您偶然发现正在读取的功能具有相应的单元测试,则通过读取测试来了解该功能的作用可能会更快.(If you happen to notice that a function you are reading has a corresponding unit test, it’s probably faster to understand what the function does by reading the test.) 假设测试不是由猴子写的.(Assuming the test was not written by a monkey.)
3.您不了解自己的编码语言(3. You don’t understand something in the coding language itself)
哦,我的上帝!什么?!你应该为自己感到羞耻!(Oh my god! What?! You should be ashamed of yourself!) … 或不.(… or not.) 我的意思是所以呢?你不知道,所以你查一下.不要为自己感到难过,教育自己!(I mean come on. So what? You don’t know, so you look it up. Don’t feel bad about yourself, educate yourself!) 您如何认为最好的程序员必须如此出色?他们只是阅读有关软件和代码的信息.很多.一遍又一遍,直到它是第二天性.(How do you think the best programmers got to be so good? They just read about software and code. A lot. Over and over until it is second nature.) 因此,您永远不会遇到(So you’ve never come across the)易挥发的(volatile)Java中的关键字,但突然每个其他文件都有一个声明为volatile的成员变量?现在,是阅读Java并发和线程并获得更多知识的好时机.它将非常方便.(keyword in Java but suddenly every other file has a member variable declared volatile? Well now would be a good time to go read up on Java concurrency and threading and get some more knowledge. It will come in very handy.) 因此,您从未见过有人将参数绑定到Javascript中的函数(例如(So you’ve never seen someone bind arguments to a function in Javascript (like)foo.bind(this,arg1)(foo.bind(this, arg1)))?现在可能是时候进一步了解JS中的闭包了.()? Now is probably the time to learn a little bit more about closures in JS.) 事实是,如果您认为学习是在毕业的那一刻,那么有人对您撒谎(或者您对自己撒谎).大学(或任何形式的编程初级教育)为您提供基础知识.剩下的,您将需要自己学习,具体取决于您的专业以及日常工作中遇到的问题.(The fact of the matter is if you thought learning was over the moment you graduated, someone lied to you (or you lied to yourself). College (or whatever form of primary education on programming you got) gives you the basics. The rest you will have to learn on your own, depending on what you specialize in, and what you come across in your day job.) 此外,科技行业正在不断发展,创新和自我改造.今天的软件与十年前的软件不同.甚至是五年前.(Plus, the tech industry is constantly moving, innovating, reinventing itself. Software today is not written like software ten years ago. Or even five years ago really.) 如果您不了解某些内容,请不要对自己感到沮丧.查找它,变得更聪明,提高自己的技能.从长远来看,这是唯一的方法.(Don’t get frustrated with yourself if you don’t know something. Look it up, become smarter, improve your own skills. It’s the only way to go in the long run.)
结论(Conclusion)
因此,现在您知道了如何在大型外部代码库中找到相关的代码,并且希望您已经学到了一些有关如何快速理解它而又不会陷入困境的知识.(So now you know how to find relevant code in a large foreign codebase, and hopefully you’ve learned a few things about how to quickly understand it and not get stuck too.) 最后,我要说的最后一件事:成为一名优秀的代码公民.(In closing I would say one last thing: be a good code citizen.) 代码有时可能像一个大城市.它的某些部分干净整洁.有些零件的窗户破损,并用胶带粘住了迹象.(Code can be like a big city at times. Some parts of it are nice and clean. Some parts have broken windows and signs held up with duct tape.) 即使发现的状态并非严格属于您,也要通过改善它们所处状态的状态来发挥自己的作用(当然,在进行修复之前,请先获得所有者的许可或代码审查!).(Do your part by improving things you come across which are in a bad state, even if they might not strictly speaking belong to you (but do get permission or code review from the owner before checking in a fix, of course!).) 毕竟您不知道,这可能是一天中凌晨2点向您分页的那段代码.您会很高兴自己是重构它的人.(After all you never know, this might be the piece of code that pages you at 2 in the morning one day. And you’ll be glad you were the one who refactored it when it does.)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
Tips tricks navigating large codebase 新闻 翻译