From 29a4de17d3c01a3da943564ece97574bf5c85624 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eray=20=C3=96zkural?= Date: Fri, 10 Jun 2005 13:10:58 +0000 Subject: [PATCH] * put coding suggestions in CODING file --- src/CODING | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/CODING diff --git a/src/CODING b/src/CODING new file mode 100644 index 00000000..ce826877 --- /dev/null +++ b/src/CODING @@ -0,0 +1,44 @@ +Like every serious project, there are guidelines. +Oooooo. "Coding Standards". + +Guidelines +---------- + +1. When using dirnames, don't expect the dir to end + with a trailing slash, and please use the dirnames + in pisiconfig +2. Python indentation is usually 4 chars. + +Suggestions +------------ +In OO programming, try to invoke Demeter's law. +One of the "rules" there is not directly accessing any +objects that are further than, 2/3 refs, away. So the +following code is OK. + destroy_system(a.system().name()) +but the following isn't as robust + destroy_system(object_store.root().a.system.name()) +As you can tell, this introduces too many implementation +dependencies. The rule of thumb is that, in these cases +this statement must have been elsewhere.... It may be a +good idea to not count the object scope in this case, +so in Python self.a means only one level of reference, +not two. + +One quibble with this: it may be preferable not to insist +on this where it would be inefficient. So if everything +is neatly packed into one object contained in another +object, why replicate everything in the upper level? If +the semantics prevents dependency changes, then chains +of 3 or even 4 could be acceptable. + +OTOH, in Python and C++, it's not always good to implement +accessor/modifier pairs for every property of an object. +It would be much simpler if you are not doing any special +processing on the property (e.g. if what the type system +does is sufficient). + +The main rule of thumb in Demeter's Law is avoiding +putting more than, say, 10 methods in a class. That works +really well in practice, forcing refactoring every now +and then.