Post date: Oct 07, 2008 6:13:5 PM
Just a forewarning, I've been putting off writing this post for awhile, because I expect it will degenerate into one huge digression and ultimately require several posts to cover. But I figure I best start somewhere. So... lets start the digression.
So, I do an awful lot of thinking about how I program, and basically I've come to the conclusion that I'm just weird. I do a lot of things in a fairly standard way, and some other things in a fairly non-standard way. A few of my quirks are as follows.
Brackets MUST be aligned vertically, or in rare cases horizontally.
if(something)
{
while(something_else)
{
statement;
}
another_statement;
}
or just maybe for the sake of compactness and code density
if(something) { statement1; statement2; }
else { another_statement; }
In my opinion, this adds to code readability immensely, I just don't understand the value people see in sticking that first bracket directly after the conditional
if(my_code_is_ugly) {
wtf;
}
I feel smugly justified in this practice, because I've several times had someone look over shoulder and make the "You code looks so organized," or "How do I make my code look so pretty." And I'm pretty sure that my strict adherence to this is the primary reason.
I tend to try and label my members variables as succinctly as possible, and as a general rule I abhor long descriptive prefixes such as miwtf_member, instead opting for a simple underscore, _member.
And indeed, I consider even this to be a compromise measure to ensure compatibility with how I write my Getters/Setters.
This is where I am the most unusual, I really hate seeing functions like
type getMember();
void setMember(type value);
First of all, if these are both one line functions that do absolutely nothing else but assign and return a private member, then you have absolutely no reason to keep it private. Just make it public and save yourself the hassle of dealing with these pointless access functions.
But if these functions actually perform some additional work, why the hell are we bothering with the get & set. Why not just write
type member();
void member(const type &value); //const reference for efficiency
and allow the parameters you pass to resolve which of these functions you're calling. This seems to me to reflect a more context sensitive approach to programming, which I've always appreciated.
I think that we as human's have an innate ability to recognize and exploit context, and there that are some parallels between context in human languages and scope in programming languages. And when we code in a context sensitive manner we learn how to apply our sensitivity to context to the programming language and its scoping rules in a manner that creates more readable code.