27

I understand that according to the C++ spec there is no such thing as a "method", and some (many? most?) C++ programmers consider "method" to be a Java-ism. On the other hand, even on a C++ forum people seem to talk about methods without twitching. I am looking for known conventions or common practices regarding this terminology.

I am documenting an API that has both C++ and Java versions. The developers actually kept the class and method/member-function names the same between the two, presumably for expedience in porting and testing. Because of this, some of what needs to be documented about these APIs sits "above" the choice of language; I need to be able to talk in general about Foos and Bars, with their baz() and mumble()...methods?

If I talk about methods Java programmers will consider it natural and, it appears, C++ programmers will probably understand but some will consider it to be incorrect. My question is: how heinous is this in practice? How are C++ member functions conventionally talked about in "general OOP" contexts, as opposed to C++-specific ones? Is there a better way to talk about member functions in a way that's not incorrect for either language? ("Member functions" is a little verbose.)

This isn't an opinion survey; I'm trying to determine if there are actual conventions or common practices to address this problem.

I am aware of this question, but it's about OOP in general and doesn't ask about specific languages.

3 Answers3

21

Well, you're not going to get executed for it.

The complaint in the C++ world is not one of pedantic correctness: it's one of ambiguity. There are so many different kinds of "methods" out there in the wilderness depending on what domain you're talking about, that a bunch of us prefer to stick to standard terminology to avoid misunderstandings later. That means, roughly, "static/[non-static] [pure] virtual/[non-virtual] member/[free] function".

If you write "method" in your documentation instead, some C++ programmers may complain that it's not really clear what you're talking about, or worry that if you're not familiar with this C++ convention, what others are you missing?

But I'm sure there are millions of professional C++ programmers who themselves have no idea that this is even a thing. It's a big ol' world.

You're not going to get executed for it.

13

Why don't you include an explanation (very much like you did in your question) in the introductory part of the documentation, e.g. a Conventions section? Then you could explain that the term "method", as used in your documentation, is meant in the generic sense of method (Java), member function (C++), ... since the documentation applies to all implementations.

sceaj
  • 324
  • 1
  • 5
4

Eiffel calls them Routines or Features, C++ calls them Member Functions, and (almost) every single other OO language ever created in the entire history of computing, both before and after C++ calls them Methods, so that latter term should generally be understood even by C++ (and Eiffel) programmers, unless they really have never heard of Simula, Smalltalk, Self, Objective-C, Newspeak, Java, C#, VB.NET, PHP, Python, Ruby, ECMAScript/JavaScript, Scala, CoffeeScript, …

Jörg W Mittag
  • 104,619