Hi,
Here is the implémentation of FAMIXFile>>numberOfCharacters numberOfCharacters <MSEProperty: #numberOfCharacters type: #Number> <MSEComment: 'Number of characters in a file.'> <derived> ^ self lookUpPropertyNamed: #numberOfCharacters computedAs: [ | result | result := self fileExists ifTrue: [ self sourceText size - self totalNumberOfLinesOfText + 1 ] ifFalse: [ 0 ]. result max: 0 ] I see some problems on this implémentation. IIUC, we take the size of the source text and we remove 1 for each line return. This is wrong because in case of CRLF the lines returns are two characters long. I think that it would be better to have: self sourceText lines ifEmpty: [ 0 ] ifNotEmpty: [ :lines | lines sum: #size ] But, I do not agree with the fact that we should remove the lines returns to the number of characters. They are characters, why should we remove them? I propose this implémentation: numberOfCharacters <MSEProperty: #numberOfCharacters type: #Number> <MSEComment: 'Number of characters in a file.'> <derived> ^ self lookUpPropertyNamed: #numberOfCharacters computedAs: [ self sourceText size ] This is because #sourceText already manage the case where the file exist or not. If I have no complain, I'll do this change. -- Cyril Ferlicot https://ferlicot.fr http://www.synectique.eu 2 rue Jacques Prévert 01, 59650 Villeneuve d'ascq France _______________________________________________ Moose-dev mailing list [hidden email] https://www.list.inf.unibe.ch/listinfo/moose-dev |
Cyril a meta remark\
Better define the block as a method so that we can reuse it.
concept of lines than the sources (if this has been extracted on Windows and analysed on a linux server).
At the end this is really the question of the definition of the “metrics”
-------------------------------------------- Stéphane Ducasse 03 59 35 87 52 Assistant: Julie Jonas FAX 03 59 57 78 50 TEL 03 59 35 86 16 S. Ducasse - Inria 40, avenue Halley, Parc Scientifique de la Haute Borne, Bât.A, Park Plaza Villeneuve d'Ascq 59650 France _______________________________________________ Moose-dev mailing list [hidden email] https://www.list.inf.unibe.ch/listinfo/moose-dev |
In reply to this post by CyrilFerlicot
I think that is dangerous. You will not have the same results if you change the platform (Windows or Mac). I think you should always consider that a line return is one char long even if it is a CRLF.
Vincent -----Original Message----- From: Moose-dev [mailto:[hidden email]] On Behalf Of Cyril Ferlicot Sent: vendredi 22 septembre 2017 15:13 To: Moose-related development Subject: [Moose-dev] FAMIXFile>>numberOfCharacters Hi, Here is the implémentation of FAMIXFile>>numberOfCharacters numberOfCharacters <MSEProperty: #numberOfCharacters type: #Number> <MSEComment: 'Number of characters in a file.'> <derived> ^ self lookUpPropertyNamed: #numberOfCharacters computedAs: [ | result | result := self fileExists ifTrue: [ self sourceText size - self totalNumberOfLinesOfText + 1 ] ifFalse: [ 0 ]. result max: 0 ] I see some problems on this implémentation. IIUC, we take the size of the source text and we remove 1 for each line return. This is wrong because in case of CRLF the lines returns are two characters long. I think that it would be better to have: self sourceText lines ifEmpty: [ 0 ] ifNotEmpty: [ :lines | lines sum: #size ] But, I do not agree with the fact that we should remove the lines returns to the number of characters. They are characters, why should we remove them? I propose this implémentation: numberOfCharacters <MSEProperty: #numberOfCharacters type: #Number> <MSEComment: 'Number of characters in a file.'> <derived> ^ self lookUpPropertyNamed: #numberOfCharacters computedAs: [ self sourceText size ] This is because #sourceText already manage the case where the file exist or not. If I have no complain, I'll do this change. -- Cyril Ferlicot https://ferlicot.fr http://www.synectique.eu 2 rue Jacques Prévert 01, 59650 Villeneuve d'ascq France _______________________________________________ Moose-dev mailing list [hidden email] https://www.list.inf.unibe.ch/listinfo/moose-dev _______________________________________________ Moose-dev mailing list [hidden email] https://www.list.inf.unibe.ch/listinfo/moose-dev |
On Sun, Oct 1, 2017 at 1:29 AM, Vincent BLONDEAU
<[hidden email]> wrote: > I think that is dangerous. You will not have the same results if you change the platform (Windows or Mac). I think you should always consider that a line return is one char long even if it is a CRLF. > Hi, You will have the same result because the sourceText method will return the same result independently of the plateform. What change depending on the plateform is the default line return character when you *write* a file. Here we only read source file without modifying them. (Or else you are doing more than just analysis) If you have a project that was written on Windows and analyzed on linux, you will get CRLF in the source code, and it will be two characters long even on linux. Counting one char even for CRLF make it impossible to build robust tools in top of Moose because we will always have shifts in the source code if we try to highlight some things. We already got bitten by that at Synectique multiple times. > Vincent > -- Cyril Ferlicot https://ferlicot.fr http://www.synectique.eu 2 rue Jacques Prévert 01, 59650 Villeneuve d'ascq France _______________________________________________ Moose-dev mailing list [hidden email] https://www.list.inf.unibe.ch/listinfo/moose-dev |
Free forum by Nabble | Edit this page |