Sunday, May 6, 2012

Java Tips 1 - Project Organization

Project Organization

Once you are becoming a expert programmer, two things will eventually happen:

You can now make bigger programs for bigger purposes.
You look at other's people code to learn something from them

This is the part when being organized with your code will help you, and other programmers, get along and learn from other people's work and don't get lost in the process. If you follow a few guidelines while writing your program, you will soon realize that after a while you will follow those guidelines almost automatically, and if, for example, you  leave out a project for a couple of months because something important had to be done, and you come back to it, you will be thankful with yourself for following the guidelines.

Now let's see some of the things we can do to stay organized:

Guideline No. 1: Project creation

At this stage try to create a project with a meaningful name, one that describes a little about what is it's main purpose.
Also keep your files organized in folders. The source files in the 'src' folder (same name as the package), the binary files in the 'bin' folder, if you are using images or documents keep them all in a folder name 'data', and the documentation of your project, that you can put it in a folder called 'docs'. This way you will quickly find the information every time you need it.

Once you have this structure created, keep your source files inside their own packages. What I usually do is create a package for the Graphic User Interface (named 'src.gui') and a package for the logic (named 'src.logic'), so most of my projects have two layers of functionality. You can create more layers to include Data Base transactions or Security Layers and so on, but I recommend to have at least two.

Finally, I would recommend not to mix the Eclipse's "workspace" folder with you projects' folders. Eclipse keeps it's session files in it's own workspace, with information about your working session, your preferences, and your projects. I like to keep my projects in my own folders depending on the topic I am working now, that way I can easily find it every time I need it. Doing so, I could properly tell you exactly where is a Java project that I made 5 years ago!!

Guideline No. 2: Naming convention