Code Organization Alternatives

This page came from a discussion of the flaws of the java packaging system on IfSmalltalkIsSoGoodWhyDoesNobodyUseIt.

First question that might be asked is why do we need code organized?

This is off the top of my head. I'm hoping TomStambaugh has a better list!


Java Packages

A classic rooted tree. Tied to the filesystem; being WriteOnceRunAnywhere it assumes a lowest common denominator filesystem - no SymbolicLinks or wacky mounting of directories (see WhatIsNotInPlanNine)

Using packages is even less comfortable than a filesystem - you must either refer to stuff in the current package, or declare dependencies using absolute paths. You can't eg refer to foo.Circle if foo is a subpackage of the current one. While java class files do actually declare explicit dependencies, the 'import foo.*' syntax allows java developers to easily declare dependencies on things they don't depend on.

The code organisation represents the view of the original developer of the best way to organize the code. There is also a feature in java that the 'protected' keyword allows access to some things within the current package that classes outside the current package can't reference. However, this is rarely the reason for a given package organization. No other views of java code are available.


While some of this is a problem, the lack of explicit dependencies can be useful. An example is the lack of an explicit dependency on the core packages ('java.*'). If the dependency was on an explicit version, then code cannot be used on later VMs, or on alternate VMs (e.g. you could not develop code on a desktop VM and use it on the palm KVM). Jar isn't in the metamodel because that whole mess (filesystems, classpaths, etc) is meant to be abstracted out by your ClassLoader, which you can change, to e.g. fetch classes from the network, or build them on the fly from a stream of bytes you generate. Package doesn't have dependency methods because dependencies are at the class level (which I agree is a lousy way of organizing things)

None of the prior objections to Java packages bother me. Except for package permission, which most programmers don't use, packages are simply a way of partitioning Java classes into separate groups. They act as a namespace, which is convenient when using third party code. Their main benefit is making the code more comprehensible. A more explicit superstructure, such as explicit package dependencies, doesn't seem necessary.


A RelationalWeenie viewpoint is to use database techniques to group the code by whatever grouping a given person wants. Individuals would use query techniques to produce the view they want for a given issue or developer task. There is no one-size-fits-all "correct" view. However, a few issues remain:


CategoryCodingIssues


EditText of this page (last edited May 18, 2007) or FindPage with title or text search