Search |
||
More Literate Programming with jMock: AnaphoraPosted by tomwhite on May 14, 2006 at 2:30 AM PDT
According to the dictionary, an anaphor is a word used to avoid repetition. It refers back to something in the conversation. The word "it" in the previous sentence refers back to the word "anaphor" in the first sentence, so "it" is an anaphor for "anaphor". Natural language is often ambiguous, and one reason for this is that it may not be clear which word an anaphor such as "it" is referring to. But ambiguity and programming languages don't go very well together - so why would anyone want to mix the two? Actually, there are circumstances in programming languages where there is no real ambiguity, and an anaphor can have a use in eliminating repetition. Think of it as applying the DRY (Don't Repeat Yourself) principle at the syntax level. jMockWe introduced a limited form of anaphora in the functional test framework I talked about in my previous blog entry, Literate Programming with jMock. Consider some more sample code:
The variable
So where does the the variable
That's it. Temporary Local VariablesThe biggest gain is the case where you can avoid having to create a temporary local variable. You often want to assert several things about an object, so you end up creating a local variable with a short name to refer to the target object:
Alternatively, you can use the
Using
Our experience has been that the little bit of syntactic sugar that »
Related Topics >>
Testing Comments
Comments are listed in date ascending order (oldest first)
|
||
|
|