返回主题:契约式设计

此卡片不在当前主题的阅读序列中,可返回主题继续阅读。

知识卡片

普通读书笔记卡 · 1971.o.1.b.1.a.1.d

代码行为与名称须对齐

理解等级:中级

可执行代码和测试能确认实际行为,但名称与组织方式仍可能讲错模型:方法名可能含糊或过时,测试变量名也可能误导。要让代码承担设计沟通,需持续对齐行为、设计意图和表达它们的名称,并尽量使用需求、开发者及领域专家共享的语言。运行正确本身不能证明读者会正确理解设计。参见 [[共同语言贯穿交付媒介]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • 原书第02章|Documents and Diagrams · 查看原书依据

      But a method name can be ambiguous, misleading, or out of date compared to the internals of the method. The assertions in a test are rigorous, but the story told by variable names and the organization of the code is not. Good programming style keeps this connection as direct as possible, but it is still an exercise in self-discipline. It takes fastidiousness to write code that doesn't just do the right thing but also says the right thing.

    参考来源

    - 位置:《Domain-Driven Design: Tackling Complexity in the Heart of Software》第20章《原书第02章|Documents and Diagrams》(源文件:_epub-src/0321125215_ch02lev1sec4.html) - 结论依据:原文区分代码的确定行为与名称所传达的含义,指出方法名和测试叙述可能失准,要求代码与需求、专家交流使用同一语言。 - 原始内容(本节倒数第三段):But a method name can be ambiguous, misleading, or out of date compared to the internals of the method. The assertions in a test are rigorous, but the story told by variable names and the organization of the code is not. Good programming style keeps this connection as direct as possible, but it is still an exercise in self-discipline. It takes fastidiousness to write code that doesn't just do the right thing but also says the right thing. - 原始内容(本节末段):Aligning the behavior, intent, and message of code using current standard technology requires discipline and a certain way of thinking about design (discussed at length in Part III ). To communicate effectively, the code must be based on the same language used to write the requirements—the same language that the developers speak with each other and with domain experts. (破折号处原 EPUB 编码为异常 U+0097;此处仅规范该字符,未增删句意。)