惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Attack and Defense Labs
Attack and Defense Labs
D
Darknet – Hacking Tools, Hacker News & Cyber Security
V
Vulnerabilities – Threatpost
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Project Zero
Project Zero
P
Palo Alto Networks Blog
G
GRAHAM CLULEY
www.infosecurity-magazine.com
www.infosecurity-magazine.com
H
Hacker News: Front Page
Help Net Security
Help Net Security
S
Schneier on Security
A
Arctic Wolf
Know Your Adversary
Know Your Adversary
L
LINUX DO - 热门话题
Security Archives - TechRepublic
Security Archives - TechRepublic
L
LangChain Blog
T
The Exploit Database - CXSecurity.com
V2EX - 技术
V2EX - 技术
罗磊的独立博客
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
有赞技术团队
有赞技术团队
P
Privacy & Cybersecurity Law Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
C
Cybersecurity and Infrastructure Security Agency CISA
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
J
Java Code Geeks
量子位
大猫的无限游戏
大猫的无限游戏
C
Check Point Blog
云风的 BLOG
云风的 BLOG
SecWiki News
SecWiki News
Hacker News: Ask HN
Hacker News: Ask HN
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Troy Hunt's Blog
U
Unit 42
N
Netflix TechBlog - Medium
阮一峰的网络日志
阮一峰的网络日志
The Register - Security
The Register - Security
Recorded Future
Recorded Future
爱范儿
爱范儿
Webroot Blog
Webroot Blog
Engineering at Meta
Engineering at Meta

GeekPlux

一代人的博客,一代人的青春注脚 那些年我打过的日结工 来美国的两年后 2023 一蓑烟雨 在美国拥有一辆 Tesla 的成本 我的 Workspaces 十年进化史 How to Sync Logseq Plugins, Themes and Settings Across Multiple Devices Setting Up Umami as Your Google Analytics Alternative: A Step-by-Step Guide 迁移豆瓣读书记录到 goodreads Enhance Your Internet Privacy in 2023 Refactor your blog comments system with Webmention.io 来美国之后,如何快速安顿下来 Three Levels of Information Perception 疫情三年 与人聊天的美好 我获取信息的方法 2022 版 我是如何学会编程的 2020 恍如隔世 接外包的一些坑和小技巧 论交友 往返香港隔离指南 即将失明,还能继续做程序员吗 小谈我对新技术的态度 How to use tailwindcss with AMP in a Next.js project 远程工作如何提高效率 复式记账、财报、量化与图论 我为什么从阿里巴巴离职 2019 柳暗花明 投资被动型指数基金正在造成下一次金融泡沫? 三种主流的网赚套利,躺着赚钱? 色盲的世界 我是如何管理 21 张信用卡的 薅羊毛的最大意义:保持对规则的敏感度 来香港的两个月 数据可视化技术实现的关键点 如何找到时薪 80 美元的远程工作(二) 如何找到时薪 80 美元的远程工作(一) 如何打造真正的简历 浅思图数据可视化 舍本逐末的学习方式 给想转行作程序员的人泼一盆冷水 算法优化人生之 —— 调度算法 杭州最适合闲来溜达的几条路线 2018 平淡无奇 突闻金庸先生逝世有感 十年博客折腾历史 数据可视化之 Sankey 桑基图的实现 研究生生涯总结 Web 前端中的增强现实(AR)开发技术 参加 Google Summer of Code 的体验 netjsongraph.js – Google Summer of Code (GSoC) 2017 summary 如何在 GitHub 上获得数百 stars Markvis - 在 markdown 中生成可视化图表 D3 force layout and WebGL integration 文本数据可视化(下)——一图胜千言 文本数据可视化(上)——从 Wordle 谈起 我获取信息的渠道 数据可视化基础——视觉编码 数据可视化基础——数据模型 数据可视化基础——可视化流程 为什么要用 Emacs Vega-Lite: A Grammar of Interactive Graphics 如何阅读一篇学术论文 超过十个人的微信群根本没有价值 毕业后的两年 建立索引式的学习方法 为什么我喜欢写代码 为什么文章写得好的人都很厉害 人总要有点盲目的自信 如何管理好自己的密码 Backbone View 之间通信的三种方式 Vim - 适合自己的,才是最好的 轻松玩转 Ukulele 告别社交网络有多难 双拼学习记 CoffeeScript 编码风格指南(译) CoffeeScript 笔记 CSS 最核心的几个概念 响应式设计简易指南(译) 初识 TDD Collapsing margins——合并的外边距 菜鸟级 Mac 配置(二) 菜鸟级 Mac 配置(一) CSS 编写原则 Goodbye,我的大学 如何新建一个 Cocos2d-x 项目 Windows8.1 下 Cocos2d-x 环境搭建 Android 开发如何入门 如何绑定独立域名 写博客就用 FarBox 尝试改变微信公众账号消息的推送方式 情似流水 操作系统总结——存储器管理 操作系统总结——处理机管理 操作系统总结——引论 C++指针与引用小结 该不该制定计划 幸福,是一种能力 弱冠,瞎扯 别当回事儿
Legacy code best practice: how to take over an existing project smoothly
GeekPlux · 2021-01-27 · via GeekPlux

Legacy code best practice: how to take over an existing project smoothly

Every programmer, I guess, would meet the code from others that you have never contributed to. And one of the ways to distinguish experienced programmers from beginners is to see if they can quickly dive into the legacy code and maintain, develop, and refactor it in the right way.

There is no silver bullet to approach it, I’ve also been caught in the nightmare of not being able to read the code at all. But I have some tips from my experience to guide you to master it step by step. Hope it would be helpful.

1. Ask for documentation or explanation

It’s very lucky if there is some detailed documentation, or if the person who wrote the code is still around. This can save you a lot of time, but of course the best way is that the previous team can help you walk through the whole codebase.

In this stage, you’d better know:

  • how to run the whole project code
  • any easier way to test or debug during development
  • the version control tool they used
  • how to release and deploy
  • any dependent library you should notice

if there are no docs and no person was responsible for it available, promise me, please do not get angry and smash your keyboard :)

smash keyboard panda

2. Fix minor bugs

Learn by doing is always the fastest way to master code. For instance, if the legacy code is for the front-end, you can just change the Button style, if it’s for the back-end, you can just replace the response, that’s the easy but effective method to:

  • know and practice how to debug during developing
  • know each function’s purpose and its scope, roughly

These small bugs or tweaks allow you to get better familiar with the code, especially if you are really confused and have no idea how to start.

3. Keep new code clean

If you do not want to make things more complicated, then keep your new code clean. To follow the Unix philosophy, make each function do one thing and do it well.

You can’t control the quality of the inherited code, but you can make sure the code you add is the style you love.

4. Only rewrite code when necessary

I know every developer can’t help trying to rewrite the legacy code, but it usually brings much undesirable behavior.

Every time when I have to rewrite some functions, I will imagine the code taken over is a black box full of magic (and it always is!) so that I will be careful with each input and output.

When it comes to interdependent functions, try to control the scope of their impact, change the code as little as possible, try to ensure that no new bugs are introduced, and keep smooth iterative development.

5. Modularize code to the minimum possible

Maintaining and developing the legacy code is a progressive process. When you have to rewrite it, don’t rush to completely overturn the previous code first, try to take it apart first.

Dividing code makes you understand the code logic totally. You could keep the input params and output as simple as possible. Roughly split first, and then split again on top of that until it is minimized.

The advantage of this step is that any future refactoring of your code will also bring minimal impact.

modularize like lego

6. Refactor after modularization

Best practices for refactoring are written in many books, but I still recommend doing it on top of completing the previous step. Which will take weeks, months or possibly years depending on the complexity.

At the same time you need to keep up with the speed of developing new features, so it’s a trade-off. I know that refactoring parts of the legacy code can improve the speed of writing new code, but it can also be more of a burden. It needs much patience to take your time and get the refactoring done.

Conclusion

In short, don’t rush to overturn all the old code, but change it little by little, modularize and optimize it. Which like eating a pie, starting from the edges and working your way to the core, little by little.