Routine, Subroutine and Coroutine in Programming - Explained Easy

 Routine in General

When I was in school, I used to wake up at 7:00 in the morning and then would prepare up myself for school. Come back from school by 3:00 in the afternoon and then study for sometime and then go for playing basketball. In a very basic sense, I followed a Routine. And I followed this routine for the entire lifetime when I was in the school. It did not change.

Routine in Programming

A Routine is essentially something that stays same for the entire lifetime of it and does not change. Similarly in programming, a routine is a fixed number of code lines that are intended to perform a specific task. Like my very own routine, which prepared me for school and so on !

Important points about Routine in Programming :

  1. Routines are self - contained. They do not depend on any other piece of code in your program.
  2. They are used to break down a complex program into smaller sub-programs to reduce the redundancy. 
  3. They can be invoked independently from other part of code to perform some task.

In a more sophisticated and human-friendly language, routines are called as functions or methods.

Subroutine in Programming

Subroutine in programming is a special type of routine which returns a value on performing set of specific tasks.

e.g. Consider the following example for best understanding of difference between a routine and subroutine.

                                            This is an example of routine which does not return anything.



 This is an example of sub-routine which returns something after performing fixed task.




Co-routines in Programming :

Co-routine stands for "Co-operative Routines". Coining of the term "Co-Routine" dates back to 1958 when Melvin Edward Conway first mentioned it during the construction of assembly language. 

Co-routines have largely been classified as routines whose execution you can pause, resume, terminate. Apart from this fact, coroutines and routines are exactly the same. 

Comments

Popular posts from this blog

LLD of a Parking Lot