473,836 Members | 2,305 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is a function an object?

Is a function an object?
Nov 14 '05
14 1725
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.l earn.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.u k> 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_Keit h) 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******** ************@wi deopenwest.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
9604
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, while an instance of class C should be able to check all methods #defined in C, B and A. #------------------------------------------------
7
1467
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() <bind obj to func> return func() return wrapper()
9
3702
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 discuss how reflection does this, but I cannot find the syntax to do this. I have tried several code example off of gotdotnet and other articles. Can somebody please show me the code to do this?
3
14968
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) { document.images.src = eval("mt" +menu+ ".src") } alert("imgOff_hidemenu"); hideMenu=setTimeout('Hide(menu,num)',500);
2
7684
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 like mine to run immediately after it. So in the code below, what JS would i need to add to my "myfile.inc" page so that I could guarantee this behavior? <!-- main page --> <html> <head> <script type="text/javascript">
28
4349
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
2249
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
2145
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
3230
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 bastard so posting it before I forgot again... By taking this minimum code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head>
12
3026
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. The global variables and global functions are hidden to prevent from accessing by the programmers. All global functions share global variables. Only very few global functions are allowed to be reusability for the programmers to use. Few...
0
9656
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10821
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10571
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9358
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7773
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6973
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4441
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4001
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.