Programming Flashcards

1
Q

Explain red green refactoring.

A

Make a test, have it fail (red), write just enough/bare minimum code to make it pass (green), then refactor implementation to improve it while keeping the test green.

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

What is TDD?

A

Test Driven Development, using red green refactoring to code.

Example of programming to an interface not an implementation. You define how you want it to work from the client side first, and once it works that way, you can refactor the implementation all you want and the results should not change.

Writing only as much as you need to pass the tests.

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

Comments should answer what question?

A

Why?

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

Where does type coercion occur? Give an example.

A

It occurs in weakly typed languages, and if you had ‘125’ and tried to add 5, it could automatically change ‘125’ which is a string, to an int, to allow the operation.

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

What is the difference between an in-place and out-of-place function? What are alternative names for them? What are the trade offs between them?

A

In place, or pass by reference can be considered destructive as it modifies the input it was given. Like passing in an array, and the function modifies that array. It will not create new copies of the input.

Out-of-place, or pass by value. functions don’t modify anything outside the scope of its stack frame. So if they are given input, they are going to make a copy of it first taking up space on their stack frame, do their thing, and return something back.

In place is more efficient usually for time and space but out of place is safer, doesn’t modify what you give it and also lets you retain the original if needed for some other operation.

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