@@ -642,6 +642,7 @@ It's an invariant of your program that a manager ID can't just be
642642random; it has to identify an employee that's in the database—that's
643643part of what it means for the program to be in a good state, and all
644644through the program you have code to ensure that invariant is upheld.
645+
645646#### Encapsulating invariants
646647
647648It would be a good idea to identify and document that whole-program
@@ -730,7 +731,7 @@ only slightly modified.
730731
731732``` swift
732733/// A resizable random-access `Collection` of `T`s.
733- struct DynamicArray <T > {
734+ struct MyArray <T > {
734735
735736 /// Removes and returns the last element.
736737 public mutating func popLast () -> T { ... }
@@ -760,7 +761,7 @@ The first one
760761
761762``` swift
762763/// A resizable random-access `Collection` of `T`s.
763- struct DynamicArray <T >
764+ struct MyArray <T >
764765```
765766
766767gives us the context we need to understand the methods: we 're looking
@@ -817,9 +818,9 @@ the array has an element. OK, so what about postconditions?
817818
818819The postconditions are the effects of the method plus any returned
819820result. If the preconditions are met, but the postconditions are not,
820- and the function does not report an error, we'd say the method has a
821- bug. The bug could be in the documentation of course, * which is a
822- part of the method* .
821+ and the function does not report a runtime error, we'd say the method
822+ has a bug. The bug could be in the documentation of course, * which is
823+ a part of the method* .
823824
824825``` swift
825826/// Removes and returns the last element.
@@ -905,7 +906,8 @@ it need not take more than a few seconds:
905906
906907### A More Complicated Example
907908
908- Let's take a look at a traditional sorting algorithm.
909+ Let's take a look at a traditional sorting algorithm on a fictitous
910+ collection type:
909911
910912``` swift
911913extension DynamicArray {
@@ -916,7 +918,7 @@ extension DynamicArray {
916918 /// over the elements of `self`.
917919 /// - Complexity: at most N log N calls to `areInIncreasingOrder`, where N is
918920 /// the number of elements.
919- mutating func sort < T > (areInIncreasingOrder : (T, T )-> Bool ) { ... }
921+ mutating func sort (areInIncreasingOrder : (Element , Element )-> Bool ) { ... }
920922}
921923
922924var a = [7 , 9 , 2 , 7 ]
@@ -1049,7 +1051,7 @@ tricky, we can drop the example, and we're left with this:
10491051/// over the elements of `self`.
10501052/// - Complexity: at most N log N comparisons, where N is the number
10511053/// of elements.
1052- mutating func sort < T > (areInOrder : (T, T )-> Bool ) { ... }
1054+ mutating func sort (areInOrder : (Element , Element )-> Bool ) { ... }
10531055```
10541056
10551057But we can go further and use a much simpler and more natural summary:
@@ -1093,7 +1095,7 @@ declaration:
10931095///
10941096/// - Complexity: at most N log N comparisons, where N is the number
10951097/// of elements.
1096- mutating func sort < T > (areInOrder : (T, T )-> Bool ) { ... }
1098+ mutating func sort (areInOrder : (Element , Element )-> Bool ) { ... }
10971099```
10981100
10991101There is one factor we haven't considered in making these changes:
0 commit comments