Timeline for What's the difference between a function and a method?
Current License: CC BY-SA 3.0
13 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Apr 28, 2016 at 16:51 | comment | added | barlop | @9000 I know some pascal, I know how functions were done prior to OOP. And I know what a language without procedures would look like.I've written QBASIC sometimes not using procedures. I understand your definition of function, what i'm asking you is where you get it from? If somebody says the definition of function doesn't mean it can't be in a class. And you say in the old says, it wasn't. That doesn't mean that the definition of function means it can't be in a class. | |
| Apr 28, 2016 at 14:15 | history | edited | 9000 | CC BY-SA 3.0 | added 452 characters in body |
| Apr 28, 2016 at 14:07 | comment | added | 9000 | @barlop: It must not. The notion of a function can even be missing from a programming language at all (look at your nearest Turing machine). Standalone functions do exist in many languages, and historically came much earlier than objects (even if we discount their use in mathematics). Using a class as a namespace is not unreasonable, but Java also has packages for namespacing, these could suffice. Improving an answer is a good idea, thanks. | |
| Apr 27, 2016 at 22:20 | comment | added | barlop | @9000 Well why don't you make you correct/improve your answer and not exclude static methods in your definition of method. On what basis do you define a function as having to be outside of any class? Or even that it must be stand alone. A static method in a class is rather like a function in a library. Even in a procedural language, functions exist in libraries(though often ones automatically imported) and they don't stand completely alone. | |
| Apr 27, 2016 at 21:32 | comment | added | 9000 | @barlop: I did! Since the parameter is implicit (invisible), its omission is not visible in the signature. Java lacks "functions proper", that is, standalone functions that are not methods of some class. Static methods and lambdas (in Java 8) are used instead. | |
| Apr 27, 2016 at 16:12 | comment | added | barlop | You write "A method is basically a function with one extra parameter (invisible in Java). You refer to it as this" <--- what about static methods, have you forgotten about them? | |
| Dec 27, 2013 at 15:32 | comment | added | 9000 | @user61852: Many methods return values. What makes a method a method is the fact that an implicit object instance is passed to it and is used inside it: in foo.bar() that foo is also a parameter to bar() invocation. Obviously a getter needs the instance to get something from, so it's strictly a method. In certain languages one could make cosine a method, too: imagine something like (0.71).cos(). | |
| Dec 27, 2013 at 12:36 | comment | added | Tulains Córdova | Getter methods returns a value. Aren't they functions ? | |
| Dec 26, 2013 at 22:18 | comment | added | Lotok | Since @Bobson bought up .NET. In VB.NET, there is a clear difference between subroutine and function syntax, although both come under the umbrella of "Methods". | |
| Dec 26, 2013 at 21:31 | comment | added | 9000 | @Bobson: yes, partial classes is a very nice feature of C#. Even more explicit approach is seen in Go, where you cannot declare methods within a class, because classes do not exist, there are only structs and interfaces. You declare an explicit "receiver" parameter in every function you want to work as a method. | |
| Dec 26, 2013 at 21:27 | comment | added | Bobson | It's worth noting that C# lets you explicitly declare functions with the this parameter outside of the object itself. This allows for what they call "extension methods", which allow you to transparently add functionality to an existing class. | |
| Dec 26, 2013 at 10:11 | review | Suggested edits | |||
| Dec 26, 2013 at 10:17 | |||||
| Dec 26, 2013 at 7:54 | history | answered | 9000 | CC BY-SA 3.0 |