调试代码遗留

by Felipe Lopes

通过Felipe Lopes

陷入遗留代码地狱吗? 这里有一些想法可以帮助您处理情况 (Stuck in legacy code hell? Here are some few thoughts to help you manage the situation)

I’m gonna tell you a little story about how I ended up in a legacy code project and how our team managed to get the best from that.

我将向您介绍一个有关我如何结束遗留代码项目以及我们的团队如何从中获得最大收益的小故事。

首先,一点背景 (First, a little bit of context)

I’ve been working for almost a year on a project, that is quite complex, to say the least.

至少可以说,我已经在一个项目上工作了将近一年,这个项目非常复杂。

While I pass the time reading here at Medium about all the awesome things people are doing around the world in software engineering (creating big infrastructures, putting together several cutting-edge systems to respond to thousands of requests per second ), part of my daily life as a software engineer has not been-so-glamorous. Which is to keep an old extension, for an old platform, up and running properly.

当我花时间在Medium上阅读有关人们在软件工程领域正在做的所有令人敬畏的事情(创建大型基础架构,将几个尖端系统组合在一起以每秒​​响应数千个请求)时,这是我日常生活的一部分作为软件工程师并没有那么出色。 这是为旧平台保留旧扩展,并正常运行。

To put it in plain English, I suffer with legacy code.

用通俗易懂的英语来表达,我受制于遗留代码。

First, let me tell you about the bright stack. This extension is meant to run in one of the most important e-commerce platforms, Magento. But Magento released a new version of the platform (2.0), with lots of improvements, implementing most of the good practices, backend developers were hoping to see.

首先,让我告诉您有关明亮堆栈的信息。 此扩展旨在在最重要的电子商务平台之一Magento中运行 。 但是Magento发布了该平台的新版本(2.0),进行了许多改进,实现了大多数优秀实践,后端开发人员希望看到这一点。

For me, it would be great if the extension was made for the latest Magento version, but the extension was developed for the previous version (1.9). An archaic one, lots of times unnecessarily complex, cumbersome and full of intricate xml files. But it does the job. Oh, boy, it does!

对我而言,如果扩展是针对最新的Magento版本进行的,那将是很棒的,但是该扩展是针对先前版本(1.9)开发的。 一个古老的文件,很多时候都不必要地复杂,繁琐并且充满了复杂的xml文件。 但这确实起作用。 哦,男孩,确实如此!

Besides that, the extension, as you may be expecting, is written in PHP, the language everyone loves to hate.

除此之外,正如您所期望的那样,该扩展是用PHP编写的,PHP是每个人都喜欢讨厌的语言。

Although PHP has gained lots of improvements with the latest 7.x version, Magento 1.9 does not support it and I’m forced into working with old PHP versions. Thus, I’m unable to play with all the new stuff. To finish explaining the scenario, there is not a single piece of test. Neither I, nor anyone in the team, was part of the original extension design and development. In the beginning we were kind of lost, most of the time.

尽管PHP在最新的7.x版本中获得了很多改进,但是Magento 1.9不支持它,因此我不得不使用旧PHP版本。 因此,我无法使用所有新内容。 为了完成对场景的解释,没有一项测试。 我和团队中的任何人都不是原始扩展设计和开发的一部分。 一开始,大多数时候我们都迷路了。

圈内奔跑和尖叫不是一种选择 (Running in circles and screaming is not an option)

When you start working in a project like this, you feel like those guys playing the last song in the Titanic. Everything is falling apart, but you keep doing your job.

当您开始在这样的项目中工作时,您会感觉像是那些家伙正在播放《泰坦尼克号》中的最后一首歌。 一切都崩溃了,但是您继续做自己的工作。

The clients keep opening tickets, the problems never seem to be solved at all. Your boss ask for new features. You start blaming the platform, the code base (someone you don’t even know wrote and you start hating them for that). At this point you are deep down in the legacy hell.

客户不断开票,这些问题似乎根本没有解决。 您的老板要求新功能。 您开始责怪平台和代码库(甚至您都不认识的人都开始为此而恨之入骨)。 在这一点上,您已经陷入了地狱的深渊。

There are actually two things you can do here. The first one is to update your Linkedin profile, put a nice photo, tell a nice story about how good you are and start sending resumés. Looking for a new job, a job without legacy code (spoiler alert, this place does not exist) or you can stop, breath and make a plan to deal with that thing.

您实际上可以在这里做两件事。 第一个是更新您的Linkedin个人资料,贴上一张漂亮的照片,讲述一个关于自己的好故事,然后开始发送简历。 寻找新的工作,没有遗留代码工作(扰流警报,这个地方存在),或者你可以停止,呼吸和制定一个计划,以对付那个东西。

开始做一些事情 (Start doing something about it)

If you are in a scenario like this, you should start acting fast. If your code base is not under a source code version system (git, please) and your team does not use a tool to manage the tasks, maybe you should think about that Linkedin stuff. But if you have the minimum, start with the basic, remove the cruft.

如果您处于这种情况,则应该开始快速采取行动。 如果您的代码库不在源代码版本系统(请使用git)下,并且您的团队未使用工具来管理任务,则也许您应该考虑使用Linkedin。 但是,如果您有最低要求,请从基本开始,删除残留物 。

I’m pretty sure that there is deprecated code, code that is not reached at all, and code that was left behind. Just taking space and making things look like a lot worse than it actually is. Give that code a good look, tinker with it, fill it with break points and start getting rid of what is not being used. Make sure you are not doing anything stupid here and don’t exaggerate. Remember, there is no test yet, so only get rid of those methods you are completely sure are useless.

我很确定有不推荐使用的代码,根本没有到达的代码以及留下的代码。 仅占用空间并使事情看起来比实际情况差很多。 给该代码一个好的外观,修改它,用断点填充它并开始摆脱不被使用的内容。 确保您在这里没有做任何愚蠢的事情,并且不要夸大其词。 记住,还没有测试,所以只有摆脱那些完全确定没有用的方法。

Doing that, you’ll be more comfortable with your code base and you will probably feel more confident. After that, you will still have unnecessary code, but almost everything you have there has meaning, or is useful.

这样做,您将对代码库更加满意,并且可能会感到更加自信。 在那之后,您仍然会拥有不必要的代码,但是您在那里拥有的几乎所有东西都具有意义或有用。

The next step is to think about tests. There are several ways to test software. You can do unitary tests, integration tests, system tests, stress tests, and plenty more. They are great and should be used in the right time. But remember, you are in a critical moment here and you should start with what is really important. Functional tests.

下一步是考虑测试。 有几种测试软件的方法。 您可以进行整体测试,集成测试,系统测试,压力测试等等。 它们很棒,应该在正确的时间使用。 但是请记住,您现在处于关键时刻,应该从真正重要的事情开始。 功能测试。

I’m not the most skilled tester. Far from that. I still have a lot to learn and study. But as far as I know, functional tests (for web projects, at least) are the least invasive ones. You don’t have to create mocks, stubs, fakes, dummies. Your tests are going to interact with the browser and simulate the human interaction.

我不是最熟练的测试人员。 远非如此。 我还有很多东西要学习。 但是据我所知,功能测试(至少针对Web项目)是侵入性最小的测试。 您不必创建模拟,存根,假货,假人。 您的测试将与浏览器交互并模拟人工交互。

At this point you have a code base with only the code that is needed and few tests to help you stop adding new bugs with every new feature. It is a win-win situation. Now you can stop, breath and think more calmly.

此时,您的代码库仅包含所需的代码,并且几乎没有测试可帮助您停止在每个新功能中添加新的错误。 这是双赢的局面。 现在您可以停下来,喘口气,更加冷静地思考。

接下来是什么? (What next?)

With more time, less bugs and sanity in place, you can start tackling other problems. Have you thought about continuous integration? How is your team development workflow? If you are using git (which I hope), you could start planning your branches. Create a master branch, a develop branch, add new features through feature branches, hot fix branches, and so on.

有了更多的时间,更少的错误和理智的解决方案,您就可以开始解决其他问题。 您是否考虑过持续集成? 您的团队开发工作流程如何? 如果您正在使用git(希望如此),则可以开始计划分支。 创建一个master分支,一个develop分支,通过Feature分支,Hot Fix分支等添加新功能。

How is your continuous delivery? How are your versions created? If you have to do more than “pushing a button”, maybe it is time to think about that process. How could you make it more reliable, less error prone? Does your application generate enough logs? Could you improve that? Now it is time to create a better software, now it is up to you.

您如何连续交货? 如何创建您的版本? 如果您要做的不仅仅是“按下按钮”,也许是时候考虑一​​下该过程了。 您如何使它更可靠,更不易出错? 您的应用程序是否生成足够的日志? 你能改善吗? 现在该创建一个更好的软件了,这取决于您。

而已 (That’s it)

We are still working on our legacy, trying to make it better. Although we haven’t reached the ideal scenario yet, several things have changed. Now we have only the necessary code. The workflow for that particular extension is well defined. We have functional tests in place and the deployment process is getting better.

我们仍在努力处理我们的遗产,力求使其更好。 尽管我们还没有达到理想的情况,但是有些事情已经改变。 现在,我们只有必要的代码。 该特定扩展的工作流程已明确定义。 我们已经进行了功能测试,并且部署过程越来越好。

After changing that scenario and surviving the legacy hell, our team got the task to develop a new extension to the same old Magento 1.9. Any sane person would be angry about that, but I’m thinking it is the perfect moment to do the right thing. This is the chance to make all the complaints become best practices and create a piece of software with maintainability in mind. but this is a subject for another article.

在改变了这种情况并在旧地狱中幸存下来之后,我们的团队获得了为相同的旧版Magento 1.9开发新扩展的任务。 任何理智的人都会对此感到生气,但是我认为这是做正确的事情的最佳时机。 这是使所有投诉成为最佳做法并创建具有可维护性的软件的机会。 但这是另一篇文章的主题。

翻译自: https://www.freecodecamp.org/news/few-thoughts-on-legacy-hell-e229f76529e0/

调试代码遗留

调试代码遗留_陷入遗留代码地狱吗? 这里有一些想法可以帮助您处理情况相关推荐

  1. java恋爱代码_陷入与代码的恋爱中:终生的爱情故事

    java恋爱代码 by Daragh Byrne 达拉·伯恩(Daragh Byrne) 陷入与代码的恋爱中:终生的爱情故事 (Falling in and out of love with code ...

  2. java重复代码重构_重构重复代码

    java重复代码重构 As a software engineer working on a large project, you'll likely be asked to do cleanup w ...

  3. python函数增强代码可读性_如何提高代码的可读性 学习笔记

    本文整理自 taowen 师傅在滴滴内部的分享. 1.Why 对一线开发人员来说,每天工作内容大多是在已有项目的基础上继续堆代码.当项目实在堆不动时就需要寻找收益来重构代码.既然我们的大多数时间都花在 ...

  4. 代码命名_肮脏的代码问题:通过良好的命名习惯来改善您的游戏

    代码命名 规则:每当您命名变量,函数或类时,都要询问它是否简洁 , 诚实 , 富有表现力和完整 . 说明 一贯地写好名字很难,但是阅读和理解坏名字却很难. 使用好名字意味着我们允许读者停止阅读更高级别 ...

  5. Python_代码风格_合理分解代码,提高代码可读性

    一.什么是PEP8 PEP 是 Python Enhancement Proposal 的缩写,翻译过来叫"Python 增强规范".正如我们写文章,会有句式.标点.段落格式.开头 ...

  6. mysql代码提示_聊一聊 php 代码提示

    title: 聊一聊 php 代码提示 date: 2017-8-25 15:05:49 这次我们来聊一聊 php 的代码提示, 不使用 IDE 的同学也可以瞧瞧看, PHP IDE 推荐 phpst ...

  7. excel vba编程代码大全_实战VBA代码一键提取EXCEL中的所有公式!

    有的时候,我们希望把表中的公式提取出来,进行保存! 少量,我们可以手动复制,量大,猝-- 所以我们今天就分享一下如何一键提取 用什么,VBA上吧! 还是老规矩,我们先看一下动画效果 动画效果 制作教程 ...

  8. angular代码规范_同样写代码,为何差距越来越大?

    前端应用越来越复杂,技术框架不断变化,如何成为一位优秀的前端工程师,应对更大的挑战?今天,阿里前端技术专家会影结合实际工作经验,沉淀了五项重要方法,希望能对你的职业发展.团队协作有所启发.来源 | 阿 ...

  9. ios静态库和代码同名_使用一个代码库开始制作NativeScript iOS和Android应用程序

    ios静态库和代码同名 Users can choose whatever operating system they prefer, but every operating system use d ...

最新文章

  1. [Vue CLI 3] 插件编写实战和源码分析
  2. 4.2 Tensorflow笔记:池化函数
  3. (19)修改PDE PTE 的RW位使物理页可读写
  4. php如何获取网址中的参数
  5. k8s包管理器helm_是时候使用Helm了:Helm, Kubernetes的包管理工具
  6. 图例解析四大UML关系图使用
  7. 关于linux低端内存
  8. 关于JeeSite框架Shiro序列化漏洞修复解决方法
  9. 基于R语言地理加权回归、主成分分析、判别分析等空间异质性数据分析
  10. struct Lnode *next
  11. STM32使用外部SRAM扩展内存,自动在SRAM上分配内存空间的方法
  12. 各层电子数排布规则_核外电子的排布及其规律,亨利·莫塞莱和查尔斯·巴克拉最先发现电子层...
  13. Axure-RP8 介绍
  14. 1330: PIPI的乐高积木
  15. 微服务启动报错:Shutting down DiscoveryClient
  16. Unity 中遮挡层级
  17. 推荐系统(八)FNN模型(FM+MLP=FNN)
  18. 使用poi解析Excel
  19. 清华大学计算机崔勇,崔勇 简历 - 名人简历
  20. 网络云存储技术Windows server 2012 (项目十 基于NTFS权限(ADLP原则)的文件共享服务的配置与管理)

热门文章

  1. IDEA 格式化代码Reform Code快捷键无效
  2. mac tomcat https
  3. svn服务器发生变更,如何切换
  4. 程序员也想改 Lottie 动画?是的!
  5. ubuntu搭建svn、git遇到的问题及解决办法
  6. 新疆弃光量下降14% 弃光问题仍然难解
  7. 数据库抽取,生成CSV文件导出,CSVUtils工具类
  8. java静态/动态成员变量、初始化块,父类/子类构造函数执行顺序问题
  9. 山寨c 标准库中的getline 函数
  10. 提权巧用RAR.EXE