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.

  • 2
    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 at 10:02
  • 1
    In the concrete case, the routine that calls your routine X is simply the caller of X. Jul 15 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 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 at 9:02

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”.
  • 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 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 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 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 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 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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