Wednesday, November 21, 2012

Contrafactual Java Package Name

I know of at least two limitations to package names. One, I've stumbled upon a few times until I learned to avoid it 'by heart': Java keywords.

Just found out about another one: can't start with a (decimal :) numeral. Which is a bummer. For instance, stuff having to do with 3-dimensional maths and graphics would be most easily recognized under the name '3d'.

Workarounds.... for '3d', let's see: Ugly "_3d"? Cryptic "ddd"? Associative "xyz"? Silly "three_d"?

With the keywords, you can at least have a name that starts with the word you'd rather have, helping with matching and alphabetical ordering and such things.

---

I wonder why he/they didn't go for a separate package syntax. I mean, the '.' can never be used as the other form of qualification operator anyway. Maybe there was plans for namespaces-as-objects or something.

(Interesting digression...it could actually be implemented (except being able to use regular dot syntax, of course); take (ClassLoader, InitialPackage) --> PackageNamespaceObject or something.)

Slash syntax would've worked. Contrafactual Java:
package com/mylib/somepackage;

import com/mylib/somepackage/misc/*;
import com/mylib/someotherpackage/thispackage/ThisClass;
import com/mylib/someotherpackage/3d-math/SomeModule;

public class Contrafactual3dDemo { //...
}
(And why not lose those package and import semicolons...)

No comments:

Post a Comment