Week 2 - Structured Programs Flashcards

1
Q

What are procedures and functions?

A

They are ways of grouping lines of code (blocks) and giving the block a name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What can functions and procedures take?

A

They both take arguments.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How are functions and procedures different?

A

Functions have one return value of a single type & side-effects, whereas procedures only produce side-effects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Arguments

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why are procedures called?

A

Because they produce side-effects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are examples of side-effects?

A

A side-effect to a procedure can include calling it inside another function, or outputting data to the screen or terminal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How are global variables marked?

A

With a $ sign.

Eg: $a

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Methods

A

An OOP term that means both functions and procedures

method()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Attributes

A

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.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are classes used for?

A

Used for creating custom data types.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the possible scopes in Ruby?

A

Global, Local & Instance

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Global Scope

A

A variable/constant that can be accessed anywhere in the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Local Scope

A

A variable/constant that’s only accessible in the block of code where declared

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Instance Scope (@Shared)

A

A variable accessible to all procedures and functions under a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is debugging code?

A

Running code and if there are errors, you’re finding them and resolving them.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What data type is on the output screen?

A

String

17
Q

What’s the difference between a parameter and an argument?

A

Parameter is the code in the brackets when defining a method.
Eg: method(n)

The argument is the value that we pass in place of the parameter/placeholder.
Eg: method(12) will substitute n = 12 and put that value into the function called method.

18
Q

What’s a splat argument? How do we mark it?

A

Splat arguments tell the program that the method can receive one or more arguments.

They are arguments followed a *.

19
Q

How do you write if a number (m) is divisible by another number (n) in Ruby?

A

m % n == 0

20
Q

How are blocks different from methods?

A

Blocks are like nameless methods. They often start with do.