Keith Ray | 6 Nov 2006 03:50
Picon

Re: The wrong duplication

1. The first time I use a certain string literal, I just use it in
whatever function needs it.

If it needs to be localizable, it's wrapped in a macro and copied to
the localizable.strings file.

2. The second time I need to use that string literal, I make it into a
symbolic constant.

This would be the case if I'm doing TDD and both the test and the
code-under-test need to use the string literal.  So the code may
transition from #1 to #2 very quickly.

3. The third to Nth times that I need to use that string literal, I
look for common code and try to extract that.

On 11/5/06, Kevin Rutherford <kevin <at> rutherford-software.co.uk> wrote:
>
>
>
>
>
>
> Here's something I've seen many times in code right across the spectrum, and
>  which I caught myself doing just the other day (hence the reason for
>  un-lurking right now). It seems to occur particularly often in codebases
>  that weren't TDD'd, and which haven't been kept lean with regular
>  refactoring...
>
>  Imagine a codebase in which one particular text string occurs frequently.
(Continue reading)


Gmane