Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to mark a method as pending to implement in Pharo?

Just wondering if you can mark a method as pending to implement in pharo, like you can do in java using "todo"

I'ts really hard for me to keep track of what's complete on pharo without something like that

like image 722
sir psycho sexy Avatar asked Mar 27 '19 21:03

sir psycho sexy


2 Answers

Methods whose implementation is still pending should send the notYetImplemented message like this:

methodImNotSureHowToImplement
  ^self notYetImplemented

if the unimplemented message gets sent anyway, it will signal a NotYetImplemented exception which will know the offending selector, #methodImNotSureHowToImplement in my example.

Note also that this will make it easy finding all methods that need to be implemented as senders of #notYetImplemented.

The implementation of #notYetImplemented is straightforward, thanks to the existence of NotYetImplemented.

notYetImplemented
  "Announce that this message is not yet implemented"
   NotYetImplemented signalFor: thisContext sender selector

Note also that NotYetImplemented is one of the subclasses of SelectorException which model several situations of similar kinds:

SelectorException
  NotYetImplemented
  PrimitiveFailed
  ShouldBeImplemented
  ShouldNotImplement
  SubclassResponsibility
like image 50
Leandro Caniglia Avatar answered Oct 03 '22 02:10

Leandro Caniglia


I found the solution for this by myself 2 days after asking about it, almost accidentally, just using the context menu option jump to test method over a method without any test. Pharo automatically generated an empty test with this:

self flag: #toImplement.
self assert: false`

the first line, which can be used not only on tests, gives me the behavior I expected as it automatically categorizes the method containing it on a flags category marked with a big "!" allowing to easily check at glance which methods are pending.

The second line forces test to fail and be shown on yellow which is pretty useful because if it's empty it will pass and be shown on green, probably leading to believe it's already done when is not the case. A similar effect can be achieved just using self notYetImplemented

I would probably start doing something like this with my incomplete methods:

MyIncompleteMethod

  self flag: #toImplement.  
  self notYetImplemented.`
like image 41
sir psycho sexy Avatar answered Oct 03 '22 02:10

sir psycho sexy