PDA

View Full Version : difference between routine and function




Howiieque
Feb 2, 2009, 03:10 AM
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
Feb 2, 2009, 03:37 AM
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
Feb 2, 2009, 08:58 AM
sometimes steve kochan said the printf routine... and sometimes he use routine to refer to method.

MacRohde
Feb 2, 2009, 09:49 AM
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.

Howiieque
Feb 2, 2009, 09:59 AM
I'm very grateful to you for all your help.:)

whooleytoo
Feb 2, 2009, 10:27 AM
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
Feb 2, 2009, 11:17 AM
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

Howiieque
Feb 2, 2009, 08:30 PM
thank you!