I don't really think they are evil. But I would love to live in a world where I never had to use them unless I really needed to.
One example I read above was future-proofing
your code. For example:
public void setValue(int value)
{
this.value = value;
}
Then, the requirements change and you need to track how many times the value was set.
So:
public void setValue(int value)
{
this.value = value;
count++;
}
This is beautiful. I get it. However, in Ruby, would the following not serve the same purpose?
someobject.my_value = 100
Later, you need to track the number of times my_value
was set. Well then, could you not just override the setter THEN and only THEN?
def my_value=(value)
@my_value = value
@count++
end
I'm all for beautiful code but I have to admit, looking through the mountains of Java classes we have and seeing literally thousands and thousands of lines of code that are NOTHING but basic getter/setters is ugly and annoying.
When I was developing in C# full time, we used public properties all the time and did custom getters/setters only when needed. Worked like a charm and it didn't break anything.