473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Is a function an object?

Is a function an object?
Nov 14 '05 #1
14 1689
On Sun, 15 Aug 2004 18:02:17 -0700, "E. Robert Tisdale"
<E.**************@jpl.nasa.gov> wrote:
Is a function an object?


By OOP convention and general connotations, I'd say no. We equate
functions to verbs and objects to nouns, and demand an actor or locus
(noun) as a thing that can perform the function (verb).

That said, it doesn't take much to reify any function into a trivial
object that does nothing but that function, and a variety of other
hacks and intertranslations to other frameworks should be easy enough
to propose.

And why might you ask?

J.

Nov 14 '05 #2
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote:
Is a function an object?


"A class can be thought of as a C-style function that can maintain state
between invocations in a thread-safe manner and can also provide
multiple services. If there were exactly one instance of a class, and
all its member functions except for exactly one public member function
were removed, the result would be a C-style function (the object's
member data would correspond to static data that is local to the
function.)" -- Marshall Cline et al. __C++_FAQs__ 2nd ed.
Nov 14 '05 #3
On Sun, 15 Aug 2004 18:02:17 -0700, "E. Robert Tisdale"
<E.**************@jpl.nasa.gov> wrote:
Is a function an object?


It depends! In languages like Python functions are objects in
their own right and can be queried for properties etc. Also in
several languages code blocks can be defined and treated aas
objects - Ruby, Lisp and Smalltalk are examples.

OTOH most OO practitioners equate functions with the methods of
an object rather than as first class objects in their own right.

HTH,

Alan G
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld
Nov 14 '05 #4
I like Alan's explanation. He correctly prefaces it with, "It depends!"
Functions existing as objects themselves is a powerful concept that escapes
many programmers. It is worth investigating.
Nov 14 '05 #5
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> writes:
Is a function an object?


Warning: This question was cross-posted to comp.object and
comp.lang.c. (I'm reading it in comp.lang.c.)

In C terms, the answer is no, a function is not an object. We've just
had a rather tiresome thread on the subject. The C standard has a
reasonably precise definition of the term "object", and a function
clearly does not qualify. (Note that the C standard's definition of
"object" is not related to object-oriented programming; it's basically
just a region of data storage, such as a variable.)

Followups directed to comp.object.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
E. Robert Tisdale wrote:
Is a function an object?


Is a barnacle a ship?

--
Phlip
http://industrialxp.org/community/bi...UserInterfaces
Nov 14 '05 #7
E. Robert Tisdale wrote:
Is a function an object?


Note that Tisdale is trolling by posting this question to two newsgroups
where the answer is different. I suppose he wants us to snip at each
other. In C, a function is not an object. Trollsdale is trying to get
the comp.object folk to tell the C folk that they are clueless. Please
don't oblige him. I have set the followups to news:comp.lang.c only,
since that's where I am. If folk on comp.object want to discuss this
question, I suggest they change the newsgroup or follow-up headers to
their newsgroup only.
Nov 14 '05 #8
Phlip wrote:
E. Robert Tisdale wrote:

Is a function an object?

Is a barnacle a ship?


Great album!

http://www.blackvelvet.be/barnacle-e.htm
Nov 14 '05 #9

"Thomas Gagne" <tg****@wide-open-west.com> wrote in message
news:Cb********************@wideopenwest.com...
I like Alan's explanation. He correctly prefaces it with, "It depends!"
Functions existing as objects themselves is a powerful concept that escapes many programmers. It is worth investigating.


Whatever you call them, functions as those from C or many FPLs are not
objects. "Functions existing as objects" may be interesting to _think_ of
as functions (in the abstract), but are certainly not functions in the
traditional sense.

l8r, Mike N. Christoff

Nov 14 '05 #10
E. Robert Tisdale wrote:
Is a function an object?


Mr. Tisdale,

Please define "object". Then define "function".

If, in your definitions, a function can fit in the realm
of, in your definition, of an object, then so mote it be.

Secondly, why does it matter?

I've used functions as objects (or more precisely,
pointer to functions). I've used objects as functions
(more precisely, pointers to functions that reside in
a structure). Whether an object is a function or a
function is an object has never precluded me from
accomplishing my programming task.

I'd rather be programming than debating the philophics
of programming.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book

Nov 14 '05 #11
Thomas Matthews wrote:
E. Robert Tisdale wrote:
Is a function an object?

Mr. Tisdale,

Please define "object".


Trollsdale posted to two newsgroups. In one of them, comp.lang.c,
"object" is defined by the standard defining the language. He knows
this. He also knows that a function is not an object in C. I have
already asked people not to get sucked into this attempt to set people
from comp.object, who have no more reason to know C than any other
language, against the people from comp.lang.c, for whom there is nothing
to discuss. *Please* don't play Trollsdale's game. If you must discuss
this boring question, set the newsgroups or at least followups to point
to your newsgroup only.

Follow-ups set to comp.lang.c
Nov 14 '05 #12

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote

Is a function an object?

It comes down to semantics. In the C standard, "object" is defined as data
occupying a contiguous region of storage. However if you said "what object
does that pointer point to?" and someone replied "it's a function pointer to
printf()" most people would accept the exchange as grammatical.

In C++ you can have "function objects" which are a template-safe form of
function pointer.

In C, given approriate support, you can create data objects which specify
functions. For instance you could write a parser that calculates a function
of x and y, written in mathematical notation.
Nov 14 '05 #13
"Malcolm" <ma*****@55bank.freeserve.co.uk> writes:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote

Is a function an object?

It comes down to semantics. In the C standard, "object" is defined as data
occupying a contiguous region of storage. However if you said "what object
does that pointer point to?" and someone replied "it's a function pointer to
printf()" most people would accept the exchange as grammatical.

In C++ you can have "function objects" which are a template-safe form of
function pointer.

In C, given approriate support, you can create data objects which specify
functions. For instance you could write a parser that calculates a function
of x and y, written in mathematical notation.


If you're referring to a data structure that can specify the
evaluation of some function, you can certainly do that, but it's not
strictly speaking a "function" in the C sense.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #14
Thomas Gagne <tg****@wide-open-west.com> wrote in
news:Cb********************@wideopenwest.com:
I like Alan's explanation. He correctly prefaces it with, "It
depends!" Functions existing as objects themselves is a powerful
concept that escapes many programmers. It is worth investigating.


Yup. I have a fairly substantial numerical methods package (originally
Smalltalk, now Java) that does function calculations, derivatives, interval
calculations, statistics, blah blah blah, where functions are objects and
practically everything else is done with the Visitor pattern.

So roughly, if you have a function that is a "one-time" thing that belongs
to another object, make it a method. But if you have a function that is
going to be used for several things, then promote it to a first-class
object.
Nov 14 '05 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fernando Rodriguez | last post by:
Hi, I need to traverse the methods defined in a class and its superclasses. This is the code I'm using: # An instance of class B should be able to check all the methods defined in B #and A,...
7
by: vegetax | last post by:
I i need a decorator that adds a local variable in the function it decorates, probably related with nested scopes, for example: def dec(func): def wrapper(obj = None): if not obj : obj = Obj()...
9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
2
by: laredotornado | last post by:
Hello, I am looking for a cross-browser way (Firefox 1+, IE 5.5+) to have my Javascript function execute from the BODY's "onload" method, but if there is already an onload method defined, I would...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
5
by: Daz | last post by:
Hi everyone. My query is very straight forward (I think). What's the difference between someFunc.blah = function(){ ; } and
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
7
by: VK | last post by:
I was getting this effect N times but each time I was in rush to just make it work, and later I coudn't recall anymore what was the original state I was working around. This time I nailed the...
12
by: Bryan Parkoff | last post by:
I write my large project in C++ source code. My C++ source code contains approximate four thousand small functions. Most of them are inline. I define variables and functions in the global scope....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.