difference between routine and function

Discussion in 'Mac Programming' started by Howiieque, Feb 2, 2009.

  1. macrumors regular

    Joined:
    Feb 1, 2009
    #1
    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.
     
  2. macrumors regular

    MacRohde

    Joined:
    Jun 1, 2004
    Location:
    Copenhagen, Denmark
    #2
    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.
     
  3. thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #3
    sometimes steve kochan said the printf routine... and sometimes he use routine to refer to method.
     
  4. macrumors regular

    MacRohde

    Joined:
    Jun 1, 2004
    Location:
    Copenhagen, Denmark
    #4
    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.
     
  5. thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #5
    I'm very grateful to you for all your help.:)
     
  6. macrumors 603

    whooleytoo

    Joined:
    Aug 2, 2002
    Location:
    Cork, Ireland.
    #6
    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).
     
  7. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    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
     
  8. thread starter macrumors regular

    Joined:
    Feb 1, 2009
    #8
    thank you!
     

Share This Page