EFH wrote:Well, it's brittle because if the name of a class changes, the code breaks
"Breaks" in what sense?" It
changes, sure. But I had assumed that the intent of the code was to provide the correct class name. Even if the class name changes. Because, after all,
that's what the code says to do. So how is that broken? Should we assume the coder was trying to do someting else entirely? Based on what?
paul wheaton wrote:Suppose you want to change the string: do you change your class name?
I would think that depends on the intent of your change. Do you want to change the string, or do you want to change the class name? Is the string intended to reflect the class name, or not? This goes back to my previous comments. To me it seems perfectly reasonable to want to, say, log the actual name of the class that was executing this method. Which this does.
PW wrote:Suppose you want to change the class name: will you remember to change your string? Or will your program still work with the new string?
From what we've seen so far, the original
intent of the program was probably to show the actual class name. The string will change automatically in reponse to the change of the class name. And this seems like a good thing. What's the problem?