Working with GitHub Copilot
Copilot is the autocomplete that finishes your sentence. It is fast, it is confidently wrong about subtle things, and it inherits the patterns of whatever code is already on your screen. Five things to start with this week. We will add more as the cohort matures.
1 Read every suggestion before you accept it
Copilot does not understand your code. It guesses. The guess is usually close, sometimes exactly right, occasionally subtly wrong. The subtle ones are the dangerous ones because they compile, they run, and they ship.
Slow down enough to read what got pasted in. If your eyes glaze over a five-line completion, that is a five-line decision you did not make. Press Esc and write it yourself.
2 Use it for code you know how to write but do not want to type
Boilerplate. Test fixtures. Repetitive null checks. The third overload of a constructor that is almost identical to the second. These are the cases where you know the right answer, so you can immediately see if Copilot got it wrong.
The opposite case is the trap. The algorithm you are not sure about. The data-structure choice you have been debating with yourself. The async pattern you have not used before. Copilot will give you a confident-looking answer and you will not be able to tell if it is right.
3 Comments above your function shape what Copilot writes
Copilot reads what is near your cursor. The lines above your function definition are the most powerful input you have. A comment like // Returns null when the key is missing produces different code than // Throws KeyNotFoundException when the key is missing.
This is the closest thing Copilot has to a steering wheel. Use it on purpose. Write the comment first, see what comes out, edit the comment, regenerate.
The cousin pattern: name your variables specifically before you type the next line. var userOrders = will draw very different completions than var x =.
4 Press the next-suggestion key
The first suggestion is the statistically likely one. The second or third is often what you actually wanted. The cost is one keystroke (Alt+]) and you see the alternatives.
This is especially valuable when Copilot writes something close-but-wrong. Often the right version is hiding in suggestion 2.
5 Watch what Copilot is copying from
Copilot completes based on what is open in your editor and what is near your cursor in the file. If the codebase has a god-method anti-pattern in the surrounding code, Copilot will write more god-methods in your new code. The autocomplete gradient is "more of what is already here."
If you are starting a clean new module, open it in its own directory first, away from the legacy patterns you want to leave behind. Otherwise you will fight Copilot the whole way as it pulls you back toward the existing style.
The flip side is useful: when you ARE adding to a clean module, the surrounding clean code makes Copilot suggest clean continuations. The tool amplifies the gradient. Set the gradient on purpose.