Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ideal number of classes per namespace branch [closed]

What number of classes do you think is ideal per one namespace "branch"? At which point would one decide to break one namespace into multiple ones? Let's not discuss the logical grouping of classes (assume they are logically grouped properly), I am, at this point, focused on the maintainable vs. not maintainable number of classes.

like image 543
petr k. Avatar asked Sep 28 '08 17:09

petr k.


1 Answers

"42? No, it doesn't work..."

Ok, let's put our programming prowess to work and see what is Microsoft's opinion:

# IronPython
import System
exported_types = [
  (t.Namespace, t.Name)
  for t in System.Int32().GetType().Assembly.GetExportedTypes()]

import itertools
get_ns = lambda (ns, typename): ns
sorted_exported_types = sorted(exported_types, key=get_ns)
counts_per_ns = dict(
  (ns, len(list(typenames)))
  for ns, typenames
  in itertools.groupby(sorted_exported_types, get_ns))
counts = sorted(counts_per_ns.values())

print 'Min:', counts[0]
print 'Max:', counts[-1]
print 'Avg:', sum(counts) / len(counts)
print 'Med:',
if len(counts) % 2:
  print counts[len(counts) / 2]
else: # ignoring len == 1 case
  print (counts[len(counts) / 2 - 1] + counts[len(counts) / 2]) / 2

And this gives us the following statistics on number of types per namespace:

C:\tools\nspop>ipy nspop.py
Min: 1
Max: 173
Avg: 27
Med: 15
like image 165
Constantin Avatar answered Sep 17 '22 11:09

Constantin