At the first glance readOnlyFileNamed:ifNone: seems to be a useful primitive. But this having the file absent might be just one case. You could have ifNotReadable:, ifParentFolderNotReadable:. Also, an error when writing in a file may occur in many different situation (disk full, file read only, ...). You may also want to provide handler for each of these situation (e.g., writeFileNamed: aName with: stream ifDiskFull: [...] ifAlreadyExistingFile: [...]...

I like you idea, but to make it cover all different improper usage may be hard...

Cheers,
Alexandre


On 15 Aug 2008, at 03:38, Bill Schwab wrote:

Stef,

I agree you are improving on the existing code, but I would prefer
something like

 file := fd readOnlyFileNamed:name ifNone:[ ^self ].

This is analogous to #at:ifAbsent:, which does not set up an exception
handler and raise and handle an exception for something that is known to be handled locally. Then, just as #at: _does_ raise an exception, there
should be

readOnlyFileNamed:aBlock
 ^self
     readOnlyFileNamed:name
     ifNone:[ FileDoesNotExist signalWith:name. ].

#signalWith: might not be the correct syntax (too tired to look<g>), but hopefully it makes the point that exceptions should be raised, but there
should also be "long winded" methods that skip the overhead when it is
possible to do so.

Bill




Wilhelm K. Schwab, Ph.D.
University of Florida
Department of Anesthesiology
PO Box 100254
Gainesville, FL 32610-0254

Email: [EMAIL PROTECTED]
Tel: (352) 846-1285
FAX: (352) 392-7029

[EMAIL PROTECTED] 08/11/08 4:15 PM >>>
------------------------------------------------------
update10052
ISSUE #124
While browsing at referencer of FileDoesNotExistException, I
discovered the following pattern
that is used in many different places. I find this pretty ugly:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        file := [fd readOnlyFileNamed: keysFileName]
                        on: FileDoesNotExistException do:[:ex| nil].
        file ifNil:[^self]. "no keys file"
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

The use of exception is completely outwitted.

I would rather write:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
        [file := fd readOnlyFileNamed: keysFileName]
                        on: FileDoesNotExistException do: [:ex| ^ self].
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project


--
_,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:
Alexandre Bergel  http://www.bergel.eu
^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.






_______________________________________________
Pharo-project mailing list
[email protected]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

Reply via email to