Re: How to name variables in a program?
- From: "Phlip" <phlip_cpp@xxxxxxxxx>
- Date: Sun, 29 May 2005 20:21:02 GMT
websnarf wrote:
> dbPop3MsgHdrGet is different. You immediately know that its an
> attribute read function of some kind (Get) its been defined in a module
> called db, or a submodule of db called pop3, and the thing we are
> reading is a "message header". So its an explicit encoding, that lets
> you know exactly what it is. In C++ it would probably look something
> like db::pop3::msg->getHdr() which is not drastically different.
But the latter has more room for improvement.
The "Law of Demeter" _roughly_ means "don't type too many dots [or colors or
arrows]" on one line.
So if we only pop pop3 message headers within their own module, and abstract
them from outside the module, we get this:
namespace db {
...
class pop3 {
...
msg->getHdr();
}
}
Now we need to type db and pop3 less often, so we can safely make them
longer. Similarily, the line with msg->getHdr() is now shorter, so we have
room to make it longer:
namespace eMailDatabase {
...
class PostOfficeProtocolThree {
...
pMessage->getHeader();
}
}
Put another way - the _need_ to cram so many abbreviations into a single
identifier is a design smell. It indicates poor encapsulation.
> The other advantage of my scheme is that when you ASCII sort the
> symbols, they make some sort of sense and look fairly organized
> anyways.
Uh, just to find a quibble here, I could point out one should manually sort
ones files, then document in the native order. Stuff should look fairly
organized anyway...
--
Phlip
http://www.c2.com/cgi/wiki?ZeekLand
.
- Follow-Ups:
- Re: How to name variables in a program?
- From: Arthur J. O'Dwyer
- Re: How to name variables in a program?
- References:
- How to name variables in a program?
- From: SerGioGio
- Re: How to name variables in a program?
- From: websnarf
- Re: How to name variables in a program?
- From: Alf P. Steinbach
- Re: How to name variables in a program?
- From: spinoza1111
- Re: How to name variables in a program?
- From: Jens . Toerring
- Re: How to name variables in a program?
- From: websnarf
- How to name variables in a program?
- Prev by Date: Re: Suggestions for double-hashing scheme
- Next by Date: Re: Advice for mid-life career change (to programming)
- Previous by thread: Re: How to name variables in a program?
- Next by thread: Re: How to name variables in a program?
- Index(es):
Relevant Pages
|