3 Designing functions
This chapter covers
One of the hardest challenges for programming novices is to know what a reasonable task is to give to Copilot so that it finds a good solution. If you give Copilot too big of a task, it will often fail in spectacular ways that can be extremely difficult to fix. What, then, is a reasonable task?
This question is important for our use of Copilot but goes far beyond it. Human programmers struggle with complexity too. If experienced software engineers try to write code to solve a problem that’s too complex without breaking it down into smaller, more solvable subparts, they often have trouble as well. The solution for humans has been to use something called a function, whose job is to perform one task. Functions help us organize our code and make it easier to think about and fix any bugs. There are various rules of thumb for how to write a reasonable function in terms of number of lines of code, but, fundamentally, these rules try to capture writing something that (1) performs a single task and (2) isn’t so complex that it’s hard to get right.