Take the 2-minute tour ×
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 referred to as 'dot notation'.

But what is

MyObject->myMethod();

called?

Also, are there others?

share|improve this question

closed as primarily opinion-based by MichaelT, gnat, Bart van Ingen Schenau, Alex Feinman, Dan Pichelman Feb 7 at 21:23

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

14  
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
9  
Why are all these apparent answers done as comments? –  Peter Boughton Nov 17 '10 at 22:52
3  
What language are you talking about? –  Jonas Dec 12 '11 at 12:27
4  
@Peter Boughton because comments that are wrong can't be downvoted! –  Jarrod Roberson Feb 14 '12 at 20:10
show 6 more comments

15 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
    
"Pointer notation" is not really good name, because one of the most prominent languages using this is PHP :) –  Matěj Zábský Feb 14 '12 at 21:03
    
Also "arrow" reads better. Take x->y and read as "x arrow y" –  Thomas Eding Oct 17 '12 at 20:28
    
+1: I've pretty much always heard "arrow" notation in the context of a language that uses it. "object notation" is fine, but misleading as it could be used in a language where that doesn't represent an object. (I don't call ( an "opening parameter thingy", for instance). –  haylem Jun 8 '13 at 11:51
add comment

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
    
In JavaScript and C#, it's called "dot notation" or "member access" because it's the most common means of doing that. In C# it's basically the only way since all variables are treated (mostly) like references. In JS, you also have the subscript notation to access members, like: object["member"] –  CodexArcanum Nov 17 '10 at 21:21
add 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
add comment

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
add comment

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
add comment

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
add comment

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
add comment

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
    
add is a function taking an Integer and returning a function that takes and Integer and returns an Integer. Easy to explain. :) But in this case, I think I'd pronounce it, "implies," borrowing the maths term since, in fact, the function taking an Integer implies a result that is a function that takes and Integer and in turn implies an Integer as the result of its computation. –  greyfade Nov 17 '10 at 21:38
    
I figured if I tried to explain the "returns a function" thing I'd wander off into a lecture on first-class functions, currying, and all kinds of fun stuff. Also, "implies" sounds like an excellent fit. I like that very well. –  CodexArcanum Nov 17 '10 at 21:54
    
"goes to" also seems to work well. –  Jörg W Mittag Nov 20 '10 at 14:58
add comment

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
    
I have to disagree. While it is part of, that's not what the notation is saying. It says something like "tell MyObject to do MyMethod" or "ask MyObject for its MyVariable". You're not declaring the part-of-ness there, you're using it. –  Kate Gregory Nov 20 '10 at 13:43
    
Well, I didn't say it declares it. It expresses it. And it does not denote function call (which is denoted by the parenthesis). Consider that the same syntax -> can be used for access, as in MyObject->MyMember = something. –  Ziffusion Nov 20 '10 at 14:05
add comment

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
    
PHP doesn't use dot notation or pointers, which is why this is true. The PHP devs have gone to great lengths to give operators one meaning (although + works on arrays as well as numbers) –  Alan Pearce Nov 17 '10 at 20:00
add 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
add comment

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
    
It's also sometimes referred to as "indexing" as that is the term used for the argument in the brackets sometimes. The object could be a dictionary which is slightly different from an array for another possibility here. –  JB King Aug 31 '11 at 20:30
add 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
add comment

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
add comment

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
add comment

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