Rationale for mandatory package statements

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Rationale for mandatory package statements

Simon Krajewski

short version: Why do we need a package statement for each .hx file if
the package structure is (necessarilly) derived from directory structure

Longer version: It struck me the other day that package statements seem
somewhat redundant, i.e. they merely state a structural information that
is constrained directly by another structure, the directory tree.
Whenever moving a class into a different package, the package statement
has to be updated as well which makes refactoring rather annoying.

I was wondering why we have to manually enter the package information
because as soon as the compiler reads the statement, the containing
source file and thus its directory tree location are already known. In
order to resolve the package, it would only have to traverse the dir
tree up to the first dir that's part of -cp and could implicitly
generate the package statement from that. Furthermore, relative import
statements would be possible by temporarily adding the current dir tree
position to the -cp when resolving.

I might be thinking too much in terms of directory trees, but this would
be so convenient for refactoring.


haXe - an open source web programming language