Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (622)
Games in Android Showcase (176)
games submitted by our members
Games in WIP (674)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Function or method?  (Read 1800 times)
0 Members and 1 Guest are viewing this topic.
« Posted 2007-09-01 23:32:54 »

This is probably better suited to my other thread about the return statement, but this is a new (quick) question, so I'm just going to put it here. Real quick, is a function the same as a method or are they different? Thanks.
Offline oNyx

JGO Coder

Medals: 2

pixels! :x

« Reply #1 - Posted 2007-09-02 01:29:35 »

There are no functions in Java only methods.

Basically... functions and methods are the same. The difference is that methods are always bound to objects. So, you got functions in functional languages and methods in OO languages.

弾幕 ☆ @mahonnaiseblog
Offline quixote_arg

Junior Devvie

Projects: 1


« Reply #2 - Posted 2007-09-02 01:46:10 »

technically, a function always returns the same value so

public Date now() {
   return new Date();

is not a function, but that's just a formality
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline JAW

Senior Devvie

Medals: 2

« Reply #3 - Posted 2007-09-14 08:00:46 »

While you can find different definitions, and you could use google for that question, here is my version:

Basically there is no relevant difference. But I once heard the definition that a function returns something and a method does not. The method just does something while a function produces a result.

After all, it doesnt matter. Usually, no one makes a difference there, so you can use either word or both.

Offline fletchergames

Senior Devvie

« Reply #4 - Posted 2007-09-14 18:02:08 »

"Function" is a math term that pretty much got hijacked by computer scientists (who were mathematicians).  A function takes a value from a set as an argument and produces a value from another set as a return value (with some restrictions that I can't remember as well as I should).

In computer science, function and method are used almost interchangeably, like the others said.  In either case, it's an algorithm that is performed and may optionally return a value.  It's not really the same as a math function because computer science functions/methods can do other things besides return a value (e.g. they can draw something on the screen).

So functions and methods the same, but you should call them methods to avoid confusion with people you probably won't talk to anyways.  Or, at least, that's my understanding of why Java has "methods" instead of "functions".
Offline rdcarvallo

Senior Devvie

Projects: 5
Exp: 15 years

2D Java games forever!

« Reply #5 - Posted 2007-09-25 20:12:19 »

I remember my first programming language, Turing.

There was procedures and functions, the diference was that procedures didn't return a value, and functions did.

That was easily translated in my mind to any function v/s void functions in my C days.

Now in Java my experience says that all are methods, bound to objects and classes (statics).

Offline Galgalid

Senior Newbie


« Reply #6 - Posted 2007-09-25 20:42:39 »

Methods is antoher word for functions Tongue Let's leave it to that shall we? Wink

I've never before built a program this stable, this secure, this L33T....

I want to be a member of the Sega Black Ops Team!
Offline keldon85

Senior Devvie

Medals: 1

« Reply #7 - Posted 2007-09-25 22:33:59 »

Methods is antoher word for functions Tongue Let's leave it to that shall we? Wink
Well the difference is good to know, some methods are functions, while some are procedures. Think that you could create a function that takes (say) a map and two points and returns a list of paths between the two points of minimal lengths. On the other hand you can have a procedure that performs operations on the map to highlight the shortest paths between the two points.

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

basil_ (33 views)
2015-09-30 17:04:40

shadowstryker (17 views)
2015-09-29 15:55:06

TheSpaceHedgehog (23 views)
2015-09-29 01:58:48

GamerC4 (46 views)
2015-09-24 21:10:38

GamerC4 (67 views)
2015-09-24 21:09:48

htuy (22 views)
2015-09-24 04:57:24

htuy (31 views)
2015-09-24 04:56:35

htuy (23 views)
2015-09-24 04:56:09

htuy (22 views)
2015-09-24 04:47:33

Roquen (59 views)
2015-09-21 12:54:28
Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11

Rendering resources
by Roquen
2015-08-17 12:42:29

Rendering resources
by Roquen
2015-08-17 09:36:56

Rendering resources
by Roquen
2015-08-13 07:40:51

Networking Resources
by Roquen
2015-08-13 07:40:43

List of Learning Resources
by gouessej
2015-07-09 11:29:36 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!