The first thing one do when want to program is starting a new project.
In the fancy Scala world one can also use REPL, but this is not on the menu in this blog.

So what do we do in traditional way – structurally speaking?

Well, we create a project, this means that we, or our beloved IDE, creates a folder for a project. Than it creates a source folder and a folder for each package we define. If we want to create a class, a file must be created that represent this class.

Not every OO language has this strict rule:
one class = one file and package = folder
But many of them.

It makes things also much easier for IDE because than the logical structure of your program is equal to resource structure of your code. And every file is a compilation unit. So if you want to find a class find a file with the same name.

Now lets see how the genius deal with this kind of problem.

In the book “Programming in Scala (2nd edition)” chapter 13, you can find everything that you need to know about packages, and there is also a very cute example in listing 13.5 where it is possible to represent a pretty complex package structure in two files.

Why the heck somebody need such a messy thing?

Well at first we should realize that the binary produced from this two source files will be well structured, because you may be messy but the compiler won’t.

Now just imagine:
You creating a new project, creating a new source folder and before you start to propagate files and folders as a rabbit, you just create one file and draft the logical structure of your application in it. It is like drawing UML, or describing your project structure in a JSON like style.

You certainly can’t leave all classes in one file because its going to grow as mad, but for initial draft it feels pretty cool.

What also would be pretty cool is, if we had a file decomposition feature in the IDE. This way we could start with one file and than split it into many files in different directories when we need structure on resource level.

Another feature that is crucial for an IDE, that wants to support such a rich code organization feature, is to provide two perspectives on the code. One perspective from the resource point of view where you browse through files and not classes / packages. Another to represents structural/logical view on the project. But I guess this feature is already supported by the major IDEs in one or another way.

Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Before you submit form:
Human test by Not Captcha

© 2011 Max Blog Suffusion theme by Sayontan Sinha