Generally, brittle code is code that depends on details that shouldnt really matter, especially in ways so that changing one thing breaks a number of really unrelated things.
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?
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?
From what we've seen so far, the original intent of the program was probably to show the actual class name.
And that's where I have advantage over you. BWA HA HA HA HA HA (cough cough) .......
So this is related to an assignment, which we are all trying to not directly discuss.
But I happen to have been the nitpicker for this assignment where it was used.
Suppose you have a shopping cart full of groceries and the user asks for a list of the stuff in the basket. You have a class called Cheese which contains info on variety of cheese, how stinky the cheese is and other interesting cheesy attributes. When asked to list the stuff in the cart, do you report the class name, or would that make the application brittle?
I know that some people use it for some logging stuff, but the uses I've seen seem stupid to me.
I'm sitting here trying to think of a case ... something to do with debugging or logging something for a developer ... but I cannot help but think all of the exception stuff takes care of any need for that sort of thing.
If nothing else, use of this sort would be rather advanced. I probably wouldn't use it unless there was no other way.