Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
What is the difference between routine and function? I have finished reading the Programming in objective-c. And the author sometimes use the word routine instead of function and method. It seems that they are not identical. Can someone give a explanation.
 

MacRohde

macrumors regular
Jun 1, 2004
164
0
Copenhagen, Denmark
Nowadays the terms can be used interchangeably. But originally the distinction was this: a routine doesn't return anything, whereas a function returns something.

When talking about object oriented programming, we use the word methods to mean functions or routines that are part of an object - also called instance methods.
 

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
sometimes steve kochan said the printf routine... and sometimes he use routine to refer to method.
 

MacRohde

macrumors regular
Jun 1, 2004
164
0
Copenhagen, Denmark
sometimes steve kochan said the printf routine... and sometimes he use routine to refer to method.

As I said they are used interchangeably. It doesn't really matter. I usually always use the word method when talking about instance routines/functions, and use the word function to mean functions/routines that are not part of an object.

I everyday use there is no need to be so precise that you have to discern between a function that returns void or some value.

In other words use the terminology you like the best. When the distinction is important it will be made clear from the context.
 

whooleytoo

macrumors 604
Aug 2, 2002
6,607
716
Cork, Ireland.
They both describe the same concept, though people from differing development backgrounds use the terms differently.

Routine, I believe, is an 'older' generic term; for any re-usable block of code. Whenever I programmed in assembly language, I always used the term 'routine'.

"Function" is the term used more nowadays in high-level languages for any 'routine' not part of a class. (Except in Pascal, function describes a routine that returns a value, while procedure is one which returns nothing.)

Then a "method" is any routine that's a member of an object (an instance method) or of a class (class/static method).
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
As stated this is really just semantics. OO sometimes uses a special set of terms like method and behavior, but you'll be fine with whatever you call a block of code.

To add a note, fortran calls program units functions if they return a value and subroutines if not.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.