A design problem I met again and again.

andrew cooke andrew at acooke.org
Thu Apr 2 13:45:46 CEST 2009


Lawrence D'Oliveiro wrote:
>> What are the average size of source files in your project?   If it's
>> far lower than 15,000,  don't feel it's a little unbalance?
>
> Why?

one reason is that it becomes inefficient to find code.  if you structure
code as a set of nested packages, then a module, and finally classes and
methods, then you have a tree structure.  and if you divide the structure
along semantic lines then you can efficiently descend the tree to find
what you want.  if you choose the division carefully you can get a
balanced tree, giving O(log(n)) access time.  in contrast a single file
means a linear scan, O(n).

(i am talking about human use here - people reading and trying to
understand code, perhaps during debugging or code review or whatever).

andrew

(you could argue that the file contents can be sorted in some way - you
could even map from the tree to the file a traversal - but in practice
humans seem to be a lot better at making a series of decisions descending
a tree than holding the entire structure in their head as a sort order)




More information about the Python-list mailing list