Looking at Unit 7 Lesson 3 Warm Up. We are to ask
“What is one way you think programming with parameters and return values may make programming or debugging more challenging?”
I disagree with the assumption that functional programming makes things harder. This should really ask about making things easier. Or at least ask about pros and cons.
With true functions, we can test using the REPL independent of the UI. We don’t need UI problems combined with our calculation bugs. So isolate them and test them independently. This is actually easier.
This could lead to testing as part of development.
/*
* Unit tests for calculate, equationAsString, and isEven
*
*/
console.log(calculate(ADD,1,2) == 3);
console.log(calculate(MULTIPLY,2,3) == 6);
console.log(equationAsString(MULTIPLY,2,3) == "2 x 3 = 6");
console.log(equationAsString(ADD,1,2) == "1 + 2 = 3");
console.log(!isEven(3));
console.log(isEven(4));
Dare we even go as far as to say write these first?
In Unit 7 Lesson 7 we introduce the idea of testing our code with console.log kind of like the above. I would move that forward. In Unit 7 Lesson 5 we introduce the idea of functions without side effects in the context of what would be good for a library. Again, I would move that forward.
If we encourage them to isolate calculations (true functions) from functions that work with the screen (side effects). And encourage them to write small functions. We can help them write clean code like this
function updateScreen (operation) {
var number1 = getNumber("inputNumber1");
var number2 = getNumber("inputNumber2");
setText("outputLabel", equationAsString(operation, number1, number2));
oddOrEvenNumber(calculate(operation, number1, number2));
resetInputNumbers();
}
Give them the framework to make small functions with one focus instead of large functions with mixed purpose and procedural programming. I think this unit might work smoother than seeming like a big jump from procedural to functional programming. The down side would be a longer instruction but part of that is offset by being ready for libraries.