|
1 | | -## Step 3: (replace-me: STEP-NAME) |
| 1 | +## Step 3: Expand Calculator Functionality |
2 | 2 |
|
3 | | -(replace-me: OPTIONAL Brief story or scenario to introduce the step) |
| 3 | +Duck wants to expand the calculator with additional operations by creating a new issue and working with Copilot CLI to implement the enhancements. |
4 | 4 |
|
5 | | -### 📖 Theory: (replace-me: Theory title) |
| 5 | +### 📖 Theory: Iterative Development with Copilot CLI |
6 | 6 |
|
7 | | -<!-- GitHub-styled notifications can be used outside of ordered lists. Available options are: NOTE, IMPORTANT, WARNING, TIP, CAUTION --> |
8 | | -<!-- |
9 | | -> [!NOTE] |
10 | | -> (Important note or additional information relevant to this section) |
11 | | - --> |
| 7 | +**Iterative Development and Agile Practices** |
| 8 | + |
| 9 | +Modern software development follows iterative approaches where features are built incrementally: |
| 10 | +- Start with a minimal viable product (MVP) |
| 11 | +- Add features in small, manageable chunks |
| 12 | +- Test and validate each addition |
| 13 | +- Continuously improve based on feedback |
| 14 | + |
| 15 | +**Maintaining Momentum with Copilot CLI** |
| 16 | + |
| 17 | +The standalone Copilot CLI helps maintain development momentum by: |
| 18 | +- Quickly generating code for new features using the latest AI models |
| 19 | +- Suggesting best practices and patterns |
| 20 | +- Helping debug and test new functionality |
| 21 | +- Reducing context switching by keeping you in the terminal |
| 22 | +- Handling long-running shell commands more efficiently |
| 23 | +- Supporting improved automation with the headless `-p` mode |
| 24 | + |
| 25 | +**Delegating Larger Tasks** |
| 26 | + |
| 27 | +For more complex tasks, you can use the `/delegate` command: |
| 28 | +```bash |
| 29 | +copilot |
| 30 | +> /delegate Add modulo, exponentiation, and square root functions to calculator.js with proper error handling |
| 31 | +``` |
| 32 | + |
| 33 | +Copilot coding agent will: |
| 34 | +1. Create a new branch automatically |
| 35 | +2. Open a draft pull request |
| 36 | +3. Work on the task autonomously |
| 37 | +4. Stream output to your terminal |
| 38 | +5. Request your review when complete |
| 39 | + |
| 40 | +**Testing and Improvement Workflows** |
| 41 | + |
| 42 | +As you add features, Copilot CLI can help you: |
| 43 | +- Generate test cases for new operations |
| 44 | +- Suggest edge cases to consider |
| 45 | +- Create documentation |
| 46 | +- Refactor code for better maintainability |
| 47 | +- Save and share your development sessions using `/share` |
12 | 48 |
|
13 | | -(replace-me: Optional theory or background information relevant to this step) |
| 49 | +### ⌨️ Activity: Add More Operations to the Calculator |
14 | 50 |
|
15 | | -### ⌨️ Activity: (replace-me: Activity title) |
| 51 | +1. Start an interactive Copilot CLI session: |
| 52 | + ```bash |
| 53 | + copilot |
| 54 | + ``` |
16 | 55 |
|
17 | | -1. (replace-me: First instruction) |
18 | | -1. (replace-me: Second instruction) |
19 | | -1. (replace-me: Additional instructions as needed) |
| 56 | +1. Ask Copilot CLI to help you create another issue for expanding the calculator: |
| 57 | + ``` |
| 58 | + Help me create a GitHub issue to add more operations to my calculator. I want to add modulo, exponentiation (power), and square root functions with proper error handling. |
| 59 | + ``` |
| 60 | + |
| 61 | +1. Or use the `/delegate` command to create the issue: |
| 62 | + ``` |
| 63 | + /delegate Create a GitHub issue titled "Add More Operations to Calculator" requesting modulo, exponentiation, and square root functions to be added to calculator.js with error handling |
| 64 | + ``` |
| 65 | + |
| 66 | +1. Work with Copilot CLI to implement the new operations: |
| 67 | + ``` |
| 68 | + Help me add these functions to my calculator.js: |
| 69 | + 1. modulo(a, b) - returns the remainder of a divided by b |
| 70 | + 2. power(base, exponent) - returns base raised to the exponent |
| 71 | + 3. squareRoot(n) - returns the square root of n with error handling for negative numbers |
| 72 | + ``` |
| 73 | + |
| 74 | +1. Alternatively, use the headless mode: |
| 75 | + ```bash |
| 76 | + copilot -p "Add modulo, exponentiation (power), and square root functions to a Node.js calculator module. Include proper error handling for edge cases like negative square roots." |
| 77 | + ``` |
| 78 | + |
| 79 | +1. Update your `calculator.js` file with the new functions |
| 80 | + |
| 81 | +1. Test your new functions: |
| 82 | + ```bash |
| 83 | + node -e "const calc = require('./calculator'); console.log('5 % 2 =', calc.modulo(5, 2)); console.log('2 ^ 3 =', calc.power(2, 3)); console.log('√16 =', calc.squareRoot(16));" |
| 84 | + ``` |
| 85 | + |
| 86 | +1. Commit your changes: |
| 87 | + ```bash |
| 88 | + git add calculator.js |
| 89 | + git commit -m "Add modulo, power, and square root operations" |
| 90 | + git push |
| 91 | + ``` |
| 92 | + |
| 93 | +> [!TIP] |
| 94 | +> Use `/share` in your Copilot CLI session to save your conversation as a Markdown file or GitHub gist for future reference! |
| 95 | +
|
| 96 | +> [!NOTE] |
| 97 | +> Creating this second issue will complete the exercise and trigger the review workflow! |
20 | 98 |
|
21 | 99 | <details> |
22 | 100 | <summary>Having trouble? 🤷</summary><br/> |
23 | 101 |
|
24 | | -- (replace-me: Troubleshooting tip or hint) |
25 | | -- (replace-me: Additional troubleshooting tips as needed) |
| 102 | +- Make sure your issue title includes "Calculator" or "Operations" |
| 103 | +- The calculator.js file should export functions that can be required/imported |
| 104 | +- You can test operations manually using Node.js REPL: `node` then type your code |
| 105 | +- For square root of negative numbers, consider returning `NaN` or throwing an error |
| 106 | +- Remember to commit and push any code changes you make |
| 107 | +- Use `copilot --help` to see all available command options |
26 | 108 |
|
27 | 109 | </details> |
0 commit comments