DenkzeitWiki

Suchen:

Aktuelle Änderungen Printable View Änderungen Bearbeiten

MetaProgramming > BooLanguage > IL > IntermediateLanguage > HackingPythonWithEmacs > SearchWiki > PythonIdioms > RubySprache > DomainSpecificLanguages > IronPython > AbstractionsLeak > Recursion > FirstClassFunctionsClear Trail
Main /

First Class Functions

ObjectOrientedProgramming
Closures

In a language supporting FirstClassFunctions, functions are objects - just like e.g. strings - which can be passed around (assigned to other variables) and called. Such a function may be bound to another object (thus called a 'method') and still be passed around.

Not all languages have FirstClassFunctions. C# does not, but provides Delegates. C++ and Java (and several other languages) have Functors or FunctionObjects. C and C++ also have FunctionPointers which, like normal pointers, can also be passed around. These are not type-safe, though.

AlanKay, the Guru that coined the term ObjectOrientedProgramming, stated that only language providing FirstClassFunctions are correctly called ObjectOriented. Sorry, I don't have a source for that statement, yet.

Update: I've found the quote - accidentally - in the book PracticalCommonLisp and it goes like this:

I invented the term object oriented, and I can tell you that C++ wasn't what I had in mind.


Python has FirstClassFunctions, bound and unbound. An example:
>>> class test(object):
...     def method(self, o):
...             self.o = o
...
>>> test.method
<unbound method test.method>
>>> test().method
<bound method test.method of <__main__.test object at 0x008D1870>>
>>> t = test()
>>> t.method
<bound method test.method of <__main__.test object at 0x008D1B70>>
>>> t.method(3)
>>> t.o
3
>>> delegate = t.method
>>> delegate(6)
>>> t.o
6



In quite many popular languages functions are not first-class but second-class citizens. They are the Kingdoms of Nouns. The programming-paradigm that reigns there could also be called ObjectObsessedProgramming.

Edit - BackLinks - Tags - Page Hist - Print - Changes - Home - Orphans - Help

Zuletzt geändert am 12.05.2009 19:55 Uhr und seit 7. April 2005 1516 aufgerufen.