每个命名空间分支类理想的数字 [英] Ideal number of classes per namespace branch

查看:114
本文介绍了每个命名空间分支类理想的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您如何看待许多类是每一个命名空间分支的理想?在这一点上总会有决定打破一个命名空间为多个的呢?让我们不要讨论类的逻辑分组(假设它们在逻辑上划分正确),我,在这一点上,集中在维护与类不维护的数量。

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.

推荐答案

42?不,这是行不通的。

"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

这篇关于每个命名空间分支类理想的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆