Conversation started Oct 25, 2016 at 15:26.
Oct 25, 2016 15:26
@jrh RE Verb(noun) vs. noun.Verb() – There is no real need for a syntactical distinction, e.g. Julia allows the former syntax, but it also uses multi-methods, which is a bit unusual. The whole verb vs noun distinction is only useful for OOP as a design approach, not for OOP as a concept or implementation technique.
The dot-notation becomes immediately obvious when you implement vtable-based OOP yourself in C. A vtable is a struct of function pointers. To call a method, you access the function pointer in the vtable struct, then also pass the object as invocant/this-parameter.
I've implemented an example here. Of course that uses a lot of dereferencing access
"->"
instead of normal struct access "."
, but that's just C for you. In C++, object pointers are rarely used – objects usually are either references which allow method calls with "."
, or are values that do not support polymorphic calls since their exact type is known at compile time.
Some later languages use
"->"
for method calls (Perl, PHP); most prefer dot notation (Java, C#, nearly everything else). Exceptions (well, actually they predate C++) are Smalltalk which uses juxtaposition ("object method", "object method: arg", "object everything: is named: arg"). And Objective-C, which uses the circumfix operator []
as in [object method]
, but is otherwise Smalltalk-like
Conversation ended Oct 25, 2016 at 15:37.
amon_OOP
Oct '1625
The Whiteboard
General Discussion for softwareengineering.stackexchange.com P...
Participants
- amon 85%
- enderland 14%
all times are UTC