0

Just a question about general terminology. A subroutine as I understand it is basically a packaged subset of instructions that a routine runs to obtain a specific result that it needs for a larger process.

What if you're studying a routine (or program, procedure, what-have-you) and discover that it's actually part of a larger routine that you didn't know was there? Obviously you can say it's a subroutine of the larger routine, but is there a specific term to label a larger routine?

Would it be a superroutine? Seems natural, but Google didn't provide many suggestions.

5
  • 5
    In my professional career, I've never had to deal with naming like this. Function is a function irrespective if it was called by another function (which it most likely was) or if it is calling another function.
    – Euphoric
    Jul 15, 2021 at 10:02
  • 3
    In the concrete case, the routine that calls your routine X is simply the caller of X. Jul 15, 2021 at 11:02
  • 1
    You might refer to the "calling routine" if you're specifically going one level higher. The top-level routine overall would likely be called the "main loop" or the "entry point", or something language-specific like the "sub main", or "WinMain" etc.
    – Steve
    Jul 15, 2021 at 11:07
  • Although it sounds logical, I don't think I've heard anyone say "superroutine." If it's important to make a distinction, I would call it "higher-level routine." For example, the if A calls B which calls C, then B is one level higher than C, and A is two levels higher than C. As mentioned, the one routine which is not really called by anything else in your program is called the "top-level", while the leaves are the bottom-level ones. This terminology makes sense if you imagine the function call graph as a tree, with the root at the top of the page and the leaves at the bottom.
    – Brandin
    Jul 20, 2021 at 9:02
  • 1
    There is only exactly one function that isn't called by another function: the entry point of your program. But really, that one is also called by someone else, so... Everything is part of something bigger, usually. Therefore, it doesn't make sense to call the something bigger somewhat, because it is expected to be there, anyways.
    – Polygnome
    Feb 15 at 14:44

3 Answers 3

4

Names like “subroutine” are no longer common, and the term is somewhat associated with assembly code that does not use procedural and structured programming. Nowadays, “function” or “method” are more common words.

It is perfectly normal that a function works by calling other functions. This does not have a commonly used special name. However:

  • a function that calls no other functions might be called a “leaf function”, at least in the context of compiler construction.
  • a function that is not part of the public interface of a module and is only intended to be called by other functions in the module is a “helper function”.
5
  • Personally, I use the term "subroutine" when I don't want to be specific as to whether I am talking about a procedure (a subroutine with side-effects), a function (a subroutine without side-effects), a method (a subroutine with privileged access to one of its arguments), or whatever else a particular language or community might call it. For example, Java has methods but no functions, C++ has functions but no methods, JavaScript has both, but methods are actually just functions, Scala has both, and they are fundamentally different, Haskell has both functions and methods, but both are … Jul 15, 2021 at 16:38
  • … fundamentally different from JavaScript's, etc. Because the term "subroutine" is so archaic, it seems to work well as a hypernym of all of those. Jul 15, 2021 at 16:38
  • Although note that Eiffel uses the term routine for what is more commonly called method, and attribute for what is more commonly called instance variable or field, and uses feature as the hypernym for both, which would more commonly be called member. Anyway, +1 for "leaf" and "helper". Jul 15, 2021 at 16:39
  • @JörgWMittag While every language has it's own terminology, I'm not sure if subroutine is widely understood as an overarching concept. For example, it would be unusual to consider a callable objects such as closures or C++ functors as subroutines, except perhaps in the context of Perl. For me, the archaicism of the term strongly evokes the punch card era with all the adventurous programming practices of the time. Nowadays, “function” seems to be the most general term in a language-agnostic setting.
    – amon
    Jul 15, 2021 at 17:13
  • In C++, functions on a class are formally called member functions, but colloquially such member functions are also known as methods. Interestingly, the creator of that language uses the term 'method' specifically to refer to a member function which is virtual, which is as far as I know, is not a very common way to use the term 'method'.
    – Brandin
    Jul 20, 2021 at 9:09
0

The following are the most common terms used to define routines, subroutines and function libraries. Each term has a specific meaning.

A routine is a named sequence of program statements that performs some useful action. It can be called by other programs or included in any program with no side effects.

A subprogram intended to be called by the main part of the calling program rather than executed as an independent unit under its own control flow path, is referred to as a subroutine. Like a function, it does not return control back to the caller until all executable statements have been executed.

Function library refers to either static or dynamic link library (DLL) that contains many individual functions.

Functions A function is a self-contained code sequence that performs some task under software control, which can be called from different program modules or from the same module in which it is defined.

-1

Some languages, such as Ada, allow you to define a function or procedure within another.

Ada refers to these as "inner" and "outer" procedures/functions.

But most programs are made up of procedures that call procedures that call procedures... There's no particular term for that.

Not the answer you're looking for? Browse other questions tagged or ask your own question.