Saturday, June 05, 2004



Analogy between "directories/files in filesystems" and "packages/programs in programming languages"

The concept of organizing files into directories is an age-old concept. But also big enough to spark a discussion. It has provoked me to think and reflect on the different schools of thought. Here is the problem :

File naming convention to different formats - (viewable, printable and text only ) of a source file - Shrek_Characters.xml. How are these files used - In a website to display different views as chosen by a user.
Based on the 2 different schools of thought are the following 2 solutions:

Solution 1:



Directory
FullContent
Print
Text


File Name
Shrek_Characters.htm
Shrek_Characters.htm
Shrek_Characters.htm


Solution 2:


















Directory File Name
FullContent Shrek_Characters-fullcontent.htm
Print Shrek_Characters-print.htm
Text Shrek_Characters-text.htm


Problem Definition:
As one can notice the only difference between Solution 1 and Solution 2 is the names of the files (solution 2 appends the format to the filename) . Both 'schools of thought' agree on the importance of segregating the files by directories (or atleast I assume so). The point of contention is group 1 feels why should a file name be called differently when the differentiating factor is already the directory. While group 2 feels what if a 'print' version file gets accidentally moved to 'FullContent'.

I wanted to offer an unbiased opinion though I feel strongly about Solution 1. Hypothetically, lets assume there could be thousands of such files. So I started thinking more about it, because it is not just 1 file that would be in each of these directories. This is when I reflected on the concept of packages in Java. A set of classes are grouped in to packages based on their functionality/purpose in the overall system. There could be 2 packages called com.movies and com.charcaters that have the same class called ListAllNames, for instance. The function of the class ListAllNames is to list all the names based on certain criteria. Just because they are stored under different packages, wouldn't lead one to change the names of the class. This class finally gets stored under 2 different directories called movies and characters but under the same name. To avoid class conflict is one of the reasons, the concept of packages was formed. The concept of packages can be seen even in PERL and any OOP language.
So one can see the analogy between directories/files and packages/classes.