Talk:Object-oriented programming/Archive 3
![]() | This is an archive of past discussions about Object-oriented programming. Do not edit the contents of this page. If you wish to start a new discussion or revive an old one, please do so on the current talk page. |
Archive 1 | Archive 2 | Archive 3 |
Physical existence of an "object" - is it unecessary baggage? - can occams razor help?
Try as I might, I have not yet come across any instance (definition) of what an object is - in physical terms. I understand that OOP defines objects in some physical sense (rather than a virtual data definition) but I have yet to come across an actual example of how this manifests itself internally in the OOP language. I think I have seen these objects in an 'exported' sense - with seemingly long strings of (comma separated?) text attributes - but what of its internal representation? For example -
- how large is a (typical) object definition (in bytes)?,
- does it have an inherent or implied structure or OOP standard? (and is this portable?),
- who decides what attributes it holds and in what (optimized?) form?,
- how much data is involved when accessing an object?
- how much processing is involved in decoding the object at execution time?
Since conventional programs can (and do) perform the same tasks as any OOP written program - without the need for any physical objects - this seems to imply that the physical objects themselves are a case of unecessary 'baggage' (requiring additional processing themselves). Using occams razor therefore, these pieces of baggage can therefore be safely removed and a more optimum solution used to provide algorithmic efficiency. This optimum solution, I would suggest, is the much simplified "conventional" programming paradigm that grew up around the first computers - unsurprisingly - as the most 'natural' way to program them.
If someone has a real life example of how an object manifests itself physically (in a particular language) perhaps they would be good enough to highlight a simple example of it here for everyone to compare with a conventional solution. It would be useful to answer the questions above in relation to their example also. If the example is good enough to serve as a generic illustration, of an OOP object perhaps they might also include it into the article itself to educate all of us? It would also be nice if the example refrained from the much overused animal metaphores and restricted itself to more real-life scenarios such as simple addition of two values (unless of course you think I am 'barking up the wrong tree' or just simply barking!) ken (talk) 11:11, 21 August 2009 (UTC) Two weeks have passed since my post above. No sign yet of a response! Isn't there anyone who can defend the OOP 'paradigm' with a concrete example of what constitutes an object in reality (at least in one language) and then go on to explain the mechanics of how this is superior to a more conventional imperative programming approach using a real life example. Since I posted the above, the thought occurs to me that such a physical object must, of necessity, be an object itself - leading to a "vicious" infinite regression of objects, each describing themselves. See also my comments in Talk: Object(computer science) Can we implement OO in any language?!!ken (talk) 09:33, 5 September 2009 (UTC).
- Nobody replied because it's not worth replying to. See the banner at the top of this talk page? This discussion page is meant strictly to improve this article. Wikipedia is not a forum for debating hot topics. Do you have some concrete improvement to propose? Pcap ping 10:57, 5 September 2009 (UTC)
I would have thought that an example of what an 'object' is, is quite central to the concept of object-oriented programming. If nobody can provide one it is, to say the least, quite peculiar. Presumably if you are so confident that there is no improvement that can be made to the article, you can either provide a link to what I am asking for on some other published site or can point to the place in the existing article that answers my question.ken (talk) 15:05, 6 September 2009 (UTC)
- Where does this article discuss the "physical existence" that you debate? I'm unable to find it... Pcap ping 15:52, 6 September 2009 (UTC)
That is precisely the point! The article linked to in the introduction (i.e. object (computer science)) describes the OO concept of "'physically' bringing together the data components with the procedures that manipulate them". In any case, it would be difficult to see how an (OO) object could have any reality without this being the case (essentially being a combined data description and a function pointer). However, how this exactly is implemented is not shown by example - in any language in either article - despite the fact that (OO) objects obviously can be manipulated independently of the underlying 'target' object (the data) and therefore must have some physical existence. —Preceding unsigned comment added by Kdakin (talk • contribs) 19:07, 6 September 2009 (UTC) Two weeks later! On my tedious search for an answer to my question, I came across this java topic [1]which seems to at least confirm my belief that OOP objects do indeed have a physical existence. If they have a length in bytes they surely must contain something! The obvious question, which I am still short of an answer to is, precisely what? It reminds me of the question "How long is a piece of string" - at least I now know it has a length - now please what is the string made of? (and please no flippant answers like green cheese or quantum soup or quarks!) ken (talk) 09:19, 21 September 2009 (UTC)
- Its data members, and a vptr, is one possible answer. But these are implementation details, and not really important to such an abstract topic as this. Regards, decltype (talk) 09:49, 21 September 2009 (UTC)
Sorry Decltype, but I think telling me that there are pointers (rather obviously!) embedded within 'objects' is not the answer I am looking for. I also believed that objects pointed to 'data members' and did not actually contain them. Why do you think this is an 'abstract topic' and not a real one? The whole point of the question is to ask why there appears to be no example of what EXACTLY an object is - when implemented (and incidentally - how much memory and processing overhead this represents). To explain it by saying it is 'abstract' and just an 'implementation detail', is avoiding the very relevant question of precisely that. If you don't actually personally KNOW the answer (from the experience of a compiler writer for instance), why bother to attempt a 'possible' answer?ken (talk) 18:13, 21 September 2009 (UTC)
- That's not so obvious to me. An object need not contain any pointers, and most certainly not a vptr. However, this is one common way of implementing virtual functions (which some would say are vital to OOP), and causes an overhead the size of a pointer. However, as the vtable article (hopefully!) tells you, this is just one possible way of implementing late binding. Now, in most C++ implementations, there will be no overhead except for the vptr (in the presence of virtual functions), and the caveat that even an object of class type with no member subobjects must occupy at least one byte (with one exception). Apart from that, the objects contain their base class(es), and their member subobjects, and not pointers, unless the member subobjects are themselves pointers. However, even the simplest class may (or may not) contain unnamed padding. Most compilers allow you to manually adjust alignment. Thus, the object layout can be completely different even for two executables created from the same source code with the same compiler, and the answer to the question of how much memory overhead there is for each object remains the same: It is entirely up to the implementation. Regards, decltype (talk) 06:25, 22 September 2009 (UTC)
Thank you Decltype, I am now (ever so slowly) getting a beakdown of an 'object'
So, now I know that:-
- objects are at least one byte long (except in one case apparently)
- true, but this is very C++-specific. The exception is the Empty base class optimization. The fact that not even I have bothered to create an article on it yet, indicates that it's not that significant.
- objects may have automatic, or manually specified, padding
- Yes. The article seems to give a good overview, so no additional comments
- objects 'contain' their base class(es), and their member subobjects, (- whatever that implies? ) and not pointers
- Member subobject = data member.
I also strongly suspect (but do not know for sure) that:-
- they have a physical name (in the form of a character string equal to its string length) - not mentioned by you
- No, this would be incredibly wasteful. Type identification can be facilitated for instance by examining the vptr.
- most objects have pointers to at least one method (multiple methods implying multiple pointers)
- Typically, member functions are implemented like normal functions, except that a pointer to the object ("this") is passed as a hidden argument to the function.
- not all methods are virtual functions - fair enough
- This is certainly not true for other languages. In many OO languages (such as Java), methods are "virtual" by default.
- different implementations imply different 'object' structures (- which I would venture is a little inconsistent for an entire new paradigm!)
- the actual implementation of an 'object' is not itself derived using OOP mechanisms for the 'objects' datastructure
I also suspect that:-
- the attributes of an 'object' are held within the object in one form or another - not mentioned by you
- I'm not sure what attributes you are referring to, but a conforming implementation need not put anything but the raw data of the data members (+ base class instances) inside an object.
- 'subobjects' are chained from base classes (and to one another) by some pointer mechanism - not mentioned by you
- No.
- objects require 'creation' and usually 'initialization' before being used - not mentioned by you
- I didn't realize you were asking about this, but sure, see constructor.
I am, in fact, only asking for a breakdown of ONE implementation so that I (and others using wikipedia) can see 'what makes OOP tick' at its basic level. Just one example of the Data structure of a couple of 'objects' (in their entirity) complete with names, init. & method pointers and object attributes would suffice, along with a narrative of how the objects are created, processed (and destroyed?) in a typical scenario like adding two integers together. This does not have to be in hexadecimal, Pseudocode will be good enough to get a rough idea of the sizes of data and processes involved.ken (talk) 07:06, 23 September 2009 (UTC)
- I am going to break the normal conventions of the talk page to address your points individually. Unless otherwise noted, my answer holds true for most common C++ implementations, but may be blatantly wrong for other programming languages. decltype (talk) 07:28, 23 September 2009 (UTC)
The more I learn about OOP, the more I realize that even its protagonists appear not to understand it sufficiently to give a clear and concise definition of what it is. Here [2] is a link to the OOP article in wikibooks that is about as clear as mud. Why is it so difficult to show a simple example of precisely how the memory is mapped for adding two values together? Let me make it easy for someone and put my wish into the form of a question perhaps set at GCE 'O' level.
Q.There are two 32 bit integers in contiguous memory locations A and B. The integers were read in together from some external I/O device as a single record and some general register points to the start of the record as the program is given control. It is required that the program adds the two input values together and passes the resultant value as a return. Draw a diagram to show the necessary memory 'blocks' used by the program and describe each step in the process using pseudocode (show ALL your workings). Do this for a conventional program and an OOP program.
- 6 months later and still nobody has responded to the challenge! Meanwhile I discover myself some more of the hidden awkward truths behind OOP implementations - heap storage used to create new "objects", calls to constructors to initialize them and heap storage used for message passing - containing (largely unecessary) exact copies of parameters; "getters" and "setters" instead of direct assignments; serialization/marshalling - breaking both so called encapsulation and data hiding. Return values provided from sent messages (instead of waiting for a result message in response) - making a mockery of the concept of true message passing. More getarounds than rats in a maze. Proprietory data mappers to automate multiple conversions between object and binary formats. Free format human readable character text strings of data and attributes used to describe data objects externally. Discussions about whether binary XML solves the newly created data compression problem or not. Parsing, parsing and yet more parsing seems to be all the rage these days. The abstraction penalty - written large - is, it seems, most evident in OOP. When will it all end - and sanity once again prevail? —Preceding unsigned comment added by 86.142.16.251 (talk) 11:14, 21 April 2010 (UTC)
okay, I'll byte.. or at least take a nibble at this ;-) You are thinking much too low level and perhaps paradoxically, not low level enough. vptr is a good answer to your original question, you just (appear to) lack the background to be able to understand the answer, perhaps a better answer would be to tell you that it's "42". The high level understanding is that an object is a private name-space referenced by a public interface. What an object does is that it groups together zero or more data items, and provides standard methods for accessing and modifying that data. The relationship of the data items to each other and to the world is defined by the object itself via zero or more associated program routines (usually) called methods. Everything else is an implementation detail and is totally language specific. The bottom line is that an object encapsulates things that the programmer has decided are useful to be packaged together, the end goal is to manage both memory and complexity. To ask questions about the storage size of an object is to display a complete lack of understanding of computer programming (obviously the size is data+overhead). --- (hey ken, I looked at your talk page, youre not ignorant, so I guess you are flame-baiting?) --- Which then brings up the question of who is this article written for? If it is intended to be useful to non-programmers than considerably more explanation is needed. But if that were done I suspect the article would be encumbered to such an extent that it was no longer of interest to programmers.... codeslinger_compsalot 67.40.8.215 (talk) 08:39, 9 December 2010 (UTC)
- Thanks for trying 67.40.8.215, but I don't think you address the issues that I have raised, dismissing them as "implementation detail". Why shouldn't I (and everyone else) know the implementation detail for heavens sake? If I was engineering Formula 1 cars I would be extremely interested in the implementation details of my competitors cars (and also for reasons of curiosity and knowledge building).
- It is only by having implementation details that will allow serious comparisons of two or more "methods" (techniques). Implementation details are available for most other entities in the real world, why ignore/censor them for OOP?
- I have recently read a humorous blog "Execution in the Kingdom of Nouns" by Steve Yegge(see here) that encapsulates a lot of the problems with OOP - even at the conceptual level (although he doesn't go nearly far enough imho!) let alone the implementation.ken (talk) 10:29, 31 December 2010 (UTC)
I'll be brief since this is off topic for a talk page, but I think you are confusing a paradigm with an implementation. I realized this today as I was talking with a co-worker who has some similar objections. When someone is talking about OOP, they are talking about a system for organizing data and processing and associating them together. This can be done in an object oriented language or any other language. The level of detail you are concerned about is the implementation. The reason nobody can answer you is that OOP design can be implemented any of a large number of different ways. A particular language may implement it with waste and overhead in storage to support other compiler optimizations, but an OOP design could be implemented in assembly if you really wanted to. In the example of taking two fields that come in next to each other, it could be as simple as setting up an object that encapsulates them and has a function pointer to add the values at the offsets. Perhaps no OO language would implement it that cleanly, but at that point you are comparing RAD to compilers to machine code instead of paradigms.Ajh16 (talk) 16:38, 22 April 2011 (UTC)
In a pure OO implementation (no unboxed numbers) you'd need some primitive i/o routine that reads the integer values from memory:
Integer add_two_words(Address loc) {
Integer a, b;
a = read_int32_from_loc(loc);
b = read_int32_from_loc(loc+4);
return a+b;
}
The above isn't actual Java, it's OO pseudocode that I used the java template for. 69.111.194.167 (talk) 03:20, 26 April 2011 (UTC)
- Regarding "implementation details" and how important or otherwise they are, see Whitaker et al. "Software engineering is not enough" ken (talk) 06:02, 6 August 2011 (UTC)
This article is confusing because
There are several flavors of object oriented programming concepts.
A recent object oriented concept was MS Windows objects. Specific action routines were associated with the object. Double click action. Redrawing the object etc. The specifics of implementation are not what is important. The interface between windows and a programed object allowed an abstraction that makes the objects purpose independent of windows functioning. I.E. clicking on the object caused some action specific to the object. The action routines could be coded in any of several programming languages. Assembly included.
A different type of an object is used in LISP 2. LISP 2 is a procedural block structured language having several built-in types. LISP 2 was meant to combine the efficiency of languages like ALGOL working on typed data with the general list manipulations of LISP. It was vastly superior to LISP in computational efficiency. It doesn't fit the criteria set down in the article as it's object types were were part of the language specification. — Preceding unsigned comment added by Steamerandy (talk • contribs) 18:10, 5 November 2014 (UTC)