Re: Code Guidelines
Re: Code Guidelines
- Subject: Re: Code Guidelines
- From: "M. Uli Kusterer" <email@hidden>
- Date: Mon, 31 May 2004 14:02:56 +0200
At 11:02 Uhr +0200 31.05.2004, Georg Tuparev wrote:
In what way "account" is communicating less useful information then
say "iAccount"? And why the hell so many developers are happy to
write
[accountList lastObject];
but when they add their own NSArray category, they write
[iAccountList mFisrtObject];
I occasionally have the pleasure of working with code somebody else
wrote. And every time I do that, I curse at people who don't use at
least a minimum of prefixes. "g" for globals should IMHO be standard.
Why?
Because when I read some code that contains an assignment statement,
if there are no prefixes, there is no way for me to immediately know
whether this assignment has any side effects. If it's a local
variable, I usually only need to glance at the top of the function to
find out that's the case.
But if it is a direct assignment to a member variable, this means
that this isn't just a local change. Yes, ObjC alleviates this a
little by having singleton factory methods that return the object
pointed to by the global, but when I have to modify the class it's
still nice to know what that accessor does at a single glance.
I see prefixes as an extension of "design by contract". I don't care
what convention you use, but use one, and stick to it. It is much too
easy to violate a contract because the popular flavors of C hardly
enforce any contracts. By naming my variables with a few prefixes, it
is clear to anyone reading the code what they may and what they may
not do with the variable.
Very often I believe all these reverse hungarian notation & friends.
are there to detract the attention from doing the programming to
talking about doing programming. Or are they there to satisfy some
unconscious masochistic and sadistic needs?
just wondering...
Well, I personally think the way Windows encodes a variable's type
in the prefix is a little overkill. I use prefixes mainly to indicate
non-obvious scope, and to save myself from scrolling through half a
source file to find out whether I just screwed global state. I also
use prefixes on pointer parameters to indicate whether the caller has
to allocate the pointer, etc.
(I and my team does what NeXT and later Apple did since 1990 and
never felt the need, or regretted that I or any of my colleagues did
not used [iAccount mBalance] instead of [account balance]...)
As I said, I currently don't use any prefixes for member variables,
and I definitely wouldn't use prefixes for accessors.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.