On 2007-06-19, Bjoern Schliessmann
<[EMAIL PROTECTED]> wrote:
> Diez B. Roggisch wrote:
>> With other OOP languages you mean Java. Which does have static
>> methods because they lack the notion of a function by its own,
>> so the shoehorned them into their "everything is inside a
>> class"-paradigm.
>
> ACK, but doesn't C++ have static methods too?

C++ does have what it calls "static member functions".

class foo
{
  public:
    static void bar() { /* nada */ }
};

Python names a similar thing a @staticmethod (the name taken from
C++, obviously, since C++ originated the essentially meaningless
word-grouping "static member function" in order to reuse an
existing keyword).

// It may be called with two different syntaxes, as in Python:

void goo()
{
  // ...using the qualified name:
  foo::bar();
  // ...or with an instance of the class:
  foo f;
  f.bar();
}

In C++ they are used most often for factory functions, since they
conveniently have access to the class's private members, and
don't want or need an existing instance. Python seems to have
adopted this use-case (ConfigParser, for example), but without a
need for it (code organization?).

-- 
Neil Cerutti
I am free of all prejudices. I hate everyone equally. --W. C. Fields
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to