Computer Science Unit 7 - Parameters, Return, and Libraries

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

How to create a library?

Build functions Add documentation Share as a library WATCH OUT FOR GLOBAL VARIABLES

How to test a library

Use console.log as the end user to test functions in a library Check that the output is what you would expect Read the library code if something does not work correctly, and contract the library owner if something needs to be changed

What would you need to know to use another function within your own program?

1. Name of the procedure 2. The parameters (if any) 3. The overall purpose of the procedure 4. The return values (if any)

What is the difference between a LIBRARY and an API?

A LIBRARY is a file containing procedures that can be used in a program. Meanwhile, an API provides specific details on how procedures in a library will behave.

How does a procedural abstraction manage complexity?

A procedural abstraction may extract shared features to generalize functionality instead of duplicating code. This allows for program code reuse, which helps manage complexity. Using procedural abstraction helps improve code readability.

What is the objective of using LIBRARIES within our programming?

A programmer can use procedures within their own code in order to simplify their program. Libraries are a form of procedural abstraction The programmer does not need to know the exact specific inner workings of the code to use a library

What is an API and how would you utilize or apply it within a program?

An API is an application program interface. This is essentially documentation for a library, and it provides details on how a library will behave. The API helps programmers understand the procedures in a library and how they can use it in their code.

API

Application Program Interface - specifications for how functions in a library behave and can be used

How to use a library

Click "manage libraries" Either choose a classmate's library or past in a library code Call the functions by writing the library name, a dot, the name of the function, and including any arguments for the parameters

Benefits of using parameters and arguments

Code will be more reusable Extracting shared features to generalize functionality is known as procedural abstraction You Can reuse code: define the code once, and use it many times You can use the same code many times with different arguments to produce different results Helps to simplify our ocde Allow the function to only return an answer based on its inputs within the function Improves code readability Procedural abstraction manages complexity by allowing for code reuse

Procedural Abstraction

Extracting shared features so that a procedure is known by what it does not how it does it

Are clean and organized programs more useful for computers or people? Why?

More useful for people than computers. When code is easy for programmers to follow and understand, its easier to make changes to a program, find errors, ect A computer can read and execute the code no matter how it is organized

How many times do you define the parameters of a function?

Only once

How could using parameters and return help you write programs collaboratively?

Parameters allow you to pass arguments through a function. This increases the veritility of the program, as you can run different values in the function to produce different results. Collaborators can each use the same function but input their own values to get returns.

Describe the purpose of the RETURN command within a function.

The RETURN command signifies the end of a procedure; once the function reaches the RETURN command, it exits the function. The RETURN command returns some type of data / value from the procedure, which may include a number, a string, a boolean A return value should be assigned a variable.

What happens when the a procedural call interrupts the sequential execution of statements?

The commands in the procedure must be executed. Only after the program reaches the end of a procedure or a RETURN value can it return to the place directly after the procedure call and continue moving through the rest of the code.

When sharing a function to a library, what should the NOT function use?

The function should not use GLOBAL variables

Modularity

The subdivision of a computer program into separate subprograms such as libraries (term for using libraries or other forms of organization in a program)

Before you call a procedure, what are two basic questions that you should ask about that procedure?

What type of parameters does the function require? What type of value will the function return?

Algorithm

a finite set of instructions that accomplish a task.

Library

a group of functions (procedures) that may be used in creating new programs a collection of functions that can be used in many different programs A library should have documentation for the included functions How each function works A complete list of parameters What (if anything) will be returned

Parameter

a variable in a function definition. Used as a placeholder for values that will be passed through the function.

What are the benefits of writing functions that use parameters and return?

helps improve code readability and manages complexity by reusing code.

Argument

the value passed to the parameter

Return

used to return the flow of control to the point where the procedure (also known as a function) was called and to return the value of expression.

If the procedure that you are calling returns some form of data, what must you do when writing the code for that procedure?

you need to assign the function call to a variable / assign the return to a variable


Kaugnay na mga set ng pag-aaral

Chapter 9: Managing Software ("DO I KNOW THIS ALREADY?" QUIZ + Review Questions)

View Set

Chapter 14: Public Order Crime: Sex and Substance Abuse

View Set

Florida Property & Casualty Insurance

View Set

Plasmid Vectors and Recombinant DNA

View Set

Series 66- Laws, Regs, Guidelines #2

View Set

Pharm: Chp 47: Lipid-Lowering Agents (PrepU)

View Set