Week 2 - Structured Programs Flashcards
What are procedures and functions?
They are ways of grouping lines of code (blocks) and giving the block a name.
What can functions and procedures take?
They both take arguments.
How are functions and procedures different?
Functions have one return value of a single type & side-effects, whereas procedures only produce side-effects.
Arguments
Data that is passed from one block of code to another (the thing that goes into the brackets of a procedure/function).
The argument is given a name (like a variable name) in the receiving procedure.
Why are procedures called?
Because they produce side-effects.
What are examples of side-effects?
A side-effect to a procedure can include calling it inside another function, or outputting data to the screen or terminal
How are global variables marked?
With a $ sign.
Eg: $a
Methods
An OOP term that means both functions and procedures
method()
Attributes
Variables and arguments, but also functions or methods that might be used to give values as though you were accessing a variable.
These are used to define a class, where a class is a new data type that we make. Eg: Attribute like id in HTML to later call onto it.
What are classes used for?
Used for creating custom data types.
What are the possible scopes in Ruby?
Global, Local & Instance
Global Scope
A variable/constant that can be accessed anywhere in the program.
Local Scope
A variable/constant that’s only accessible in the block of code where declared
Instance Scope (@Shared)
A variable accessible to all procedures and functions under a class.
What is debugging code?
Running code and if there are errors, you’re finding them and resolving them.