Re: [Pharo-project] [MethodTrailer] #getSourceCodeBySelector: and #getSourceCodeByIdentifier: are not implemented
I vote for removing any dead code. Less code, less bugs. Less code, easier to understand. On May 12, 2011, at 3:45 PM, Mariano Martinez Peck wrote:
If we see CompiledMethodTrailer >> sourceCode "Answer the source code of compiled method. Note: it does not attempts to read from source files using sourcePointer, nor reconstruct the source code using temp names"
(kind == #EmbeddedSourceQCompress or: [ kind == #EmbeddedSourceZip ]) ifTrue: [ ^ data ].
kind == #SourceBySelector ifTrue: [ ^ method methodClass getSourceCodeBySelector: method selector ].
kind == #SourceByStringIdentifier ifTrue: [ ^ method methodClass getSourceCodeByIdentifier: data ].
^ nil
But neither #getSourceCodeBySelector: nor #getSourceCodeByIdentifier: are implemented. In fact, it is easy to modify their test and make them red. Change #testSourceBySelectorEncoding or #testSourceByIdentifierEncoding and add a send to #sourceCode. Example:
testSourceBySelectorEncoding
| trailer |
trailer := CompiledMethodTrailer new.
trailer setSourceBySelector.
self assert: (trailer kind == #SourceBySelector ). self assert: (trailer size = 1). trailer sourceCode.
So...I don't know why they are not implemented, but if this was work "unfinished", we should at least make that clear and not to appear that it is supported but at the end it is not. So, if that's the case, I suggest to put nice comments explaining that and in addition implement:
Behavior >> getSourceCodeBySelector: ^ self notYetImplemented
Behavior >> getSourceCodeByIdentifier: ^ self notYetImplemented
What do you think ?
-- Mariano http://marianopeck.wordpress.com
-- Marcus Denker -- http://www.marcusdenker.de INRIA Lille -- Nord Europe. Team RMoD.
For #getSourceCodeByIdentifier: the idea was to introduce a source manager, which could manage source code by using some arbitrary IDs. Then you can store source code in database or on web.. depending how source manager is implemented. And for getSourceCodeBySelector: i did a trick to actually answer the source modified by comment (if method is originally comes from trait) so for example when method belongs to trait, then you will see something like: "This method implemented in TMyTrait" fooo ^ self then you will think twice before modifying such methods, because if you do that, you will replace it in class where you doing, but maybe you should do it in trait. But this change were not integrated. On 12 May 2011 16:30, Marcus Denker <marcus.denker@inria.fr> wrote:
I vote for removing any dead code. Less code, less bugs. Less code, easier to understand.
On May 12, 2011, at 3:45 PM, Mariano Martinez Peck wrote:
If we see CompiledMethodTrailer >> sourceCode   "Answer the source code of compiled method.   Note: it does not attempts to read from source files using sourcePointer,   nor reconstruct the source code using temp names"
  (kind == #EmbeddedSourceQCompress or: [ kind == #EmbeddedSourceZip ]) ifTrue: [     ^ data ].
  kind == #SourceBySelector ifTrue: [     ^ method methodClass getSourceCodeBySelector: method selector ].
  kind == #SourceByStringIdentifier ifTrue: [     ^ method methodClass getSourceCodeByIdentifier: data ].
  ^ nil
But neither #getSourceCodeBySelector: nor #getSourceCodeByIdentifier: Â are implemented. In fact, it is easy to modify their test and make them red. Change #testSourceBySelectorEncoding or #testSourceByIdentifierEncoding and add a send to #sourceCode. Example:
testSourceBySelectorEncoding
  | trailer |
  trailer := CompiledMethodTrailer new.
  trailer setSourceBySelector.
  self assert: (trailer kind == #SourceBySelector ).   self assert: (trailer size = 1).   trailer sourceCode.
So...I don't know why they are not implemented, but if this was work "unfinished", we should at least make that clear and not to appear that it is supported but at the end it is not. So, if that's the case, I suggest to put nice comments explaining that and in addition implement:
Behavior >> getSourceCodeBySelector: ^ self notYetImplemented
Behavior >> getSourceCodeByIdentifier: ^ self notYetImplemented
What do you think ?
-- Mariano http://marianopeck.wordpress.com
-- Marcus Denker  -- http://www.marcusdenker.de INRIA Lille -- Nord Europe. Team RMoD.
-- Best regards, Igor Stasenko AKA sig.
participants (2)
-
Igor Stasenko -
Marcus Denker