158

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.

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 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:

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

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

Mike Spross
  • 7,999
  • 6
  • 49
  • 75
  • 1
    Common, get yourself a personal domain (firstname-lastname.net) and use it as a package name. The purpose of package is to be globally unique, so myprojects don't really cut it. – Vladimir Dyuzhev Nov 15 '08 at 16:16
  • 5
    [Using an .onion domain](https://www.torproject.org/docs/tor-hidden-service.html.en) is also an option (like `onion.duskgytldkxiuqc6.packagename`). As long as the private key remains secret, you're in control of the domain name. So it's free to register (generate), and it's permanent (unlike conventional domains). It conforms to the letter of Java convention, and it identifies you uniquely. – sastanin Oct 30 '13 at 14:50
  • 16
    You could always create a GitHub account and use io.github.username.*. – Bardi Harborow Mar 05 '15 at 02:06
  • 2
    @BardiHarborow thanks, I used your suggestion. – Nick Volynkin May 28 '15 at 13:13
  • @BardiHarborow Why "io." ? – GabrielBB Dec 26 '16 at 19:22
  • 4
    @GabrielBB, [GitHub Pages](https://pages.github.com/) allows you to host HTML and Jekyll sites at yourusername.github.io, and therefore subdomains of github.io are more "guaranteed" to correspond to GitHub users than subdomains of github.com (which might be used for internal GitHub projects at any time). – Bardi Harborow Dec 27 '16 at 23:16
  • Reason to reopen: two good answers (github and onion) are comments. – serv-inc Jan 27 '18 at 12:30
  • 1
    @serv-inc I agree; nominated for reopening. – Mateen Ulhaq May 31 '20 at 17:26
  • @sastanin : you could post this as an answer now – serv-inc Jun 04 '20 at 15:03
  • @BardiHarborow : you could post this as an answer now – serv-inc Jun 04 '20 at 15:04

12 Answers12

52

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).

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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
  • 1
    So If I want to address the package name as `com.xyz` should this package name be registered somewhere?? P.S. `xyz` is my client. – Prasad Dec 29 '14 at 10:02
  • 14
    I wonder if I can use my github id for that and github domain? E.g. `com.github.mygithubid.myproject`? – Kirill G. Apr 26 '15 at 02:45
  • 2
    @KirillG. I would kind of recommend against it, since GitHub IDs can be changed at any time, any number of times. Granted, any domain can change, but not as easily or often (not normally anyway). Though I guess it's OK for hobby projects. – sara May 06 '15 at 23:39
30

I just use my initials: fg.nameofproject.etc

It reduces typing. It can be prefixed at any time with sf.net or com. or org. or com.google..

As the project is personal treat it special just like your freshly pressed personalized gift shirt - it will feel good.

Florin
  • 1,379
  • 3
  • 16
  • 21
  • 19
    @click according to the [guidelines](http://docs.oracle.com/javase/tutorial/java/package/namingpkgs.html) that would be `bond.james._007` - doesn't have the same ring to it... :-{ – corsiKa Oct 18 '13 at 16:56
20

<sarcasm> Bah. Any self-respecting programmer would have his or her own domain name. This is clearly a trick question. Everyone has their own personal domain name! </sarcasm> :-)

Ok, in all seriousness, buying a custom domain name is probably the easiest option. For about $10 a year, you can find reputable providers to host the domain and forward email.

James Schek
  • 17,844
  • 7
  • 51
  • 64
  • 18
    Strangely enough, this'll do your self-confidence a boost too. – jamesh Nov 18 '08 at 17:00
  • 32
    Good answer, but a starting programmer probably doesn't want to buy a website just to follow some tutorial website or video on how to create a GUI with a close button. – Jochem Kuijpers Nov 13 '14 at 18:07
20
pmurray_at_bigpond_dot_com.project.package
paulmurray
  • 3,355
  • 1
  • 22
  • 17
17

I store most of my hobby projects in Google Code, so I just use the project site as the package name: com.googlecode.donkirkby.someproject.

serv-inc
  • 35,772
  • 9
  • 166
  • 188
Don Kirkby
  • 53,582
  • 27
  • 205
  • 286
  • 8
    How blind could we have been to not see the folly of our actions?! – Joey Sabey Oct 05 '15 at 20:45
  • 1
    You miss Google Code, @Joey? I've mostly used [GitHub](https://github.com/donkirkby) for the last several years, so I just had to move a few of my old projects over from Google Code before they shut down. – Don Kirkby Oct 06 '15 at 18:40
  • So did you rename the packages, kept the googlecode names, or ...? – serv-inc Jan 27 '18 at 12:26
  • 1
    I haven't used any of the old code since I moved it, @serv-inc. Either option would work. – Don Kirkby Jan 28 '18 at 05:04
3

my name is anjan

usually, I use com.anjan

I have a fantasy company of my own -- sometimes I use that

the tradition with sourceforge(as hibernate and other packages showed) is net.sf.*

so, depending on your mood, you can go with that.

anjanb
  • 12,999
  • 18
  • 77
  • 106
  • 14
    Unless you also own http://anjan.com/ I think you are terribly wrong in doing so. – Fredrik May 31 '09 at 19:50
  • 8
    @Fredrick luckily, it looks like anjan.com isn't going to be releasing any libraries any time soon. – corsiKa Oct 18 '13 at 16:58
  • 1
    @corsiKa : you're right, as long as I'm not releasing anything, I'm OK. :-) – anjanb Oct 23 '13 at 15:04
  • 3
    @anjanb Well, I went to they're website. They do pet food. I'm no expert, but most pet food companies don't release many software libraries =) – corsiKa Oct 23 '13 at 15:33
3

I think you've got it worked out. The temptation to avoid here is to not bother with a package name at all. It's easy to save a few keystrokes because "I'm just writing some test code." But then the code gets good and useful and large, and then you realize you have a solid start for what may be a long-lived library or application. It may not be a library or an application that ever leaves your home network, but the point is, you've not thought ahead. That's the Denmark ghost of computer science -- always think ahead, if only a little bit.

The naming convention I use for my hobby code is very much like yours. I have a top-level directory named "futura" (long, boring reasons why that name came about) that all my code hangs off of. I do try and organize my code into package libraries, even if it might be a class or package I never use for another project. I place all applications (that is, anything that has a void main(String[] args) in the class) in the futura.app.* folder. I also try to mimic the standard Java library package names for my own code, although in a couple of cases I broke convention because of my own tastes (i.e. futura.inet for Internet, not merely socket, code, and futura.collections for non-util stuff.) To paraphrase David Mamet: Always be genericizing. Always be genericizing!

From the care you used to post the question, I suspect you agree with my last point as well: You don't have to treat hobbyist hacking as an enterprise-level project, but if you bring some of that discipline to the home game, the hobby is all the more rewarding.

Jim Nelson
  • 1,688
  • 3
  • 15
  • 27
3

My naming: prj.project_name.

Amir Saniyan
  • 13,014
  • 20
  • 92
  • 137
2

I use my OpenID URL and then I append my project's name. for example, com.myopenid.cd1.twitter is the root package of a Twitter client I've been developing.

cd1
  • 15,908
  • 12
  • 46
  • 47
  • I liked this, but then I realized it no longer exists. :( http://www.janrain.com/myopenid-service-ends/ "As of February 1, 2014 MyOpenID service has been turned off." – successhawk Mar 12 '17 at 17:33
1

I just use my name: surname.initials.xxx, as a nice comprise between brevity and collision avoidance. I figured that would give a reasonable collision free namespace should I ever choose to publicly publish the code. I also have a little program I've written which can repackage entire directory trees so I figured should I ever need to repackage for publishing it's quite painless... therefore I didn't loose too much sleep over it.

After the surname.initials.xxx, I use either app for application packages, lib for library packages, and tst for stuff I am purely experimenting with.

Lawrence Dol
  • 63,018
  • 25
  • 139
  • 189
1

what you think about lastname.firstname.project ??? like luz.marlon.project ?

  • 16
    That might work for you, but John Smith and Bob Jones might run into conflicts when they want to release their code someday. – Bill the Lizard Nov 18 '08 at 13:38
0

I thought about asking this same question. So far i've used the prefix com.tehvan, even though i don't actually have a company.

tehvan
  • 10,189
  • 5
  • 27
  • 31