Talk:Method (computer programming)
In use, a method is a function.. Fundamentally, Methods + Data = Object.. Just the elaborations of this invariant property of objects has muddied the definition of what an object is.. For instance inheritance is more a language construct than a property of an object.. Also a "Class" is the beginning state of an object, so what use is a class aside from an object, as objects could be used to make more objects.. I think over the years Java and C++ has muddied the definition of what an object is, when really its a simple concept that I believe (in conspiracy theory) that capitalists not interested in the adoption of object oriented languages has intentionally sabotaged to avoid the competition from perpetually consistent pluggable entities. Agents are merely mobile objects and whatever happened to the use of Agents? I challenge you to track down the use of Agents, popular in the 90s but was this just a fad? You may find they were systematically extinguished (I was told one such language that used agents as objects was forced out indirectly by Microsoft, but this is a rumor). --Rofthorax 10:38, 24 August 2005 (UTC)
---
Is static really the same as "shared"--I thought it was the opposite--static *fields* cannot be modified.
more information and more accurate information needs to be put here. I don't know enough about Java to help.
My references: (by memory)
Java Methods, avaliable directly from www.skylit.com
The static keyword is, by default, related to single storage. For instance, any modification of a static field will be seen by all instances of a given class as they are applied to the same piece of memory. There are exceptions, however. I will care to provide one example: global variables in C which are also static will have internal linkage, that is, they will only be seen by functions inside the same file (if, naturally, placed after the variable in question was defined).
The keyword global is related to access. A global variable is one which will be accessed by all functions which do not include definition of a variable of the same name and type. Global variables will naturally have a single piece of memory related to them. This means they are "static" in such sense. But a language may allow them to be defined as static and this will have a different behavior, as stated on the above paragraph.143.54.30.7 18:49, 18 January 2007 (UTC)
I would not consider static functions as methods [they're just functions associated with the class]. Similarly, constructors and destructors (in C++) are not strictly speaking methods. A method should be able to assume that invariants are satisfied on entry to the method, and should leave the object in a valid state. [unsigned]
All the Microsoft documentation refers to "static methods" in C#. 86.131.96.29 (talk) 18:10, 8 February 2008 (UTC)
Subroutines and Methods
Aren't subroutines and methods pretty simliar? If so, I think each article should mention the other one to some degree. -Hyad 2 July 2005 23:25 (UTC)
- A subroutine is one possible way to implement a method. Wouter Lievens 14:33, 26 January 2007 (UTC)
"Method" is just a new word for function or procedure that has become popular in the object oriented paradigm. This article should refer to existing articles on functions and procedures, should relate methods to functions and procedures, and should explain in very clear terms that a method is simply a module of code that contains a sequence of instructions. Some methods attach to classes, others to objects, others to neither (in structured programming languages). There should be some explanation of parameters and return values, but nothing that duplicates discussions already in place under "function" or "procedure" or the more generic "subroutine".
Actually it's wrong to say that "method is just a new word for function or procedure." When I invoke a procedure, I can be sure exactly what code will be called. When I invoke a method of an object, the actual code will vary according to the class of the object (which might be different from what I expect.) (Erik Zoltan (talk) 16:33, 16 September 2008 (UTC))
It's true that a method invocation might execute one out of several polymorphic pieces of code. I would happily describe each polymorphic variation as a "method" - that is, a function or procedure. Are you implying that the word "method" applies only to the polymorphic signature, and a different word should be used to describe each of the implementations? If so, what word? Paul Foxworthy (talk) 04:08, 17 September 2008 (UTC)
Note that there already exists a definition on page Dynamic_dispatch;
dynamic dispatch is the process of mapping a message to a specific sequence of code (method) at runtime..
Disregarding the particular focus on dynamic dispatch leave us with the definition dispatch is the process of mapping a message to a specific sequence of code (method)'.' This implies that the it is the message which is sent, delivered and understood (reacted to). That is, the polymorphic signature, including intended semantics, are captured within the message definition. It is important to clearly distinguish this from the method which contains the implementation details regarding what specifically should happen upon message delivery, with relation to specific object or class (or set of classes in the case of multi-methods). The two concepts are often confused, as well as the difference between methods and procedures as outlined above.
Based on current terminology, I'd offer the general definition that a method is a self contained, specific sequence of code (e.g. a procedure or subroutine) that has been explicitly associated with an object or class and will be automatically selected for use upon delivery of the message it implements. This rules out general procedures, functions, lambdas, case blocks within switch statements (and by extension if-blocks) as well as blocks within for and while loops, which are generally not considered methods (except perhaps just before being extracted into such during refactoring), and rules in Erlang's message handling mechanisms. --Mike Amy 11 Oct 2009
main()
In Java class hierarchy, where does the method main()
fit? Anwar (talk) 12:20, 28 January 2008 (UTC)
It does not fit in the hierarchy. Java's design is simply silly. This is because Java was designed to be unimplementable, dealing only with objects living... No beginning of the execution was designed. So main() was fit something like randomly. Please stop using java, consider ANY OTHER serious language. DrW —Preceding unsigned comment added by 78.12.176.15 (talk) 20:51, 22 April 2008 (UTC)
Java designed to be "unimplementable"? That must be why it's "unimplemented" to the point of market dominance. Truth is, Java's implementation of main()
is no more random than in C++. In neither language does the main routine fit into the class hierarchy. Both languages hack the OO paradigm in order to give programs a point of entry. I agree with anyone who wants to argue that C++'s enforcement of only one point of entry is cleaner, but to call Java's design "silly" is putting it way too strongly. --Rtperson (talk) 16:55, 10 September 2008 (UTC)