Programming Methodology - Stan Flashcards

1
Q

What is a good comment to put in when programming

A

Pre condition: what you expect before a method is called

Post condition: what you expect after it is called

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

What is Top Down Design (eg stepwise refinement etc)

nb think Top Down rather than Bottom Up. Think about the most abstract level and break down from there

A

Top Down Design

Stepwise refinement is breaking steps/tasks (actions/methods) down into ‘primitives’ until we/the computer understand them

E.g. Morning list

  1. Get up
  2. Brush teeth - put toothpaste on brush/move brush on teeth

Breaking these down is referred to as decomposition. This is all top down design

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

Outline some good programming practices for a method - ie decomposition

A

Solve one problem at a time

Mathods are usually between 1 and 15 lines. A one line method could be calling another method. This is done when you want to give one method a different name - eg ‘move to wall’ method is changed ‘descent hurdle’ to help visualise the program conceptually

This is related to giving the method good names

Add comments. Add pre- and post- conditions if needed.

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

What is the OBOB?

A

The OBOB is the Off By One Bug. When a code does not finish executing due to flawed programming - ie it does everything correct until the last move (eg Karel the Robot)

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

What is object orientated programme (ie java programme)

A

An object oriented (ie java) program is a programme that is made of a set of of classes

A class is an encapsulation of behaviour and data

Classes get organised into hierarchies

Superclass 
\I/
Subclass (this extends the superclass and can be more advanced) 

eg classes = Animals -> mammals-> primates-> humans

an instance of a class = a human called “bob”

In object oriented languages these instances are called objects. An object is an instance of a class - a particular example of a class

Classes are the template for objects

eg in Karel, the particular Karel programme (ie superKarel), the robot running around is an instance/object of the superKarel class

Objects interact with each other

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

What is an instance of a class?

A

classes = Animals -> mammals-> primates-> humans

eg an instance of a human = a man called ‘bob’

In java is an object. An object is an instance of a class - a particular example of a class

Classes are the template for objects

eg in Karel, the particular Karel programme (ie superKarel), the robot running around is an instance/object of the superKarel class

Objects interact with each other

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

What is acm. program Hierarchy?

Association for Computing Machinery

A
Applet (runs on webpage)
JApplet
Program
I
ConsoleProgram / Dialog Program / Graphics Program

You extend these kinds of programmes above (these are classes)

nb ConsoleProgram extends Applet…it is an Applet

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

Give an example how graphics work

A

Graphics:

A blank canvas loads and you put a collage of objects on the blank canvas:

Objects that exist in the graphics world:

  • GLabel
  • GRect
  • GOval
  • GLine

]^ Note that all the above are classes, or templates for objects. You create particular instances of these objects and put them up in the college on the canvas.

eg 
add( new GLabel( "hello world". 100, 75) ):
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Give an example of how a method works using . syntax

A
GLabel label = new GLablel("Hello, world", 100, 75) ;
label.setFont("SansSerif-36");

You create a new label object in the first line and label it

setFont is the method, and you are passing it to the label object. This sets the label’s text to the new font.

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

What are primitive types?

A

The types that are built into Swfit / Java

eg int, string, double, boolean, char

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

Explain how you would describe the following (eg message and receiver)

GLabel label - new GLabel("hello", 100, 150);
label.setColor(Color.Red);
A

label.setColor(Color.Red);

label is the receiver and setColor is the message.

The name of the variable is the receiver, and the method that’s being called is the message.

“I made a method call on the object”

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

What if you don’t specify a receiver for a message (method)?

eg getWidth()

A

If you don’t specify a receive for a method, then the receiver is the encapsulating class. eg for the below example, it sends the message to the GraphicsProgram class

eg getWidth()

(returns the width of the graphics window)

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

What are statements that affect the order in which a program executes commands called?

What are the two types of control statements?

A

Statements that affect the order in which a program executes commands are called control statements.

  1. Conditional statements - Conditional statements specify that certain statements in
    program should be executed only if a particular condition holds eg if x = 1 {
  2. Iterative statements - Iterative statements specify that certain statements in a program
    should be executed repeatedly, forming what programmers call a loop - eg ‘for’ and ‘while’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a ‘for’ statement?

A

A ‘for’ statement is used when you want to repeat a set of commands a predetermined number of times.

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

What is a ‘while’ statement?

A

A ‘while’ statement is used when you want to repeat an operation as long as some condition holds.

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

What’s the difference between a declaration and a definition?

A

A declaration introduces an identifier and describes its type, be it a type, object, or function. A declaration is what the compiler needs to accept references to that identifier.

A definition actually instantiates/implements this identifier. It’s what the linker needs in order to link references to those entities. These are definitions corresponding to the above declarations:

17
Q

When do you use a for loop and when do you use a while loop?

A

-for:-
for (init ; test ; step) {
statements
}

used when;
- you have a definite iteration. Generally, we know how many times we want to iterate

-*while:*-
init 
while (test) {
 statements
 step
}

used when;
- indefinite iteration. Generally, we don’t know how many times to iterate beforehand (iteration number can vary, eg 1 or 2 etc)