Tim
Tim

Reputation: 99488

Are "subroutine" and "routine" the same concept?

I have seen both "subroutine" and "routine" used in programming language books. Are they the same concept? What does "sub-" mean?

I guess there are many examples which you might have seen in computer science books, besides the following one from Programming Language Pragmatics, by Scott:

In Section 3.2.2 we discussed the allocation of space on a subroutine call stack (Figure 3.1). Each routine, as it is called, is given a new stack frame, or activation record, at the top of the stack. This frame may contain arguments and/or return values, bookkeeping information (including the return address and saved registers), local variables, and/or temporaries. When a subroutine returns, its frame is popped from the stack.

Thanks.

Upvotes: 5

Views: 3851

Answers (2)

El Mehdi
El Mehdi

Reputation: 41

Both terms refer to the same thing : a subroutine is a routine called inside a routine. Think of it as a main program (a routine) that has function calls inside and every call to a function is a subroutine. However there are few differences between functions and routines, you can read more here

Upvotes: 4

Ryan Workman
Ryan Workman

Reputation: 51

It is my understanding that subroutine or routine are just names for self-contained blocks of code or instructions the program runs. For example, in Ruby we'd call subroutines methods where as in JavaScript they are called functions.

In the context of the Programming Language Pragmatics example you provided, the subroutine appears to be the call stack of actions to be executed and each item of the stack are routines that launch their own self-contained stack. After all of the processes are performed, the routine exits and the subroutine moves down to the next routine.

Wikipedia has a great high-level explanation of what is happening within the call stack and how subroutines got their name.

Upvotes: 4

Related Questions