3 Functions
3.1 Generating functions
You may have seen examples of this in other programming languages. Note that generative AI systems like Github Copilot or ChatGPT are not determistic meaning they can give different results for the same prompt. You may not be able to exactly reproduce examples in this chapter and in this book, but they provide an example of what your response could look like.
3.1.1 Naming things
“There are only two hard things in Computer Science: cache invalidation and naming things” -Phil Karlton
Naming things is hard, but ChatGPT can help with that. Note that you can ask ChatGPT to come up with catchy names or edit existing names. Here are some names you can get help with
- function names
- function arguments
- object names
3.1.2 Pattern matching
3.2 Generating function documentation
Here’s an example prompt:
3.2.1 roxygen2 headers
roxygen2 is the standard tool for function documentation. You can request your AI code assistant to generate roxygen2 documentation or even include it as a header above previously generated functions or future functions.
Here’s an example prompt:
4 Understanding third party code
The next chapter covers how AI coding assistants can help with unit test development.