Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I know that

MyObject.myMethod();

is refered to as dot notation.

But what is

MyObject->myMethod();

called?

Also are their others?

share|improve this question
13  
In C++ it's Member dereference. Member can mean either a field or a method. – rwong Nov 17 '10 at 20:09
1  
I call it object notation.. – Fosco Nov 17 '10 at 20:12
8  
Why are all these apparent answers done as comments? – Peter Boughton Nov 17 '10 at 22:52
1  
@DevSolo: in C++, a '*' in front of a pointer is pointer dereference. There is no requirement that the dereferenced type is an object (like, dereferencing int*). For member dereference, the dereferenced type must be an object (class or struct). In fact, in C++ you can overload the -> operator of an object type. – rwong Nov 18 '10 at 5:52
3  
@Peter Boughton because comments that are wrong can't be downvoted! – Jarrod Roberson Feb 14 '12 at 20:10
show 6 more comments

16 Answers

It is often called pointer notation or arrow notation. Personally I prefer arrow because that is what it looks so others will know what you are talking about even if they have not heard the term before.

share|improve this answer
2  
"Arrow notation" is definitely clear - it doesn't describe the purpose, but does describe the syntax. The "Dot notation" advocated by others here is confusing for a notation that doesn't include a dot. – Steve314 Aug 31 '11 at 21:45
show 2 more comments

It's typically referred to as "pointer notation", at least in C/C++ circles.

[Adding] Used when the variable is a pointer and points to an address. That address is typically another variable, but can be a pointer to a function.

share|improve this answer
show 1 more comment

Why do you need a name? I can't think of a time I've actually said "dot notation". If have to describe it, for instance when pair programming, I'd just say "you need a dot" or "use an arrow there".

When reading C code, I tend to read object->method as "object at method", as in 'points at'. It just flows better than "object arrow method".

(However, in languages where @ is a legal syntax character this is probably confusing.)

share|improve this answer

Since you gave no context at all, I'll just muddy the waters further by saying that in C++0x when you need to tell the compiler your lambda's return type, you do that with a -> also:

[](int n) -> double { ...stuff ... }

Since those two characters mean different things in different languages, or even in different places in the same language, it's not surprising there's no single answer to " -> is called ___ notation".

I call the character "arrow" if I want someone to type it ("dash-greater-than" if I'm dealing with someone really inexperienced and confused), and I pronounce it "points to" when it's being used like your dot-notation example, and "returns" in the lambda example I just gave above.

share|improve this answer

Perl calls it method invocation. Used transparently, it's just like dot or method notation in other languages. But internally, it is syntactical sugar for function calls on classes, since Perl5 lacks real objects.

Package->method($arg);

# is the same as
Package::method('Package', $arg);

$object->method($arg);

# is the same as
ObjectClass::method($object, $arg);

Edit: Thanks to Sean for pointing out that I incorrectly referred to it as "indirect object notation". Indirect is when it doesn't use the arrow at all!

share|improve this answer
1  
Actually, indirect object notation in Perl is the notation that doesn't use the ->. The -> notation is called arrow notation. (See perlobj for details.) – Sean McMillan Aug 30 '11 at 19:45

In C++, . and -> are both sometimes called member access operators. If you need to distinguish between them you can call . the member access operator and -> the indirect member access operator. That terminology works out nicely, since the indirect member access operator (->) is a combination of the member access operator (.) and the indirection operator (*), i.e.:

foo->bar;

is the same as:

(*foo).bar;
share|improve this answer

In Haskell, F#, and other functional languages, the -> symbol is often used in function definitions. As in:

add :: Integer -> Integer -> Integer

The :: means "has type of" and the rest means "a function taking two Integers and returning an Integer." The reason the arrow separates both the arguments and the return type is not super complex, but involves a long side discussion on how functional languages work. So just trust me on this one. ;)

In Haskell the -> is also used for anonymous functions (called lambda functions) as well to separate the arguments from the function body.

I'm not sure how you'd "pronounce" it though. I usually translate function definitions into something like what I said above.

share|improve this answer
show 3 more comments

Conceptually both denote "part of". MyMethod is a part (member) of MyObject.

In languages like C and C++, where you can have objects and pointers to objects, the "." syntax is used with objects (and references) and "->" syntax is used with pointers.

share|improve this answer
show 2 more comments

Also are their others?

Yes of course. There's this notation in Objective-C:

[MyObject myMethod]

I like to call it the WTF-notation, but I suppose that's incorrect :D
Like Objective-C is inspired from Smalltalk, the WTF-notation is inspired from the OMGWTF-notation:

MyObject myMethod

This actually looks pleasant at first, but nested calls of methods with multiple arguments will just really give you the aforementioned feeling.

In accordance with those language's semantics you could maybe call them "message (passing) notation" or "(method) selector notation".

share|improve this answer
1  
Sometimes. You mostly don't use nested calls of methods with multiple arguments, and when you do, it's not hard to lay things out to minimise the pain. Decently written Smalltalk should look almost like English (or, apparently, nearly exactly like Turkish!). – Frank Shearar Nov 17 '10 at 21:14

If you're using PHP that's the same.

class Person 
{
    $name = "John";
}
$p = new Person();
echo $p->name; // John

Otherwise, pointer notation as mentioned.

share|improve this answer
show 1 more comment

If you're using C++ then it's used the same as a ., except that it's used with pointers.

MyClass myObject = new MyClass();
myObject.myMethod(); // Direct object usage
MyClass* myPointer = &myObject;
myPointer->myMethod() // Pointer-based usage

However in PHP since . is used as the string concatenation operator, -> is used for accessing member variables and methods.

$myObject = new MyClass();
$myObject->myMethod();
share|improve this answer

Also are their others?

Yes, there's also bracket notation:

MyObject['MyMethod']


This makes it possible to specify dynamic method/property names (omit the quotes and use a string variable), and even variable names that might otherwise be invalid.

It's also sometimes referred to as "array notation" and similar, due to arrays using this style too, even though it's not an array here.

share|improve this answer
show 1 more comment

In Clojure -> is the threading macro.

It is used to pass a value through a set of expressions, with each expresion determining the value to be passed to the next expression.

The value is that this enables you to compose sequences of of operations such as:

(-> 10
  inc 
  ((fn [x] (* 2 x)))
  (str " green bottles"))

=> "22 green bottles"
share|improve this answer

At least in C/C++, it could conceivably still be called a "dot" operator:

foo->bar is a shortcut for (*foo).bar

But yes, "arrow" (based on shape), "at" (another answer), and "to" (what I think of) are more common.

share|improve this answer

From a C standpoint, there's no official designation. I've seen "dot" and "arrow" (obvious), "member selection" (for both), "component selection" (for both), "whoziewhatsit" (you get the picture), und so weiter.

I prefer "member-" or "component access" over "dot" and "arrow" simply because it conveys what the operator does, but that's just me.

share|improve this answer

I've always called it the finger pointer.

share|improve this answer
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.