[BUG] FileDirectory>>exists

Anthony Adachi adachipro at yahoo.com
Wed May 21 21:02:27 UTC 2003


Lukas Renggli wrote: 

>  Ok, these are just a few ideas to make
file-handling easier, dumped out
>  of my brain as SUnit tests:
  
Ah, okay things are a bit clearer now. I misunderstood
what you were trying to say before. I thought, as I
tried to indicate in the partial test I posted, you
wanted to have a special kind of class for handling
files created? That concept sounded like a good idea
to me. 

Tim Rowledge wrote:

>  > > idea would be to have a new class called
Filename that represent files
>  > > only. As a result, we would be able to move a
lot of stuff from
>  > > FileDirectory to Filename.
>  I pretty much agree, except that Filename should
represent file _names_
>  only. An actual open file should be represented by
some Stream object.

I know  Tim said file handling (or at least the
opening of files) should be the responsibility of a
stream class. However, I disagree as far as handling
files as complete entities though (i.e.- moving,
copying, renaming, ect.).

In the AppleScript Inheritance Object Model files and
containers (i.e.- directories/disks/folders) are
different kinds of objects. File and containers have
commands (messages) and properties (access methods to
instance variables) to which they both respond
(polymorphic). However, they have their own
responsibilities which they specialize in. They are
subclasses of item which one can use if one needs to
deal with both files and containers. 

The concept of working with an item within the file
system (i.e.- moving, copying, renaming, ect.) is a
separate idea than working on the contents of a file
(as one would do with a Stream).

This results in a very flexible system. I'm not trying
to suggest Squeak should follow the same Object
Hierarchy as AppleScript but it could serve as a
source of inspiration on how to make file & directory
entity handling easier in Squeak.

http://www.apple.com/applescript/

Lukas, your idea sounded intriguing since it sounded
like a potential starting point to refactor Squeak
towards a system which dealt with the handling of
directories and files in an easier manner. Perhaps,
something similar to AppleScript such as a parent
DirectoryItem class and
DirectoryNode/DirectoryContainer and DirectoryFile
subclasses. 

Is that something like what you had in mind at first?

If this is could be of interest I'll try to come up
with some tests which might illustrate better how this
could work in Squeak.

>  I'm sorry, my newsreader messed everything up. I
agree that SUnit tests
>  are most of the time much better to explain
expected behaviour, but one
>  could/should write hundreds more to explain the
complete behaviour of
>  Filename.

Yes, but it's a start. Also, in the end I doubt if one
would really need to demonstrate complete behaviour.
Just the basic intended behaviour of the implemented
features. A few good tests should be enough to give
people the idea on how to use a class. As well,
eventually tests which check everything that could
possibly break within reason for the class
implementor's sound of mind. I'm not trying to suggest
that it's easy to wind up with a good set of tests but
it is relatively easy to begin writing in a test first
manner. 

>  > By the way, are you familiar with test first
coding or
>  > Test Driven Development?
>  
>  Sure I am! As you have probably heard already I am
the developer of
>  SmallWiki and almost everything there has been
implemented like this.
>  Today I have just written the 200th test :-) .

Excellent! It's very encouraging to hear that.

> It is really a pleasure
>  to see them all running green, after fixing a bug
or doing several
>  refactorings.

Yes, there's great satisfaction in seeing all the
tests pass. A irreplaceable, major safety net when it
comes to refactoring. Not only do tests help in
locating and isolating bugs once an unanticipated bug
occurs tests can serve as documentation of that issue
for the future. Moreover, it's easier than trying to
monitor behaviour in a debugger and hoping for the
best. Makes one more productive, reduces stress, and
one lives longer in the end as a result. 

Thanks for making your intentions clearer through
tests,

Anthony

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com



More information about the Squeak-dev mailing list