Programming Flashcards
Explain red green refactoring.
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.
What is TDD?
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.
Comments should answer what question?
Why?
Where does type coercion occur? Give an example.
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.
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?
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.