Please enable Javascript to view the contents

奇文共赏: 12 年没有版本控制的 PHP 代码,产生两千万美元年收入

 ·  ☕ 3 分钟

赚钱的烂代码,要不要重构?今天看到网友分享的一个项目,看描述真的是很烂。但是问题来了,为什么这么烂的代码,还年入两千万美刀?

代码屎山

奇文共赏: 12 年没有版本控制的 PHP 代码,产生两千万美元年收入 - V2EX

Ask HN: 继承了我见过的最差的代码和技术团队,怎么办?
529 点赞 | 660 评论

我必须找到一个策略来解决这个开发团队的问题,不是直接管理团队。现状如下。

  • 这个代码每年产生超过 2000 万美元的收入
  • 运行在 PHP 上
  • 已经在生产环境直接开发了 12 年,没有源代码控制(都是这种 index-new_2021-test-john_v2.php )。
  • 没有使用 composer 或任何依赖管理。都是 require_once 。
  • 不使用任何框架
  • 路由管理完全是在 NGInX 中重写的( NGInX 的配置大约是 10,000 行)。
  • 这些年只往上堆代码,没有任何代码被删除。我想这是因为直接在生产环境开发,删东西太冒险了。
  • 数据库结构也是一团糟,没有迁移,等等。当添加一个列时,由于数据量大,他们会建一个新的表,然后用 join 。
  • JS 和 CSS 也是如此。多个版本的 jQuery 互相打架,取决于你在哪个页面,甚至在同一个页面也存在。
  • 当然没有 MVC 模式,或者什么模式。没有模板库。这是 PHP2003 的风格。
  • 在很多地方,我看到像是 Controller 一样的文件,向它自己的 rest API 发出 curl 请求(通过域名,而不是 localhost )做 oauth 授权,等等。只是为了获得菜单项或产品列表…
  • 没有缓存(但有 memcached ,但只用于 Session…)
  • 团队有 3 个人,很初级。一个后端,一个前端,一个 iOS/android 。对变化有很强的抵触。
  • 生产力很差,这是可以理解的。乱七八糟的东西实在是太多了,根本没办法做新东西。

业务部门有相当积极的规划,因为管理层和总部没有真正了解这些代码上的障碍。而且在 COVID 之后,预算真的很紧张。

我知道应该全面重写,但如何抉择呢?

原文:Ask HN: Inherited the worst code and tech team I have ever seen. How to fix it? | Hacker News

Ask HN: Inherited the worst code and tech team I have ever seen. How to fix it?
531 points by whattodochange 2 days ago | hide | past | favorite | 662 comments
I have to find a strategy to fix this development team without managing them directly. Here is an overview:

  • this code generates more than 20 million dollars a year of revenue

  • it runs on PHP

  • it has been developed for 12 years directly on production with no source control ( hello index-new_2021-test-john_v2.php )

  • it doesn’t use composer or any dependency management. It’s all require_once.

  • it doesn’t use any framework

  • the routing is managed exclusively as rewrites in NGInX ( the NGInX config is around 10,000 lines )

  • no code has ever been deleted. Things are just added . I gather the reason for that is because it was developed on production directly and deleting things is too risky.

  • the database structure is the same mess, no migrations, etc… When adding a column, because of the volume of data, they add a new table with a join.

  • JS and CSS is the same. Multiple versions of jQuery fighting each other depending on which page you are or even on the same page.

  • no MVC pattern of course, or whatever pattern. No templating library. It’s PHP 2003 style.

  • In many places I see controllers like files making curl requests to its own rest API (via domain name, not localhost) doing oauth authorizations, etc… Just to get the menu items or list of products…

  • no caching ( but there is memcached but only used for sessions …)

  • team is 3 people, quite junior. One backend, one front, one iOS/android. Resistance to change is huge.

  • productivity is abysmal which is understandable. The mess is just too huge to be able to build anything.

This business unit has a pretty aggressive roadmap as management and HQ has no real understanding of these blockers. And post COVID, budget is really tight.

I know a full rewrite is necessary, but how to balance it?

分享

码中人
作者
码中人
Web Developer