English subtitles

← 03-27 Changing Seq

dummy description

Get Embed Code
1 Language

Showing Revision 1 created 04/29/2012 by Amara Bot.

  1. Now one thing I noticed as I was writing all those test patterns is that functions like
  2. seq and alt are binary, which means if I want a sequence of 4 patterns,
  3. I have to have a sequence of (a, followed by the sequence of (b, followed by sequence of (c,d),
  4. and then I have to count the number of parens and get them right.
  5. It seems like it'd be much easier if I could just write sequence of (a, b, c, d).
  6. And we talked before about this idea of refactoring, that is changing your code
  7. to come up with a better interface that makes the program easier to use,
  8. and this looks like a good example.
  9. This would be a really convenient thing to do.
  10. Why did I write seq this way?
  11. Well, it was really convenient to be able to define sequence of (x,y)
  12. and only have to worry about exactly 2 cases.
  13. If I had done it like this, and I had to define sequence of an arbitrary number
  14. of arguments, then the definition of sequence would have been more complex.
  15. So it's understandable that I did this.
  16. I want to make a change, so let's draw a picture.
  17. Imagine this is my whole program and then somewhere here
  18. is the sequence part of my program.
  19. Now, of course, this has connections to other parts of the program.
  20. Sequence is called by and calls other components,
  21. and if we make a change to sequence,
  22. then we have to consider the effects of those changes everywhere else in which it's used.
  23. When we consider these changes, there are 2 factors we would like to break out.
  24. One is, is the change backward compatible?
  25. That is, if I make some change to sequence,
  26. am I guaranteed that however it was used before,
  27. that those uses are still good, and they don't have to be changed?
  28. If so, then my change will be local to sequence, and I won't have to be able to go
  29. all over the program changing it everywhere else.
  30. So that's a good property to have.
  31. So for example, in this case, if I change sequence so that it still accepted
  32. 2 arguments like it did before, but it also accepts more than 2,
  33. than that would be a backwards compatible change as long as I didn't break anything else.
  34. And then the second factor is whether the change is internal or external.
  35. So am I changing something on the inside of sequence that doesn't effect all the callers,
  36. than that's okay. In general, that's going to be backwards compatible.
  37. Or am I changing something on the outside--changing the interface to the rest of the world?
  38. In this case, going from the binary version to this n_ary version,
  39. I can make it backwards compatible if I'm careful.
  40. It's definitely going to be both an internal and external change.
  41. So I'm going to have to do something to the internal part of sequence.
  42. And then I'm also changing the signature of the function, so I'm effecting the outside as well.
  43. I can make that effect in a backwards compatible way.
  44. Thinking about those 2 factors, what would be the better way to implement this call?
  45. Let's say we're dealing with the match-set version where we're returning a tuple,
  46. would it be better to return the tuple sequence (a, b, c, d)
  47. or the tuple sequence of (a, sequence of (b, sequence of (c, d)?
  48. Tell me which of these do you prefer from these criteria.