Are "subroutine" and "routine" the same concept?
Asked Answered
M

2

5

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.

Mcneese answered 24/8, 2017 at 21:36 Comment(1)
Once upon a time, "routine" would apply to the top-level code in a program. "subroutine" would be bits of code that are called by the top-level code, or by other subroutines.Ingra
D
4

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.

Demanding answered 24/8, 2017 at 21:54 Comment(2)
Thanks. If you read the link to the book I just added, both subroutine and routine have a frame in the stack. So I think they are the same concept. Do you agree?Mcneese
Reading the excerpt in more detail, I see what you're saying. It sounds like subroutines and routines are different names for the same concept. Going off of what Wayne Conrad commented above, it seems like the term "subroutine" is just a remnant from years ago. A subroutine is a routine that is executed within another routine. With all that being said, yes, I agree with you, subroutines and routines are the same. Thanks for post and the research. It's cool stuff.Demanding
T
3

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

Thrifty answered 2/5, 2021 at 1:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.