TDD has subsumed YAGNI in a way. If you do TDD properly, that is, only write those tests that result in required functionality, then develop the simplest code to pass the test, then you are following the YAGNI principle by default. In my experience, it is only when I get outside the TDD box and start writing code before tests, tests for things that I don't really need, or code that is more than the simplest possible way to pass the test that I violate YAGNI.
In my experience the latter is my most common faux pas when doing TDD -- I tend to jump ahead and start writing code to pass the next test. That often results in me compromising the remaining tests by having a preconceived idea based on my code rather than the requirements of what needs to be tested.
Yagni 和 KISS(保持简单,愚蠢)本质上是相同的原理。 不幸的是,我看到 KISS 被提及的次数和我看到“yagni”的次数一样多。
在我所在的领域,项目延迟和失败的最常见原因是不必要的组件执行不力,所以我同意你的基本观点。
Yagni and KISS (keep it simple, stupid) are essentially the same principle. Unfortunately, I see KISS mentioned about as often as I see "yagni".
In my part of the wilderness, the most common cause of project delays and failures is poor execution of unnecessary components, so I agree with your basic sentiment.
The freedom to change drives YAGNI. In a waterfall project, the mantra is control scope. Scope is controlled by establishing a contract with the customer. Consequently, the customer stuffs all they can think of in the scope document knowing that changes to scope will be difficult once the contract has been signed. As a result, you end up with applications that has a laundry list of features, not a set of features that have value.
With an agile project, the product owner builds a prioritized product backlog. The development team builds features based on priority i.e., value. As a result, the most important stuff get built first. You end up with an application that has features that are valued by the users. The stuff that is not important falls off the list or doesn't get done. That is YAGNI.
While YAGNI is not a practice, it is a result of the prioritized backlog list. The business partner values the flexibility afforded the business given that they can change and reprioritized the product backlog from iteration to iteration. It is enough to explain that YAGNI is the benefit gained when we readily accept change, even late in the process.
The problem I find is that people tend to bucket even writing factories, using DI containers (unless you've already have that in your codebase) under YAGNI. I agree with JB King there. For many people I've worked with YAGNI seems to be the license to cut corners / to write sloppy code.
For example, I was writing a PinPad API for abstracting multiple models/manufacturers' PINPad. I found unless I've the overall structure, I can't write even my Unit Tests. May be I'm not a very seasoned practioner of TDD. I'm sure there'll be differing opinions on whether what I did is YAGNI or not.
I don't see YAGNI as the opposite of quick-and-dirty, really. It is doing just what is needed and no more and not planning like the software someone writes has to last 50 years. It may come rarely because there aren't really that many questions to ask around it, at least to my mind. Similar to the "don't repeat yourself" and "keep it simple, stupid" rules that become common but aren't necessarily dissected and analyzed in 101 ways. Some things are simple enough that it is usually gotten soon after doing a little practice. Some things get developed behind the scenes and if you turn around and look you may notice them may be another way to state things.
发布评论
评论(6)
TDD 在某种程度上包含了 YAGNI。 如果你正确地进行了 TDD,即只编写那些能够实现所需功能的测试,然后开发最简单的代码来通过测试,那么你就默认遵循了 YAGNI 原则。 根据我的经验,只有当我走出 TDD 框框并开始在测试之前编写代码、测试我真正不需要的东西,或者代码不仅仅是通过测试的最简单方法时,我才违反了 YAGNI 。
根据我的经验,后者是我在进行 TDD 时最常见的失误——我倾向于跳到前面并开始编写代码以通过下一个测试。 这通常会导致我根据我的代码而不是需要测试的要求产生先入为主的想法,从而损害剩余的测试。
YMMV。
TDD has subsumed YAGNI in a way. If you do TDD properly, that is, only write those tests that result in required functionality, then develop the simplest code to pass the test, then you are following the YAGNI principle by default. In my experience, it is only when I get outside the TDD box and start writing code before tests, tests for things that I don't really need, or code that is more than the simplest possible way to pass the test that I violate YAGNI.
In my experience the latter is my most common faux pas when doing TDD -- I tend to jump ahead and start writing code to pass the next test. That often results in me compromising the remaining tests by having a preconceived idea based on my code rather than the requirements of what needs to be tested.
YMMV.
Yagni 和 KISS(保持简单,愚蠢)本质上是相同的原理。 不幸的是,我看到 KISS 被提及的次数和我看到“yagni”的次数一样多。
在我所在的领域,项目延迟和失败的最常见原因是不必要的组件执行不力,所以我同意你的基本观点。
Yagni and KISS (keep it simple, stupid) are essentially the same principle. Unfortunately, I see KISS mentioned about as often as I see "yagni".
In my part of the wilderness, the most common cause of project delays and failures is poor execution of unnecessary components, so I agree with your basic sentiment.
变革的自由推动着 YAGNI。 在瀑布项目中,口头禅是控制范围。 范围通过与客户签订合同来控制。 因此,客户将他们能想到的所有内容都填入范围文档中,因为他们知道一旦合同签署,范围的更改将变得困难。 结果,您最终得到的应用程序具有一系列功能,而不是一组有价值的功能。
通过敏捷项目,产品负责人可以构建优先的产品待办事项列表。 开发团队根据优先级(即价值)构建功能。 结果,最重要的东西首先被构建。 您最终会得到一个具有用户重视的功能的应用程序。 不重要的事情从清单上消失或者没有完成。 那是亚格尼。
虽然 YAGNI 不是一种实践,但它是优先积压列表的结果。 业务合作伙伴重视为业务提供的灵活性,因为他们可以在迭代之间更改产品待办事项并重新确定其优先级。 这足以解释 YAGNI 是当我们欣然接受改变时所获得的好处,即使是在过程的后期。
The freedom to change drives YAGNI. In a waterfall project, the mantra is control scope. Scope is controlled by establishing a contract with the customer. Consequently, the customer stuffs all they can think of in the scope document knowing that changes to scope will be difficult once the contract has been signed. As a result, you end up with applications that has a laundry list of features, not a set of features that have value.
With an agile project, the product owner builds a prioritized product backlog. The development team builds features based on priority i.e., value. As a result, the most important stuff get built first. You end up with an application that has features that are valued by the users. The stuff that is not important falls off the list or doesn't get done. That is YAGNI.
While YAGNI is not a practice, it is a result of the prioritized backlog list. The business partner values the flexibility afforded the business given that they can change and reprioritized the product backlog from iteration to iteration. It is enough to explain that YAGNI is the benefit gained when we readily accept change, even late in the process.
我看过很多关于 SO 的帖子,引用了过早优化,这是 yagni 的一种形式,或者至少是 ydniy (你还不需要它)。
I have seen a lot of posts on SO referencing premature optimization which is a form of yagni, or at least ydniy (you don't need it yet).
我发现的问题是,人们甚至倾向于在 YAGNI 下使用 DI 容器(除非您的代码库中已有该容器)来编写工厂。 我同意 JB King 的观点。 对于许多与我一起工作过的人来说,YAGNI 似乎是偷工减料/编写草率代码的许可。
例如,我正在编写一个 PinPad API,用于抽象多个型号/制造商的 PINPad。 我发现除非我有整体结构,否则我什至无法编写单元测试。 可能我不是一个经验丰富的 TDD 实践者。 我确信对于我所做的是否是YAGNI,会有不同的意见。
The problem I find is that people tend to bucket even writing factories, using DI containers (unless you've already have that in your codebase) under YAGNI. I agree with JB King there. For many people I've worked with YAGNI seems to be the license to cut corners / to write sloppy code.
For example, I was writing a PinPad API for abstracting multiple models/manufacturers' PINPad. I found unless I've the overall structure, I can't write even my Unit Tests. May be I'm not a very seasoned practioner of TDD. I'm sure there'll be differing opinions on whether what I did is YAGNI or not.
我真的不认为 YAGNI 是“快速而肮脏”的对立面。 它只是做需要做的事情,而不是像某人编写的软件必须持续 50 年那样进行规划。 这种情况可能很少发生,因为至少在我看来,并没有太多问题要问。 类似于“不要重复自己”和“保持简单、愚蠢”的规则,这些规则变得很常见,但不一定以 101 种方式进行剖析和分析。 有些事情很简单,通常经过一点练习后很快就能掌握。 有些事情是在幕后发展的,如果你回头看,你可能会注意到它们可能是陈述事情的另一种方式。
I don't see YAGNI as the opposite of quick-and-dirty, really. It is doing just what is needed and no more and not planning like the software someone writes has to last 50 years. It may come rarely because there aren't really that many questions to ask around it, at least to my mind. Similar to the "don't repeat yourself" and "keep it simple, stupid" rules that become common but aren't necessarily dissected and analyzed in 101 ways. Some things are simple enough that it is usually gotten soon after doing a little practice. Some things get developed behind the scenes and if you turn around and look you may notice them may be another way to state things.