你如何为命名空间设置名称?

时间:2023-01-13 12:26:47

I'll preface this by saying that I usually work in C#/.Net.

我将通过说我通常在C#/ .Net中工作来作为序言。

Normally, I use a naming scheme that puts common, reusable components into a namespace that reflects our organization and project-specific components into a namespace tied to the project. One of the reasons I do this is that I sometimes share my components with others outside my department, but within the organization. Project-specific namespaces are typically prefaced with the name or abbreviation of the department. When I reuse code between projects, I typically migrate it into one of the organization-based namespaces.

通常,我使用命名方案将常见的可重用组件放入命名空间,该命名空间将我们的组织和项目特定组件反映到与项目相关联的命名空间中。我这样做的原因之一是我有时会与我部门以外的其他人共享我的组件,但在组织内部。特定于项目的命名空间通常以部门的名称或缩写开头。当我在项目之间重用代码时,我通常会将其迁移到一个基于组织的命名空间中。

For example:

UIOWA.DirectoryServices contains classes that deal with the specific implementation of our Active Directory.

UIOWA.DirectoryServices包含处理Active Directory特定实现的类。

UIOWA.Calendar contains classes that deal with the University's master calendar.

UIOWA.Calendar包含处理大学主日历的类。

LST.Inventory.Datalayer holds the classes implementing the data layer of the Learning Spaces Technology group inventory application.

LST.Inventory.Datalayer包含实现Learning Spaces Technology组清单应用程序的数据层的类。

I'm embarking on a project now for an entity that has a fuzzier connection to the Unviersity (a student group that runs a charity event) that has the potential to be sold outside of our University and, thus, it doesn't really fit into my normal naming conventions, i.e., the department is only the first customer of potentially many that might use the project.

我现在正在开展一个项目,这个实体与Unviersity(一个举办慈善活动的学生团体)有着更为模糊的联系,有可能在我们大学以外的地方销售,因此它并不适合进入我的常规命名约定,即部门只是可能使用该项目的许多人的第一个客户。

My inclination is to go the organization naming route and create an "organizational project" name space for this application. I'd like to hear how others handle this and any advice you might have.

我倾向于去组织命名路线并为此应用程序创建“组织项目”名称空间。我想听听其他人如何处理这个以及你可能提出的任何建议。

Thanks.

See also this related question about namespace organization.

另请参阅有关命名空间组织的相关问题。

EDIT

I ended up creating the org/project namespace UIOWA.MasterEvent and deriving further namespaces from there. Still interested in other opinions for future projects.

我最终创建了org / project命名空间UIOWA.MasterEvent并从那里派生了更多的命名空间。对未来项目的其他意见仍然感兴趣。

3 个解决方案

#1


6  

My department got his name changed thrice in the last five years, so we're all glad that someone decided against using namespaces with organisational names...

我的部门在过去的五年中改变了他的名字三次,所以我们都很高兴有人决定不使用具有组织名称的命名空间......

Our namespaces are organised by project names. Reusable stuff is put into the Toolbox namespace. Perhaps a bit crude, but it works quite well so far.

我们的命名空间按项目名称组织。可重用的东西放入Toolbox命名空间。也许有点粗糙,但到目前为止它运作良好。

#2


1  

I'm a .NET developer, and I always use the organisational project namespace (com.bolidian.projectspace) because it guarantees uniqueness.

我是.NET开发人员,我总是使用组织项目命名空间(com.bolidian.projectspace),因为它保证了唯一性。

#3


0  

I use the organisation, followed by the product eg Acme.Crm. When grouping classes together in a subnamespace always use a plural or action so that it cant * with a class. eg

我使用组织,然后是产品,例如Acme.Crm。在子名称空间中将类分组在一起时,始终使用复数或操作,以便它不能与类冲突。例如

  • Acme.Crm.Letters
  • Acme.Crm.Invoicing

I follow Microsoft's convention by not capitalising acronyms eg Crm instead of CRM, Sql instead of SQL - but that's more a personal preference.

我遵循微软的惯例,不是首字母缩略词,例如Crm而不是CRM,Sql而不是SQL - 但这更像是个人偏好。

#1


6  

My department got his name changed thrice in the last five years, so we're all glad that someone decided against using namespaces with organisational names...

我的部门在过去的五年中改变了他的名字三次,所以我们都很高兴有人决定不使用具有组织名称的命名空间......

Our namespaces are organised by project names. Reusable stuff is put into the Toolbox namespace. Perhaps a bit crude, but it works quite well so far.

我们的命名空间按项目名称组织。可重用的东西放入Toolbox命名空间。也许有点粗糙,但到目前为止它运作良好。

#2


1  

I'm a .NET developer, and I always use the organisational project namespace (com.bolidian.projectspace) because it guarantees uniqueness.

我是.NET开发人员,我总是使用组织项目命名空间(com.bolidian.projectspace),因为它保证了唯一性。

#3


0  

I use the organisation, followed by the product eg Acme.Crm. When grouping classes together in a subnamespace always use a plural or action so that it cant * with a class. eg

我使用组织,然后是产品,例如Acme.Crm。在子名称空间中将类分组在一起时,始终使用复数或操作,以便它不能与类冲突。例如

  • Acme.Crm.Letters
  • Acme.Crm.Invoicing

I follow Microsoft's convention by not capitalising acronyms eg Crm instead of CRM, Sql instead of SQL - but that's more a personal preference.

我遵循微软的惯例,不是首字母缩略词,例如Crm而不是CRM,Sql而不是SQL - 但这更像是个人偏好。