转载-代码的马斯洛金字塔

科技爱好者周刊(第 156 期):显卡缺货与异业竞争看到的关于代码的马斯洛金字塔这种说法;搬运过来方便自己随时阅读;
原文是代码的马斯洛金字塔
内容如下:
As in Maslow’s pyramid, each layer requires the previous one. It is useless for code that is charging the wrong customer to be readable.
Code should be:

  • Correct: does the code do what it’s supposed to? Does it handle edge cases? Is it adequately tested to make sure that it stays correct even when other engineers modify it? Is it performant enough for this use case?
  • Secure: does the code have vulnerabilities? Is the data stored safely? Is personal identification information (PII) handled correctly? Could the code be used to induce a DOS? Is input validation comprehensive enough?
  • Readable: is the code easy to read and comprehend? Does it make clear what the business requirements are (code is written to be read by a human, not by a computer)? Are tests concise enough? Are variables, functions and classes named appropriately? Do the domain models cleanly map the real world to reduce cognitive load? Does it use consistent coding convention?
  • Elegant: does the code leverage well-known patterns? Does it achieve what it needs to do without sacrificing simplicity and conciseness? Would you be excited to work in this code? Would you be proud of this code?
  • Altruist: does the code leave the codebase better than what it was? Does it inspire other engineers to improve their code as well? Is it cleaning up unused code, improving documentation, introducing better patterns through small-scale refactoring?
    Update Feb 18th: there’s some great comments on reddit about this. I removed the notion of large refactor because I think small refactors have a higher probability of success. I also added a comment about why layering matters.
    周刊中翻译以及配图为:
    马斯洛金字塔是美国心理学家马斯洛提出的一个心理学模型,认为人类的心理需求从下往上分为5个层次,一旦实现了下层的需求,就会追求上一层的需求。
    在这里插入图片描述
    这五个层次依次是:生理需求、安全需求、社交需求、尊严需求、自我实现。
    代码质量也可以用金字塔模型表示,从下往上有五个层次。
    在这里插入图片描述
    (1)第一层:正确(Correct)
    代码是否执行预期的工作?是否考虑了边缘情况?是否经过充分测试?是否有可维护性?是否有可接受的性能?
    (2)第二层:安全(Secure)
    代码是否存在漏洞?数据是否安全存储?个人识别信息(PII)是否得到正确处理?是否对用户的输入进行了全面的验证?
    (3)第三层:可读(Readable)
    代码是否易于阅读和理解?测试足够简洁吗?变量、函数、类的名称是否适当?使用领域模型是否可以清晰地映射现实世界,以减少认知负担?是否使用一致的编码风格约定?
    (4)第四层:优雅(Elegant)
    代码是否利用了众所周知的编程模式?能否更简单简洁地实现所需的功能?你会为编写这些代码感到兴奋吗?你为这些代码感到骄傲吗?
    (5)第五层:利他主义(Altruist)
    别人能否从这些代码学到东西?这些代码是否会激励其他工程师进行改进?它是否会让世界变成一个更好的地方?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值