[Pharo-project] ugly code related to files management
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]. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= If some of you agree, I will add an issue and fix where this occurs (e.g., CompiledMethod>>timeStamp, FileDirectory class>>retrieveMIMEDocument:, FileUrl>>retrieveContents, ResourceManager class>>loadResource: urlString, fromCacheFileNamed: fileName in: dir, ResourceManager class>>lookupCachedResource: cachedUrlString ifPresentDo: streamBlock, SecurityManager>>loadSecurityKeys) Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
Alexandre Bergel wrote:
While browsing at referencer of FileDoesNotExistException, I discovered the following pattern that is used in many different places. I find this pretty ugly:
I think the pattern is a result of me basically keeping the original method structure/pattern when rewriting the file creation code to use the Exception handling. So any clean-up/improvement is welcome :-) Michael
Hi! It is now the Issue #124 on google code. I also propose some refactoring under the name SLICE- FixingUglyCodeRelatedtoFiles In PharoInBox Cheers, Alexandre On 30 Jul 2008, at 12:09, Alexandre Bergel wrote:
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]. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If some of you agree, I will add an issue and fix where this occurs (e.g., CompiledMethod>>timeStamp, FileDirectory class>>retrieveMIMEDocument:, FileUrl>>retrieveContents, ResourceManager class>>loadResource: urlString, fromCacheFileNamed: fileName in: dir, ResourceManager class>>lookupCachedResource: cachedUrlString ifPresentDo: streamBlock, SecurityManager>>loadSecurityKeys)
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
excellent! I will have a look at that! Stef On Jul 30, 2008, at 2:06 PM, Alexandre Bergel wrote:
Hi!
It is now the Issue #124 on google code. I also propose some refactoring under the name SLICE- FixingUglyCodeRelatedtoFiles
In PharoInBox
Cheers, Alexandre
On 30 Jul 2008, at 12:09, Alexandre Bergel wrote:
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]. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
If some of you agree, I will add an issue and fix where this occurs (e.g., CompiledMethod>>timeStamp, FileDirectory class>>retrieveMIMEDocument:, FileUrl>>retrieveContents, ResourceManager class>>loadResource: urlString, fromCacheFileNamed: fileName in: dir, ResourceManager class>>lookupCachedResource: cachedUrlString ifPresentDo: streamBlock, SecurityManager>>loadSecurityKeys)
Cheers, Alexandre -- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
-- _,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;: Alexandre Bergel http://www.bergel.eu ^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;._,.;:~^~:;.
_______________________________________________ Pharo-project mailing list Pharo-project@lists.gforge.inria.fr http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project
participants (3)
-
Alexandre Bergel -
Michael Rueger -
Stéphane Ducasse