Like in marketing management, 4Ps of Marketing by Philip Kotler has been ever green guiding principle, 4Ss seems going to be guiding principle in the world #GenAI driving coding.
If you are using #GithubCopilot, your AI companion tool that can help you write code faster and better, you might want to know how to create effective prompts that elicit accurate and useful responses from it. Here are the 4 S’s that you should follow when crafting your prompts:
- Single: Write a clear and specific prompt that asks for one thing at a time. A vague or ambiguous prompt can lead to confusing or irrelevant responses from Copilot. Therefore, you should always state your task or question clearly and precisely in your prompt.
- For example, instead of asking “How do I sort a list and print it?”, ask “How do I sort a list in ascending order?” and then “How do I print a list?” separately.
- Specific: Provide clear and detailed instructions. This will help you get more relevant and accurate code snippets. For example, you should specify the programming language, the input and output formats, the expected functionality and any constraints or requirements.
- For example, instead of asking “How do I connect to a database?”, specify the type of database, the language, the framework, the credentials method (not best practice to put secrets in code ), etc.
- Short: Be specific but brief. Avoid unnecessary details that may confuse Copilot or make the interaction more complex. This way, you can communicate your intention clearly and get the best results.
- For example, instead of writing a long paragraph explaining what you want to achieve, use bullet points or keywords to summarize your goal.
- Surround: A good way to improve the quality of your code suggestions from Copilot is to use descriptive filenames and keep related files open. This way, Copilot can understand the context of your project better and generate more relevant code.
- For example, if you are working on a web app, you can name your files according to the functionality or component they contain, such as login.js or navbar.css. You can also keep the files that are related to each other open in the same editor window, such as index.html and app.js. This will help Copilot to suggest code that matches your project structure and style.
Additional Guidance: Like Product Marketing, 3 more Ps gets addres for Service Marketing. 🙂 Similar to this, 3 more Ss i believe can help you further improving your prompt and your code companion Copilot.
- Suggestions: Use suggestions to check and improvise. Once you have extension installed. It will show against your prompt output or auto suggestion.
- Scope: Sometime it is better reduce the scope so that we solve specific problem.
- Example: You may be writting complex loop function and need Copilot only to give loop function for subset of code block. In that case, select the piece of code subset followed by right click operate and operate on Copilot Options or CTRL+I (provide relevant prompt)
- Shortcut Keys: Use keyboard short-cuts to reduce time on mouse operation and give more time on keyboard operation (Developer Mindset). Refer available Keyboard Shortcuts for various platform here My Personal favourity A+] (for next suggestion), A+[ (for previous suggestion), CTRL+I (for limiting scope)
By following these 7 S’s, (yes now 7S :-D) you can create effective prompts that will help you get the most out of Copilot. Happy coding!
Reference and want to learn and test: https://learn.microsoft.com/en-gb/training/modules/introduction-prompt-engineering-with-github-copilot/