Repeat Target Reference

In striving for HelpersInsteadOfWrappers, I notice a common pattern that perhaps could be linquistically refactored:

   foobar = x(a, foobar, b);

I'd like to propose something like this:

   foobar = x(a, @, b);

Where "@" refers to the receiving variable. The particular symbol chosen for the example is only a suggestion and is not the main point.

One may argue that by making the 2nd parameter modifiable (by reference) we can achieve the same thing. However, one may not always want to reference the same variable as the receiver. The above gives us a shortcut when we need it, but does not force it upon each call. (When the pattern occurs, it occurs in roughly about 80% of the call instances.)

It serves at least 3 needs:

1. Documents the fact that we are modifying the same variable.

2. If you need to change the target reference, then the parameter automatically matches up.

3. If you copy-and-paste the code for another use or instance, then you don't have to remember to change and check both "sides".

--top


CategorySyntax, CategoryCodingIssues


EditText of this page (last edited November 16, 2012) or FindPage with title or text search