Does one "call a method" when polymorphism is used?

S

Stefan Ram

I wonder what the correct wording for the following situation is:

void print( final java.lang.Object object )
{ java.lang.System.out.println( object.toString() ); }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Without further thinking, one might say »The method
"toString()" is being called here.«.

However, according to the JLS, a methode is a specific member
of a specifc class. »toString« above does not denotate such an
entity, because for each invocation the method activated will
be determined only at run-time.

»toString()« yields a signature which is used at run-time to
choose a method. Sometimes (in the case of other identifiers
than »toString«) a method might not even be found in the
target object's class, so actually this is at most a »call
attempt«.

To call this »to call a method« might be misleading, because
it hides the indirection via late-binding and gives the wrong
impression that »toString()« indicates a specific method of a
specific class, while it really is only used to choose a
method at run time.

So, is there a more appropriate and precise wording?

The first two ideas that come to my mind would be to say »to
call a signature« or »to call an identifier«.

I believe that the last idea is better, because »identifier«
is used in the JLS3's description of the syntax of this
invocation pattern and it also takes into consideration that
the identifier expresses the intention of the author, while
there might be multiple possible signatures depending on minor
details for an identifier (like in »print("a")« and »print(2)«).

But »to call an identifier« is unusual and also not contained
in the usual sense of the verb to »call«. The second problem
might be addressed by using »to call /via/ an identifier«,
which also hints at the indirection.
 
M

Mark Space

Stefan said:
To call this »to call a method« might be misleading, because
it hides the indirection via late-binding and gives the wrong
impression that »toString()« indicates a specific method of a

I see "invoke" used a lot.
 
S

Stefan Ram

Mark Space said:
I see "invoke" used a lot.

Yes, but invoke /what/?

My question was based on the observation that
»to invoke a method« is too direct, because the
signature does not represent a specific method.
 
A

andrewmcdonagh

I wonder what the correct wording for the following situation is:

void print( final java.lang.Object object )
{ java.lang.System.out.println( object.toString() ); }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Without further thinking, one might say »The method
"toString()" is being called here.«.

However, according to the JLS, a methode is a specific member
of a specifc class. »toString« above does not denotate such an
entity, because for each invocation the method activated will
be determined only at run-time.

»toString()« yields a signature which is used at run-time to
choose a method. Sometimes (in the case of other identifiers
than »toString«) a method might not even be found in the
target object's class, so actually this is at most a »call
attempt«.

To call this »to call a method« might be misleading, because
it hides the indirection via late-binding and gives the wrong
impression that »toString()« indicates a specific method of a
specific class, while it really is only used to choose a
method at run time.

So, is there a more appropriate and precise wording?

The first two ideas that come to my mind would be to say »to
call a signature« or »to call an identifier«.

I believe that the last idea is better, because »identifier«
is used in the JLS3's description of the syntax of this
invocation pattern and it also takes into consideration that
the identifier expresses the intention of the author, while
there might be multiple possible signatures depending on minor
details for an identifier (like in »print("a")« and »print(2)«).

But »to call an identifier« is unusual and also not contained
in the usual sense of the verb to »call«. The second problem
might be addressed by using »to call /via/ an identifier«,
which also hints at the indirection.

From a OO PoV, the toString() is a 'Message' that is being sent to the
object. The object decides at runtime how to handle that Message,
depending upon the virtual nature of the method - i.e. has the method
toString() been over ridden?

An easy way of understanding this, is if you used Java's reflection
API to obtain a reference to the method from the obj's class.

Alternativitly, if you understand dynamically typed languages like
Python, Ruby, Smalltalk, etc., then these behave exactly like the
description above. With the code like "obj.2String()" compiling, but
failing at runtime as the is no method defined that can handle the
Message.

Andrew
Andrew
 
M

Mark Rafn

Stefan Ram said:
I wonder what the correct wording for the following situation is:
void print( final java.lang.Object object )
{ java.lang.System.out.println( object.toString() ); }
Without further thinking, one might say "he method
"toString()" is being called here."

Yup, that's what I call it, and what everyone I talk to calls it. Sometimes,
we say "invoke" rather than "call", but the object (of the sentence) is still
"the method toString on the Object referenced by object".
However, according to the JLS, a method is a specific member
of a specifc class.
"toString" above does not denotate such an entity, because for each
invocation the method activated will be determined only at run-time.

Different context. Defining a method and invoking a method are not the same,
and "method" can mean different things in different situations.
To call this to call a method might be misleading, because
it hides the indirection via late-binding and gives the wrong

Yup. Welcome to English. Almost no simple description is exactly correct.
And a lot of these ambiguities are far too ingrained to change, combined with
not actually harmful very often.

When you say "invoking a method starts with the VM determining the correct
method to invoke", it's obvious with a little thought that the two uses
of "method" in the sentence refer to different things.
So, is there a more appropriate and precise wording?

Not in common use. Where precision is needed, I'd recommend "declared method"
and "dispatched method". This is close to the distinction between
getMethods() and getDeclaredMethods() in java.lang.Class. Most of the time,
though, you can just say "method" and the listener will have to know what you
mean.
The first two ideas that come to my mind would be to say »to
call a signature« or »to call an identifier«.

identifier is wrong - there's only one type you can call, and it's a method.
signature isn't bad, but I doubt it'll catch on.
while
there might be multiple possible signatures depending on minor
details for an identifier (like in »print("a")« and »print(2)«).

Those details aren't minor - they can cause different code to be run as much
as any other signature change.
 
L

Lew

Stefan said:
Yes, but invoke /what/?

My question was based on the observation that
»to invoke a method« is too direct, because the
signature does not represent a specific method.

Sure it does.

It represents a specific method owned by a specific object.
void print( final Object object )
{ System.out.println( object.toString() ); }

You really don't need the "java.lang." everywhere.

This is 'out' "calling the method" toString() on Object 'object'.

Naturally 'object' is going to use its own implementation of the method.
That's the whole freaking point.
 
L

Lew

Lew said:
Sure it does.

It represents a specific method owned by a specific object.


You really don't need the "java.lang." everywhere.

This is 'out' "calling the method" toString() on Object 'object'.

I'm wrong. It's the object that owns print() calling the method.
 
A

A. Bolmarcich

Yes, but invoke /what/?

My question was based on the observation that
»to invoke a method« is too direct, because the
signature does not represent a specific method.

Then, how about "invoke a method on an object". The
method signature and class of the object and runtime
determines the specific method.
 
A

A. Bolmarcich

Then, how about "invoke a method on an object". The
method signature and class of the object and runtime
determines the specific method.

Oops, I better correct that typo.

Then, how about "invoke a method on an object". The
method signature and class of the object at runtime
determines the specific method.
 
M

Mark Space

Mark said:
Not in common use. Where precision is needed, I'd recommend "declared method"
and "dispatched method". This is close to the distinction between
getMethods() and getDeclaredMethods() in java.lang.Class. Most of the time,

I like "dispatch." As A. Bolmarcich pointed out, an early term used for
method invocation was "sending a message." And messages are also
dispatched.

However, I saw a lot of people get confused, thinking that the message
was actually passed between two separate threads of execution. So the
OO community hunted around for a better term and "invoke" is what they
came up with. (I think. History lesson taken with a chunk of salt.)
 
S

Stefan Ram

Mark Space said:
OO community hunted around for a better term and "invoke" is what they

According to my perception, »to invoke« is interchangeable
with »to call«. »To invoke« is also common in other
programming paradigms, such the procedural paradigm. One
»invokes« a »procedure« or a »function«. There is nothing
object-oriented about it.

For example,

»the semantic rules may even, in suitable
circumstances, invoke themselves recursively«

Revised Report on the Algorithmic Language
ALGOL 68

»The longjmp function is invoked to restore
a nonexistent environment«

ISO/IEC ISO/IEC 9899:1999, Programming languages -- C
 
L

Lew

Stefan said:
According to my perception, »to invoke« is interchangeable
with »to call«. »To invoke« is also common in other
programming paradigms, such the procedural paradigm. One
»invokes« a »procedure« or a »function«. There is nothing
object-oriented about it.

For example,

»the semantic rules may even, in suitable
circumstances, invoke themselves recursively«

Revised Report on the Algorithmic Language
ALGOL 68

»The longjmp function is invoked to restore
a nonexistent environment«

ISO/IEC ISO/IEC 9899:1999, Programming languages -- C

Either way - invoke a method, call a method - they're all fine, and all widely
accepted.
 
M

Mark Space

Stefan said:
»invokes« a »procedure« or a »function«. There is nothing
object-oriented about it.

Not object oriented. Just more than a standard call. "Call" is an
assembly language op-code that pushes a return address on the stack and
then load a new address in the program counter. (Also sometimes "js" or
"jsr".)

If it's more complicated than that, especially if it involves looking up
or search for bindings, then invoke is appropriate. For example:
»The longjmp function is invoked to restore
a nonexistent environment«

Longjmp definitely does something more complicated than just call or return.

That's my thinking anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,736
Latest member
zacharyharris

Latest Threads

Top