首页 时政热点 科技头条 智能AI 安全攻防 数码硬件 开发者生态 汽车 游戏 社会热点 开源推荐 医疗健康 归档 标签 关于

可以对功能标志进行硬编码(2025)

2026-09-02 1 阅读 约4分钟阅读 biscuits1
分享:
字号:
功能标志(或切换开关)通常用于控制产品中新功能的可见性。 There are a few different ways to implement them, but the most talked and marketed about is to use feature flag management software. The simplest way of course is to hardcode them, though it’s the least written about.虽然功能标志管理软件功能强大,但它们也是复杂性和风险的根源。 The blogspam marketing behind them is so strong, that admitting they’re unnecessary feels like confessing to technological impotence.我们说服自己,我们不仅仅需要几个功能标志,我们需要扩展到数千个功能标志。不仅如此,我们绝对需要在运行时更改某个功能,而且我们绝对必须在没有部署、没有重新启动、没有缓存刷新、没有数据库迁移、没有审查、没有测试的情况下进行更改,因为业务正在火热进行中,唯一的方法就是更改主页上按钮的颜色。 The only flags that the capabilities of such a system should bring up are of the #ff0000 variety.从架构的角度来看,它们只不过是美化的 if 语句,在单独的进程中进行管理。通常需要自己的基础设施、托管、监控以及随之而来的所有责任。从开发生命周期的角度来看,它们引入了非确定性行为,并使代码推理变得更加困难。 Long lived feature flags, though initially well intentioned, lead to technical debt that ossifies the codebase;硬编码标志确实存在这种风险,但更容易查看和管理。从安全角度来看,它们是一种负担,因为攻击或漏洞的范围现在已经增加。无论如何,在任何软件系统中添加更多移动部件都应该经过仔细审查,看看它是否确实有必要,以及它带来的风险是否值得解决问题。硬编码的功能标志消除了其中许多问题;它们简单、可靠且安全。 They are the most boring way to do it, and that’s why they’re the best way to do it. Simply start with a simple JSON file, read it in at application startup, and use it to control the visibility of features. Keep on top of the flags, remove them when they’re no longer needed.如果它们活得太久,请将它们设为实际行为并删除标记。通过正常的开发过程更改值,对其进行审查、测试和部署。对于大多数团队和产品来说,这通常已经足够好了,并且会有很多里程。当团队实际上需要在运行时大规模更改某个功能时,就像 SPA 中的状态管理一样,他们会知道自己需要它。过早的优化不是正确的出路。它的设计很糟糕,工程也很糟糕,而且只适用于技术会议上销售发言人询问是否有人在使用它们时的短暂自我庆幸时刻。
这篇文章对您有帮助吗?

订阅66必读

每日精选科技资讯,直达你的邮箱