Try the fastest way to create flashcards
Question

How do functions help you to reuse code in a program?.

Solution

Verified
Answered 2 years ago
Answered 2 years ago
Step 1
1 of 2

A function\textbf{function} consists of a block of statements written in a programming language that is used to perform a particular task. Whenever there is a requirement of performing a particular task multiple times in a program then we can do either of the following:

a. Whenever we need to implement the task then we will use the same setof instructions every time.b. A function consisting of the required statements is created once and thenit is called every time whenever we need to implement the task.\begin{align*} &\text{a. Whenever we need to implement the task then we will use the same set}\\ &\hspace{4mm} \text{of instructions every time.}\\ &\text{b. A function consisting of the required statements is created once and then}\\ &\hspace{4mm} \text{it is called every time whenever we need to implement the task.} \end{align*}

From the above two options the second option (b)(b) seems to be more efficient because it uses the concept of function where a set of instructions are written just once but can be used multiple times. The function is used to combine a set of instructions together thus encapsulating a task. There are several in-built functions available in many programming languages. We are only concerned about what is being done by a function.

Code reuse is the act of utilizing existing code for another function or programming. The code that will be reused should be of high-caliber implying that the code to be reused should be reliable, protected and secure. It is also referred to as programming reuse since it follows the reusability principle and utilizes the existing programming code to fabricate a new program.

Functions follows the code reuse concept since we do not have to repeat the same instructions again and again but just define them once and use them anywhere. This results in lesser code, easy to use and easy to maintain. Thus functions help to reuse code by utilizing effectively created code as indicated by our prerequisite without composing from the scratch. The line of code and compile time is diminished since the code is compiled once but is utilized on numerous occasions.

Functions help to reuse code by utilizing effectively created code asindicated by our prerequisite without composing from the scratch.The line of code and compile time is diminished since the code iscompiled once but is utilized on numerous occasions.\boxed{ \begin{array}{clr} \textrm{\text{\textcolor{#4257b2}{Functions help to reuse code by utilizing effectively created code as}}}\\ \textrm{\text{\textcolor{#4257b2}{indicated by our prerequisite without composing from the scratch.}}}\\ \textrm{\text{\textcolor{#4257b2}{The line of code and compile time is diminished since the code is}}}\\ \textrm{\text{\textcolor{#4257b2}{compiled once but is utilized on numerous occasions.}}} \end{array}}

Create a free account to view solutions

Create a free account to view solutions

Recommended textbook solutions

Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
948 solutions
Starting Out with Python 4th Edition by Tony Gaddis

Starting Out with Python

4th EditionISBN: 9780134444321 (8 more)Tony Gaddis
671 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
872 solutions
Introduction to Algorithms 4th Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

4th EditionISBN: 9780262046305Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
945 solutions

More related questions

1/4

1/7