您在Java中使用什么包命名约定用于个人/业余爱好项目? [英] What package naming convention do you use for personal/hobby projects in Java?

查看:656
本文介绍了您在Java中使用什么包命名约定用于个人/业余爱好项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经熟悉使用域名创建唯一包名称的标准Java包命名约定(即包 com.stackoverflow.widgets )。但是,我从未见过有关如何为个人项目选择包名的任何建议。我假设是因为这是因为这真的是个人品味的问题。

I'm already familiar with the standard Java package naming convention of using a domain name to create a unique package name (i.e. package com.stackoverflow.widgets). However, I've never seen any recommendations for how to choose package names for personal projects. I assume because this is because this is really a matter of personal taste.

那么,你如何选择永远不会投入生产的个人项目的包名?可能在业余时间尝试新的框架)。假设您没有可以用来创建包结构的个人网站,那么您(或将会)做什么?你有一个逻辑系统来为业余爱好项目生成新的包名,或者你只是使用简单的丢弃包名称,如 mypackage

So, how do you choose package names for personal projects that will never make it into production (you might be experimenting with a new framework in your spare time). Assuming you don't have a personal website whose domain you can use to create your package structure, what do (or would) you do? Do you have a logical system in place for generating new package names for hobby projects, or do you just use simple throw-away package names like mypackage?

由于我很想知道不同人的想法是什么,我已经把它变成了社区维基。

Since I'm just curious to see what different people's thoughts are on this, I've made this a community wiki.

For我个人而言,我从未考虑过这个问题,但我想今晚与 Wicket 一起玩,并且它发生了对我来说,我不清楚我是如何组织自己的爱好项目的。对于业余爱好项目(在我看来,至少),一个单独的,独特的包命名约定将成为保持个人和工作相关代码彼此明显分离的好方法。

For me personally, I've never given it much thought, but I wanted to play around with Wicket tonight and it occurred to me that I don't have a clear idea of how I want to organize my hobby projects. A separate, distinct package naming convention for hobby projects (in my mind, at least) would serve as a good way to keep personal and work-related code clearly separate from each other.

我在想一个简单的分层命名约定,将我个人项目的源代码保存在一个根文件夹中:

I was thinking of a simple hierarchal naming convention, to keep the source for my personal projects in a single root folder:


  • 使用 myprojects 作为根文件夹

  • 附加项目名称

  • 添加任何其他子包名称

  • Use myprojects as the root folder
  • Append the project name
  • Add any additional subpackage names

所以,我的Wicket项目将在 myprojects.learningwicket 包中测试将在包 myprojects.learningwicket.tests (例如)中。

So, my Wicket project would be in the package myprojects.learningwicket and unit tests would be in the package myprojects.learningwicket.tests (for example).

推荐答案

如果你只做个人项目而没有其他人会使用这些代码,那么你就可以组成一个你喜欢的包名。不要构成以 com。 net。或其他顶级域名开头的东西,因为那样意味着你拥有域名(即使用 com.john 作为你的包名,因为你的名字恰好是John并不是个好主意。)

If you're just doing personal projects where nobody else will use the code, then you can make up a package name that you like. Don't make up something that starts with com. or net. or other top-level domain though, because that would imply that you own the domain name (ie. using com.john as your package name just because your name happens to be John is not a good idea).

如果您要将代码提供给其他人,则应使用全局唯一的包名称,根据Java约定,您应该注册并使用域名。

If you're going to give the code to anybody else, you should use a globally unique package name, which according to Java conventions means you should register and use a domain name.

这篇关于您在Java中使用什么包命名约定用于个人/业余爱好项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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