Where a message is sent from

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Where a message is sent from

Sean McGinty
How can I tell where a message was sent from while in a method? For instance, I have a class called Reminder that has a class method called todo: that receives a string:

Reminder >> todo: aString
Transcript show: aString.

With the following as an example:

SomeClass >> doSomething

Reminder todo: 'Fix this'.

When Reminder todo: in doSomething is invoked, how can I tell where todo: was sent from? 

Thanks

Sean



Reply | Threaded
Open this post in threaded view
|

Re: Where a message is sent from

Vassili Bykov-2
On 5/17/07, Sean McGinty <[hidden email]> wrote:
> How can I tell where a message was sent from while in a method?

thisContext sender printString

Reply | Threaded
Open this post in threaded view
|

RE: Where a message is sent from

Alexander Ivanov-2
In reply to this post by Sean McGinty
If your Reminder rely on knowledge about a sender, I would make it clear passing a sender as an argument:
 
Reminder >> todo: aString for: sender
    Transcript show: aString.
    "Use sender as you need"
 
SomeClass >> doSomething
    Reminder todo: 'Fix this' for: self.
 

Alex Ivanov
[hidden email]

 
 
-----Original Message-----
From: Sean McGinty [mailto:[hidden email]]
Sent: Thursday, May 17, 2007 6:10 PM
To: VWNC
Subject: Where a message is sent from

How can I tell where a message was sent from while in a method? For instance, I have a class called Reminder that has a class method called todo: that receives a string:

Reminder >> todo: aString
Transcript show: aString.

With the following as an example:

SomeClass >> doSomething

Reminder todo: 'Fix this'.

When Reminder todo: in doSomething is invoked, how can I tell where todo: was sent from?

Thanks

Sean



Reply | Threaded
Open this post in threaded view
|

Re: Where a message is sent from

Runar Jordahl
In reply to this post by Sean McGinty
If you are doing this for debugging, you might look at this post:
http://www.cincomsmalltalk.com/userblogs/runarj/blogView?showComments=true&printTitle=Logging_Context&entry=3254739381

Runar Jordahl

Reply | Threaded
Open this post in threaded view
|

Re: Where a message is sent from

David Lattimore
In reply to this post by Vassili Bykov-2
Vassili Bykov wrote:
> On 5/17/07, Sean McGinty <[hidden email]> wrote:
> > How can I tell where a message was sent from while in a method?
>
> thisContext sender printString
>  
The VW debugger inserts stack frames when you are stepping through
methods, so when debugging this will likely get a different result than
when you are not debugging.  This probably doesn't matter in this case,
but if it does, the other approach would be to put the thisContext
reference in the method that you care about and implement your method on
MethodContext.  For example:

MethodContext>>remindToDo: aString
    Transcript cr; show: aString, ': ', self printString.

someMethod
  thisContext remindTodo: 'Fix this'.

David

Reply | Threaded
Open this post in threaded view
|

Re: Where a message is sent from

Wolfgang Eder
In reply to this post by Sean McGinty
Sean McGinty wrote:

> How can I tell where a message was sent from while in a method? For
> instance, I have a class called Reminder that has a class method called
> todo: that receives a string:
>
> Reminder >> todo: aString
> Transcript show: aString.
>
> With the following as an example:
>
> SomeClass >> doSomething
>
> Reminder todo: 'Fix this'.
>
> When Reminder todo: in doSomething is invoked, how can I tell where
> todo: was sent from?
>
> Thanks
>
> Sean
>
>
>
Dear Sean,
you could also implement #todo: in Object
like this:

Object>>todo: aString
     Reminder todo: aString sender: self

and change your example:
SomeClass>>doSomething
     self todo: 'Fix this'

I suggest you stay away from thisContext
trickery if there are other ways...

Cheers
Wolfgang

Reply | Threaded
Open this post in threaded view
|

Re: Where a message is sent from

Reinout Heeck

>
> I suggest you stay away from thisContext
> trickery if there are other ways...
>

Why have #todo: print anything at all?

Reminders are meta information so you can use the tools you already  
have, like 'senders of'.

This way there is no need to even ponder an implementation for you  
reminders :-)

R
-




jas
Reply | Threaded
Open this post in threaded view
|

Re: Where a message is sent from

jas
In reply to this post by Sean McGinty
At 06:09 PM 5/17/2007, Sean McGinty wrote:

>How can I tell where a message was sent from while in a method? For instance, I have a class called Reminder that has a class method called todo: that receives a string:
>
>Reminder >> todo: aString
>Transcript show: aString.
>
>With the following as an example:
>
>SomeClass >> doSomething
>
>Reminder todo: 'Fix this'.
>
>When Reminder todo: in doSomething is invoked, how can I tell where todo: was sent from?


Hi Sean,

For the answer "as asked":
        See other posts in this thread (or find it buried in the following).

Taking your question at face value,
here is a quick rundown of the way
this issue is typically addressed.

There were hints, but it's worth a
further look.

One can get an awful lot of mileage
out of just these two techniques.
(season to taste, but sparingly.)
 
Regards,

-cstb


===============================================================
The really quick hacks: (lookup senders of #fixMe or #revisit).
The secret of success: avoid temptation to add more tag words.
Todo has two very distinct barks - so it pays to differentiate.
===============================================================


SomeClass>>doSomething
        #fixMe.
        ...
        " some broken code - need to fix it before we ship. "
        ...

SomeClass>>doSomething
        #revisit.
        ...
        " good enough for now, but could be improved - later. "
        ...


===================================================================
The above works just fine, until --  
suddenly, you're not in Kansas anymore.

You may say to yourself:
"This is not my beautiful house. How did I get here?"

The basic tagAlog idiom: (lookup senders of #flag: or #flag:with:)
===================================================================


SomeClass>>doSomething
        self flag: 'fix this'.
        ...


Object>>flag: something
        self whenLogging
                ifTrue: [self log: something]

Object>>flag: someoneOrSomething with: moreInfo
        self whenLogging
                ifTrue: [self log: someoneOrSomething with: moreInfo]

Object>>whenLogging
        ^self isLogging or: [self controlKeyIsDown]

Object>>isLogging
        " subclasses override this to turn logging on "
        ^false

Object>>log
        ^Transcript

Object>>log: something
        self loggerHeads: something.
        self log cr.

Object>>log: something with: moreInfo
        self      loggerHeads: something
                ; loggerTails: moreInfo

Object>>loggerHeads: deheads
        self log
                  nextPutAll: Timestamp now printstring
                ; nextPutAll: ' '
                ; nextPutAll: thisContext sender printstring
                ; nextPutAll: '>'
                ; nextPutAll: deheads printString

Object>>loggerTails: details
        self log
                  nextPutAll: '('
                ; nextPutAll: details printString
                ; nextPutAll: ')'
                ; cr


============================================
Optional multi-developer/project shortcuts.
Tradeoff: more things to lookup senders-of.

        sean works on 'foo'
        cstb works on 'bar'

        but assignments can change,
        over time, so:
============================================

SomeClass>>doSomething
        self flagAll: 'fix this'.
        ...
        self flagFoo: 'fix that'.
        ...
        self flagBar: 'add class comments'
        ...

Object>>flagAll: reminder
        self flag: #all with: reminder

Object>>flagFoo: reminder
        self flag: #sean with: reminder

Object>>flagBar: reminder
        self flag: #cstb with: reminder


Regards,

-cstb