In Getter Eradicator, Martin Fowler argues that there are cases when using getters and setters is entirely appropriate. There is the argument that using getters violates encapsulation, but Fowler argues that you shouldn’t think about hiding data so much as design decisions. The real case for avoiding getters is to discourage procedural design in object-oriented languages. Pulling data out of an object to decide what to do is just procedural programming, whereas telling the object to do something and letting it figure out for itself how to do so would be more appropriate. He referenced a few other articles, among them Tell, Don’t Ask which describes the principle above.
It made for great reading, but it made me a bit concerned. I know and have known beyond a doubt that I must be doing something wrong; there is no way that I can claim 100% accuracy and correctness with the code I write. What I don’t know is what exactly would be wrong. I might write some code that seems perfectly fine to me but would make someone more experienced roll his/her eyes.
Now, if I write code, and it works, and I manage to finish whatever project I am working on, someone might argue, “Hey! Who cares how ‘correct’ it is? It works, so it is good enough!” If my goal was to just finish a project and be done with it, yes, I would agree. If it works, it is correct enough.
But one of my goals is to improve my ability to create, and that includes improving my coding as well as my designing skills. It isn’t enough to be able to get something working, although doing so would be a great first step. I want to be able to write great code and know it. It may take years of practice, and the Thousander Club will certainly help, but I want to design and write better code.
Of course, practice doesn’t help when there is no one to look over your work except yourself. I might be doing something that works well enough that I don’t realize that I’ve done it completely backwards. It may be the source of some trouble, but if I am not aware that the trouble is optional, how can I do anything about it?
In the past, I’ve asked other game programmers to look over my work and provide some feedback. It is definitely enlightening to get an analysis on a real project and not just a grade in class for writing a function. I’ve asked questions on forums and IRC, but it usually depends on who is around to answer and if they feel the question is good enough. Otherwise, I’m on my own.
I’m sure I am not the only lone wolf out there, so please let me know: how do you improve your own abilities when you’re basically the only one to provide a “peer review”?