What would you say if you saw a C# framework that had classes with public fields. No, I'm not talking about const fields. I'm talking about public non-static mutable fields.

If you are like most developers, there are probably a number of things running through your head now. One is that whoever wrote the code must be naive. We all know that public fields are bad. At the very least, fields should be hidden behind properties, or at least getters and setters. It's just bad practice.

But... how do you know?

One answer is: because violates style rules. Another is: it ignores years of experience formulating best practices for programming.

But, again, how do you know it is bad?

I run into this problem frequently now. It seems that we're very good about articulating rules and best practices. If you go onto any newsgroup or mailing list, you'll find a number of people who will argue with you about the right way to do something. However, the saddest experiences I've had with teams are times when I've visited and seen code that applies nearly every "best practice" you can imagine, without thought. You look at a particular situation and you see that, well, in this particular case, the advice of so-and-so in this-or-that book about programming in C++, C#, or Java doesn't apply... that there is some much more contextual way of doing things, but no, the rule is the rule and we have to argue.

Good programming is contextual. Practice is contextual. We can articulate rules about how to use language constructs correctly, but they're just guidelines. Context is king.