Category: 

In Computers, what is a Subroutine?

Article Details
  • Written By: A. Leverkuhn
  • Edited By: Andrew Jones
  • Last Modified Date: 17 September 2016
  • Copyright Protected:
    2003-2016
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
The atmosphere of Jupiter's moon Io collapses every time it is eclipsed by the planet.   more...

September 29 ,  2008 :  The Dow Jones Industrial Average experienced its largest one-day drop in history.  more...

A subroutine in computer programming is a smaller part of a larger code module that has its own internal operations designed to serve the overall program. A subroutine is sometimes called a function or a method because it returns a specific code result that is used by the program. Functional programming provides for versatile code that is laid out in pieces. Programmers then choose events that initiate the functions that “drive” the user’s experience.

Different computer languages use subroutine functions in different ways. Some computer programming languages use a “stack” model, where functions or subroutines are arranged in a linear format, and used according to their immediate relevance. Other languages use compartmentalized formats to isolate functions and distinguish them from one another.

Using a subroutine correctly is part of what a programmer learns when he or she is looking at ways to keep computer code accessible. Critical strategies like the efficient use of a subroutine go along with other more general strategies such as how to use white space in code, or how to leave directions for program changes with comments. Arranging computer code in the appropriate way makes it a lot easier for other programmers and engineers to “read” it, and understand what goes on in the program.

Ad

All of the code made up by subroutines and other code modules is often made into an “executable” program. Calling a program executable relates to the idea of executing or “running” a program. In many cases, the executable program is simply made up of a collection of subroutines. When someone “runs” the program, the computer starts with an initial line of code, and then gets pointed along to other successive lines of code by the directions written into the program.

Another main benefit of subroutines is in the task of debugging a program. If there is a problem with the program, engineers can go into the code and look through the lines of code sequentially to see where the problem started. With subroutines, the programmers can look at each piece of code separately and “clear” the parts that are error-free to focus on where errors did occur.

Subroutine use is an integral part of learning computer programming. Subroutines will often be a part of academic computer science classes. Programmers learn these skills in school, or in the field, to create programs with better overall function and transparency.

Ad

You might also Like

Recommended

Discuss this Article

Logicfest
Post 1

The good use of subroutines is critical for debugging. Why? Organization is important when writing a program of substantial length as it makes it easier to figure out why part of your code is not functioning as intended.

Back when I was learning how to code in COBOL and Fortran, subroutines were a major part of our code. That is how we were taught to program, in fact, for the very reason that organization leads to the ability to track down the culprit when something goes wrong.

Post your comments

exception 'Exception' with message 'error writing captcha: Duplicate entry '2147483647' for key 'PRIMARY'' in /ssd/www/wisegeek/public_html/_core/classes/public/Captcha.php:44
Stack trace:
#0 /ssd/www/wisegeek/public_html/_core/controls/public/ControlDiscussionPostBox.php(324): Captcha->createCaptcha()
#1 /ssd/www/wisegeek/public_html/framework/classes/Control.php(104): ControlDiscussionPostBox->preRender(false)
#2 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): Control->render()
#3 /ssd/www/wisegeek/public_html/tpl/default-nocustom-lu/pages/public/article/article.htm(526): Control->__toString()
#4 /ssd/www/wisegeek/public_html/framework/classes/Control.php(300): require('/ssd/www/wisege...')
#5 /ssd/www/wisegeek/public_html/framework/classes/Control.php(309): Control->requireTpl('pages/public/ar...', Object(PageArticleCom), true)
#6 /ssd/www/wisegeek/public_html/framework/classes/Control.php(131): Control->renderTpl('pages/public/ar...', Object(PageArticleCom))
#7 /ssd/www/wisegeek/public_html/framework/classes/FormDataControl.php(87): Control->renderTemplate()
#8 /ssd/www/wisegeek/public_html/framework/classes/Control.php(109): FormDataControl->renderTemplate()
#9 /ssd/www/wisegeek/public_html/framework/classes/ScriptPage.php(50): Control->render(false)
#10 /ssd/www/wisegeek/public_html/framework/classes/Control.php(149): ScriptPage->render()
#11 /ssd/www/wisegeek/public_html/framework/classes/Page.php(97): Control->__toString()
#12 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(443): Page->processRequest()
#13 /ssd/www/wisegeek/public_html/_core/classes/public/PublicFrontController.php(7): PublicFrontController->renderPage()
#14 /ssd/www/wisegeek/public_html/index.php(11): PublicFrontController::run()
#15 {main}