Le 17/8/16 à 22:11, Peter Uhnák a écrit :
On Wed, Aug 17, 2016 at 9:44 PM, stepharo <steph...@free.fr
<mailto:steph...@free.fr>> wrote:
Hi
I have a file
/Users/ducasse/PharoMooc/Subtitles/W1/C019SD-W1-sous-titres-EN/EN_C019SD-W1-S1.srt
and I would like to generate a new one with a different extension
/Users/ducasse/PharoMooc/Subtitles/W1/C019SD-W1-sous-titres-EN/EN_C019SD-W1-S1.vtt
Why not just myFile withExtension: 'vtt'
If you see my code you will see that I could not guess that it was
working on a fullpath.
Of course since I did not add a proper comment to this method, there is none
and learning is always more difficult.
I really hate that we have to read and understand the implementation of
a method to understand
what is does.
e.g.
f := '/tmp/file.txt' asFileReference.
"File @ /tmp/file.txt"
f withExtension: 'log'
"File @ /tmp/file.log"
Now I'm browsing FileReference and I do not find an easy way to do it.
It's an AbstractFileReference method.
/Users/ducasse/PharoMooc/Subtitles/W1/C019SD-W1-sous-titres-EN/
Why not just #parent? Some languages also use #dirname.
/Users/ducasse/PharoMooc/Subtitles/W1/C019SD-W1-sous-titres-EN/EN_C019SD-W1-S1
This one is the one hard to get… but how often do you need it? Is it
worth the extra method in the API?
If just for changing the extension, then there's #withExtension:
Proposal one:
We could add withoutExtension
withoutExtension
^ (self parent / self basenameWithoutExtension)
What is the use case for this?
To get everything except the extension. Is it not obvious?
How do you did it else?
Proposal two:
We could add withoutBasename
withoutBasename
^ self parent
I don't see a point of this method, why not just use #parent?
This is a helper.
parent is good for navigation now withoutBasename is good for
manipulation of parts.
It took me a while to think that I should use parent because I was
looking for something else.
You convinced me this library is perfect and I will keep these
extensions for me.
Proposal three:
Not sure that it is worth
(note that this is not a rename)
withNewExtension: anExtension
^ self parent / self basenameWithoutExtension
withExtension: anExtension
Is this somehow different than using #withExtension: directly?
It is the same. I will add a real comment to this method.
I hate so much libraries that do not have comments (I'm fed up to lose
my time documenting undocumented library).
Since I stupidly wrote also the FS chapter I missed such scenario since
I was exhausted to reverse engineer and comment.
So now this is not in the documentation. Easy and revealing the poor
coverage of our documentation.
Obviously since I'm with Sven one of the few persons that seem concerned
with such aspect.
Now I will not work on documenting others code anymore.
Peter