Why old rookies like code refactoring

"Flowers will bloom again, and people will never be young again", everyone, if you are given another chance, will you still choose to be a code farmer?

"This year's flower is better than last year's red, but it's a pity that next year's flower will be better." Everyone, how much do you expect from the career of a code farmer?

"Look at the flowers on the tree today, not the flowers on the branches last year." Everyone, have you ever thought: If you had the current technology and salary a few years ago, would it be different to face life and talk about girlfriends? Woolen cloth...

alright! Enough talking, let’s talk about the main topic: Why do old rookies like code refactoring!

Digging on the shit mountain

Let me share with you the popular "planting flowers in the garden" in recent months:

222213.jpg

小朋友们准备开始
在小小的花园里面   ~ 挖呀挖呀挖 ~ 种小小的种子   ~ 开小小的花
在大大的花园里面   ~ 挖呀挖呀挖 ~ 种大大的种子   ~ 开大大的花
在特别大的花园里面 ~ 挖呀挖呀挖 ~ 种特别大的种子 ~ 开特别大的花
在什么样的花园里面 ~ 挖呀挖呀挖 ~ 种什么样的种子 ~ 开什么样的花
在特别大的花园里面 ~ 挖呀挖呀挖 ~ 种特别大的种子 ~ 开特别大的花

Facing the code in my project every day, I really want to adapt it:

在小小的屎山里面   ~ 挖呀挖呀挖 ~ 
在大大的屎山里面   ~ 挖呀挖呀挖 ~
在特别大的屎山里面 ~ 挖呀挖呀挖 ~
在特别大的屎山里面 ~ 挖呀挖呀挖 ~

A mountain of shit that hasn't been shoveled away is a mountain of good shit

Everyone, do you want to see Shishan's true face? ----Go to your own project to find it, haha; refactoring is not necessarily because of the shit mountain, and the shit mountain may not necessarily require refactoring

  1. As far as companies and projects are concerned, the code that can run normally and meet the needs of customers is OK, regardless of whether it is a shit mountain or a garden, the one that can help the company make money is king!

  2. The reason for the existence of Shishan is due to the early design of the project, the unreasonable structure, the irregular coding in the middle and later stages, or the lack of structure and specification at all;

  3. Many large factories or some more sophisticated companies have their own architects and quality teams, so the quality of the projects they produce will be very high. Even refactoring may be a cross-generational, technical upgrade. It is definitely not a shit mountain. Caused refactoring!

  4. Grandpas are all from grandchildren, who hasn’t had a memory of growing up, who hasn’t (written some garbage code) shit on their pants when they were young (in the primary stage); being able to accept other people’s sprays shows that you are mature , being able to find bad code in the project shows that your technology has grown;

  5. The most important point is to look at the problem from a developmental perspective, and to examine the projects many years ago with the current technology and trends. It is still necessary to be full of respect, not just complain!

optimization

What you need may be to optimize

Refactoring is not necessarily due to Shishan, it may be the transformation and upgrading of the technology itself; Shishan may not necessarily need to be refactored, maybe it only needs to be optimized for code; if the technology stack of the project is still relatively young, then the possibility we are facing It's optimization, not refactoring;

Where does that bad code come from?
  • Who used to be? You once dreamed of walking around the world with your sword, but now you are bald with a big belly and coding;
  • Colleagues who have left? People go to cool the tea, and geese go to pluck their hair;

By the way, who hasn’t grown up from a small dish? When you find that there are many unreasonable things in the project, it means that your technology has grown and improved a lot;

  • Maybe you took over an old project and the code you see is the product design of the company a few years ago
  • 可能你自己今年前写的代码,因为项目赚钱了,又要升级
  • 可能你接手了(不太讲究的)同事的代码
  • 可能就是因为赶进度,只要功能实现

如果仅仅是代码不够友好,我们需要的或许只是长期优化了...

网友谈重构

当你看到眼前的屎山会作何感想? TMD,怎么会会会有如此的代码呢,某某某真**,ε=(´ο`*)))唉? 正常,如果你没有这样的感慨,下文就不用看了,直接吐槽就行了...

看看网友回复
  • 看心情

  • 别自己找trouble

  • 又不是不能用,你领导怕成本太高吧,新项目可以用新架构

  • 除非你自己愿意花时间去重构,不然哪个老板舍得花这个钱和时间

  • 应该选择成为领导,让底下人996用新技术重构 .... 下面的更绝

  • 小伙子还年轻吧,动不动就重构

  • 代码和你 有一个能跑就行 哈哈,太多了,诸位,你会怎么想,面对糟糕的代码你会重构吗?

cg3.jpg

问题

当你发现问题时说明你用心了;当你吐槽槽糕代码时,说明你技术提升了;当你想爆粗口时说明你对美好生活是充满向往的;

那么,你的项目上可能有哪些问题呢(以前端代码为例)?

  • 技术栈过于古老
  • 架构设计不合理
  • 技术选型、规范不合理
  • 不合理的三目运算符
  • 过多的if嵌套
  • 回调地狱
  • 冗余的方法、函数
  • 全局变量混乱
  • 项目结构混乱
  • 路由管理糟糕
  • 状态数据管理混乱
  • CSS样式样式混乱
  • ..... .... 哪些该重构,哪些该优化?

sikao6.jpg

机会

“祸兮福之所倚,福兮祸之所伏”, 问题的背后往往就是机会;

路人甲: 明明就是一座屎山,又何来机会一说?有扒拉屎山的功夫,搞点新技能,搞点原创不开心吗?答案是肯定的

路人乙: 解决屎 OR 新项目搭建,会选择哪个呢? 我想脑子正常点的人应该会选择重新搭建吧!

个人觉得对于经验比较丰富的开发当然选容易的,对于经验不丰富的开发而言当然也选容易的!对于有一定基础 && 想要快速提升综合能力者,解决屎山或许别有一番滋味,未尝不是一件闻起来臭吃起来香的(臭豆腐)幸事;

  • 理解老旧项目的初始架构、设计有助于了解、理解技术发展的脉络
  • 有很多老旧项目的设计、架构是非常优秀的,值得去深入学习背后的思想
  • The whole process of refactoring is also a process of constantly examining one's own deficiencies, checking for gaps and filling gaps, and improving the shortest board
  • All technologies serve the business, and the process of refactoring is also a process of in-depth understanding of the business
  • It is a kind of happiness to have the opportunity to reconstruct. Facing many pressures is a kind of mental training. How can you see the rainbow without going through the wind and clouds? Those who succeed must be those who suffer a lot!

challenge

Behind the problems are opportunities, and opportunities are often accompanied by many challenges; in the face of refactoring, if you don’t fight for it, what is the difference (what is the value) between the old fritters and the rookie? Don’t wait until you quit the industry, and then say: “Once upon a time The opportunity for reconstruction was in front of me. I didn't cherish it. I regretted it when I lost it. The most painful thing in the world is this. If the boss can give me another chance, I will say: Refactoring! Refactoring! Refactoring!. If a deadline must be added, I hope it will be before the time set by the company!"

QQ screenshot 20230628143530.jpg

  • Time : Will the leaders and the company give enough time for in-depth refactoring, in case it is not completed as scheduled?
  • Return : Can the refactoring meet expectations, can it bring about a qualitatively improved experience, and what if the refactoring fails?
  • Ability : whether one's own ability can bear the heavy responsibility of reconstruction, and whether it has a certain ability to resist pressure
  • Game : Refactoring is also a game of resources, consider how to maximize your own interests

refactor

  • Opportunities to refactor should be earned, not given

  • There is pressure everywhere in life, and it is always overwhelming. If you dare not even think about or do a code refactoring, what about all the unsatisfactory things in your life? Just like the saying: "If a man has no dreams, what is the difference between him and a salted fish?"

QQ screenshot 20230628143731.jpg

reward

In fact, I personally feel that the most rewarding thing is the tempering of the mind; the second is the improvement of technology;

epilogue

Life is tiring enough, chat with everyone and relax! Relax! Relax! The most important thing is to drink plenty of water, eat more vegetables and fruits, and exercise moderately in hot weather! Welcome everyone to talk about your views

heshui15.jpg

Guess you like

Origin juejin.im/post/7249586143011291192