Live data from Hacker News

Yagni (2015)

martinfowler.com

21–30 of 61 posts

Re: Yagni (2015)

#21
I think coherency of implementation is a lot more important than YAGNI. For example:

  class Car:

      def honk(self):
          print('Honk!')
Cool, now we have a car, but it only honks. But we only needed it to honk, so that's fine.

  class RoadTrip:

      def __init__(self, car, destination):
          self.car = car

      def go(self):
          self.car.start()
          self.car.drive_to(destination)
Oh no, we built a car but it does nothing that a car does. Let's add this functionality.

  class Car:

      def __init__(self):
          self.started = False
          self.gps = []
          self.location = cool_app.get_current_location()

      def honk(self):
          print('Honk!')

      def start(self):
          self.started = True

      @property
      def location(self):
          return self.gps[-1]

      @location.setter
      def location(self, new_location):
          self.gps.append(location)

      def drive_to(self, location):
          self.location = location
Super easy. Except a different user of our library implemented this functionality already for a different reason, but in a different way.

  class CarEngine:

      def __init__(self, car):
          self.car = car
          self.started = False

      def start(self):
          if self.started:
              raise Exception('Already started!')
          self.started = True

      def turn_off(self):
          if not self.started:
              raise Exception('Not started!')
          self.started = False

  class CarGasTank(self, car):

      def __init__(self, gallons):
          self.car = car
          self.capacity = gallons
          self.level = gallons

      @property
      def empty(self):
          return self.level == 0

  class MotorCar:

      def __init__(self, engine, gas_tank, mpg, location):
          self.engine = engine
          self.gas_tank = gas_tank
          self.location = location
          self.mpg = mpg

      @property
      def started(self):
          return self.engine.started

      def start(self):
          return self.engine.start()

      def drive_to(self, location):
          distance = location - self.location
          fuel_required = distance / self.mpg
          if fuel_required > self.gas_tank.gallons:
              raise Exception('Not enough gas!')
          self.gas_tank.gallons -= fuel_required
          self.location = location
I've lost count of the number of times I've seen stuff like this. Sometimes the original implementation is in a different library that's hard to change. Sometimes other code rely on specific details of the original implementation so changing it requires changing that code too. Sometimes additions seem "out of scope" so they are actively pushed to dependencies.

It might feel like this is a process problem -- like there should have been better upfront design or communication -- but these "failure cases" are actually the success cases for code. You want code to rely on your libraries. You want to consider all users of your libraries when making changes.

The problem is actually YAGNI, because that mentality encourages us to churn out big, incoherent bags of functions when we should be thinking about code responsibilities and designing whole systems.

You can see this in action with JavaScript most infamously. Its standard library is extremely YAGNI, and it led to whole new programming languages being built on top of it because it was so anemic. The complexity has to live somewhere, and if you don't deal with it in a coherent and orthogonal way, someone else will have to deal with it and their options will be a lot more limited than yours.

Following simple mantras like DRY, YAGNI, and whatever else fits on a poster is the surest way to mess up your design. It requires thoughtfulness and experience, and there are no shortcuts.

Re: Yagni (2015)

#22
post #20

YAGNI is a sad example of the state of software engineering: our field follows rules of thumb, based on anecdotes as evidence. When will experimental validation become best practice, like in the other engineering disciplines?

There is a whole field of study--what was originally called software engineering--that does quantitative, empirical analysis of software development. Its practitioners are often called by managers entering into large projects that have tight quality requirements so that the optimal choices can be made in terms of tooling and techniques. (For example, large-scale automotive software, where there is far less tolerance for error than in IT.)

Re: Yagni (2015)

#23
Everyone likes to pretend they can predict the future for a while, to the point where they will stop at nothing to make it conform to their predictions. Then comes the part where they will defend their choices to death, no matter how much evidence to the contrary is piling up. Once you start seeing the entire chain of consequences, it becomes easier to discipline yourself; it's a process of growing up and taking responsibility.

Re: Yagni (2015)

#24

The problem I've seen when yagni is applied is not building something now leads to a costly data migration down the road when you actually do need it. I run a site that stores audio files. For the first half of its life, it simply stored the URL of the file on S3. I could have used objects representing audio assets with metadata to store the reference, but I didn't think I'd need it. When I was building another featu…

What if you'd never built the feature that needed the metadata/reference? What if you had abandoned your project? How long did you run with the much simpler, non abstract S3 location and what did getting to launch sooner buy you?

Re: Yagni (2015)

#25
post #16

Like any generalization, it's not always true. Boss decides to add y,x,z options "just in case"? - YAGNI Engineer wants to get the datamodel correct up front to avoid costly rework and data migration in the future? - Not YAGNI Fowler fortunately states this distinction: "Yagni only applies to capabilities built into the software to support a presumptive feature, it does not apply to effort to make the software easier…

That's a bit of a cop-out, though. How much software development isn't either implementing the actual features or making the software easier to modify? This one is a bit like the TDD advocacy that says you shouldn't need to do much design work up-front because you can let the tests drive the design along with everything else.* *Except for the part where you refactor your code, which by definition shouldn't be changin…

> How much software development isn't either implementing the actual features or making the software easier to modify?

The key is the adjective, presumptive. YAGNI is about features that aren't needed now and it's uncertain whether they ever will be.

Re: Yagni (2015)

#26
post #16

Like any generalization, it's not always true. Boss decides to add y,x,z options "just in case"? - YAGNI Engineer wants to get the datamodel correct up front to avoid costly rework and data migration in the future? - Not YAGNI Fowler fortunately states this distinction: "Yagni only applies to capabilities built into the software to support a presumptive feature, it does not apply to effort to make the software easier…

That's a bit of a cop-out, though. How much software development isn't either implementing the actual features or making the software easier to modify? This one is a bit like the TDD advocacy that says you shouldn't need to do much design work up-front because you can let the tests drive the design along with everything else.* *Except for the part where you refactor your code, which by definition shouldn't be changin…

I always thought tests were supposed to make refactoring easy since they ensure correctness. In practice I've only seen that a couple of times since the tests usually end up tightly coupled to the implementation.

Re: Yagni (2015)

#27
post #20

YAGNI is a sad example of the state of software engineering: our field follows rules of thumb, based on anecdotes as evidence. When will experimental validation become best practice, like in the other engineering disciplines?

There is a whole field of study--what was originally called software engineering--that does quantitative, empirical analysis of software development. Its practitioners are often called by managers entering into large projects that have tight quality requirements so that the optimal choices can be made in terms of tooling and techniques. (For example, large-scale automotive software, where there is far less tolerance…

Do you have some pointers to important papers of this field of study?

Re: Yagni (2015)

#28
post #24

The problem I've seen when yagni is applied is not building something now leads to a costly data migration down the road when you actually do need it. I run a site that stores audio files. For the first half of its life, it simply stored the URL of the file on S3. I could have used objects representing audio assets with metadata to store the reference, but I didn't think I'd need it. When I was building another featu…

What if you'd never built the feature that needed the metadata/reference? What if you had abandoned your project? How long did you run with the much simpler, non abstract S3 location and what did getting to launch sooner buy you?

1. The new feature increased the reliability of a user onboarding function. If I hadn't built it, I likely would not have remained in business. 2. The company would go bankrupt? I don't see your point. 3. One and a half years. It didn't get me anything, because I didn't plan for the added metadata until about nine months in. If the question is "what did the nine months between when you came up with the idea and when you were forced to build it get you?" the answer is "a world of hurt." At the time, the cost of migrating was low. When my users 100xed, the cost of migrating had increased over a thousand-fold.

Re: Yagni (2015)

#29

The problem I've seen when yagni is applied is not building something now leads to a costly data migration down the road when you actually do need it. I run a site that stores audio files. For the first half of its life, it simply stored the URL of the file on S3. I could have used objects representing audio assets with metadata to store the reference, but I didn't think I'd need it. When I was building another featu…

But what if you built out all the meta data but did it wrong, then you'd have to migrate from one complex model to another which is usually more difficult then migrating from a simple one to a complex one.

I built the same thing I'd planned originally, so the point is moot. YAGNI does nothing to stop you from misunderstanding the problem. And in the case of my problem, the metadata was fresh anyway. Generating it from scratch would have the same migration cost, but all the original tooling existed so I wouldn't be building the feature from scratch.

If the point is "what if the whole concept was wrong?" then sure, you got me. But the point is that I _did_ follow a YAGNI mindset and paid a considerable cost. Even if I had built the wrong thing, that doesn't negate the fact that technical debt had accumulated and prevented me from doing the thing I actually needed to do.

Re: Yagni (2015)

#30
post #16

Like any generalization, it's not always true. Boss decides to add y,x,z options "just in case"? - YAGNI Engineer wants to get the datamodel correct up front to avoid costly rework and data migration in the future? - Not YAGNI Fowler fortunately states this distinction: "Yagni only applies to capabilities built into the software to support a presumptive feature, it does not apply to effort to make the software easier…

Engineer wants to get the datamodel correct up front to avoid costly rework and data migration in the future? - Not YAGNI

The key here is avoid costly rework. The counterpart to YAGNI, is Avoid Painting Yourself Into A Corner. APYIAC. Actually, that is first and foremost, and YAGNI is secondary. How do we know this? Because we know change is universal and unavoidable. Planning as if change doesn't and will never occur is like planning without acknowledging weather.

Post reply on HN