学习如何更好地阅读代码的资源 [英] Resources for learning how to better read code

查看:30
本文介绍了学习如何更好地阅读代码的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近继承了一个大型代码库,不得不阅读它.问题是,我通常是开始一个项目的开发人员.结果,我没有太多阅读代码的经验.

I recently inherited a large codebase and am having to read it. The thing is, I've usually been the dev starting a project. As a result, I don't have a lot of experience reading code.

我对不得不阅读大量代码的反应是,嗯,重写它.但我需要让自己快速跟上进度,并在现有系统的基础上进行构建.

My reaction to having to read a lot of code is, well, umm to rewrite it. But I need to bring myself up to speed quickly and build on top of an existing system.

其他人是否有他们学到的技术来吸收代码库?在这一点上,我只是在阅读代码.我试过使用 UModel 生成 UML 图.它们太大了,打印不干净,当我放大时,我真的失去了看到所有关系的视角.

Do other people have techniques they've learned to absorb a code base? At this point, I'm just reading through the code. I've tried generating UML diagrams using UModel. They're so big they won't print cleanly and when I zoom in, I really do lose the perspective of seeing all the relationships.

其他人是如何解决这个问题的?

How have other people dealt with this problem?

推荐答案

哇 - 我真的刚刚听完关于阅读代码的播客!!!

Wow - I literally just finished listening to a podcast on reading code!!!

http://www.pluralsight-training.net/community/blogs/pluralcast/archive/2010/03/01/pluralcast-10-reading-code-with-alan-stevens.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+pluralcast+%28Pluralcast+by+Pluralsight%29

我建议听听这个.一个有趣的观点是我发现激进的,可能是你可以尝试的东西(我知道我要去!).下载整个源代码库.开始编辑和重构代码,然后……扔掉那个版本!!!我认为,鉴于我们对截止日期的所有要求,大多数开发人员甚至不会这样做.

I would recommend listening to this. One interesting point that was made that I found radical and may be something you could try (I know I'm going to!). Download the entire source code base. Start editing and refactoring the code then...throw that version away!!! I think with all the demands that we have with deadlines that doing this would not even occur to most developers.

我在自己的工作中与您处于类似的位置,我发现以下内容对我有用:- 在现有代码上编写测试用例.为了能够编写测试用例,您需要能够理解 cde 基础.- 如果可用,请查看产品生命周期中记录的错误\问题,并查看它们是如何解决的.- 尝试重构一些代码 - 你可能会破坏它,但没关系,你可以把它扔掉重新开始.通过将代码分解成更小的问题,你会更好地理解它

I am in a similar position to you in my own work and I have found the following has worked for me: - Write test cases on existing code. To be able to write the test case you need to be able to understand the cde base. - If it is available, look at the bug\issues that have been documented through the life cycle of the product and see how they were resolved. - Try and refactor some of the code - you'll probably break it, but that's fine you can throw it away and start again. By decomposing the code into smaller problems you'll understand it bettter

不过,在重构时您不需要进行剧烈的更改.当您阅读代码并理解某些内容时,请重命名变量或方法名称,以便更好地反映要解决的问题.

You don't need to make drastic changes when refactoring though. When your reading the code and you understand something, rename the variable or the method names so the better reflect the problem the are trying to solve.

哦,如果可以,请获取 Michael C. Feathers 撰写的《有效地使用遗留代码》的副本 - 我认为您会发现它在您的情况下非常宝贵.

Oh and if you can, please get a copy of Working Effectively with Legacy Code by Michael C. Feathers - I think you'll find it invaluable in your situation.

祝你好运!

这篇关于学习如何更好地阅读代码的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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