Skip to content

Commit a6cd662

Browse files
committed
acrolinx updates
1 parent 1e02385 commit a6cd662

1 file changed

Lines changed: 29 additions & 29 deletions

File tree

Instructions/Labs/LAB_AK_07_consolidate_duplicate_code.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ lab:
66

77
# Consolidate duplicate code using GitHub Copilot
88

9-
Duplicate code logic is often introduced when developing/extending a codebase that includes similar or related features. It may not be intentional, and it can be as simple as reusing code to prototype a new feature. If duplicated logic evolves to match the surrounding code over time, the issue can become more complicated. Changes to variable names, function names, and code structures in one location (but not the another) can mask duplicated logic. A rushed schedule, poor documentation, and a lack of proper code reviews can exacerbate the issue. In the end, duplicated logic makes the code difficult to read, maintain, debug, and test.
9+
Duplicate code logic is often introduced when developing/extending a codebase that includes similar or related features. It might not be intentional, and it can be as simple as reusing code to prototype a new feature. If duplicated logic evolves to match the surrounding code over time, the issue can become more complicated. Changes to variable names, function names, and code structures in one location (but not the other) can mask duplicated logic. A rushed schedule, poor documentation, and a lack of proper code reviews can exacerbate the issue. In the end, duplicated logic makes the code difficult to read, maintain, debug, and test.
1010

1111
In this exercise, you review an existing project that contains duplicated code logic, analyze your options for consolidation, consolidate the duplicated code logic, and test the refactored code to ensure it works as intended. You use GitHub Copilot in Ask mode to gain an understanding of an existing code project and explore options for consolidating the logic. You use GitHub Copilot in Agent mode to refactor the code by combining duplicate logic into shared helper methods. You test the original and refactored code to ensure the consolidated logic works as intended.
1212

@@ -16,19 +16,19 @@ This exercise should take approximately **30** minutes to complete.
1616
1717
## Before you start
1818

19-
Your lab environment must include the following: Git 2.48 or later, .NET SDK 9.0 or later, Visual Studio Code with the C# Dev Kit extension, and access to a GitHub account with GitHub Copilot enabled.
19+
Your lab environment must include the following resources: Git 2.48 or later, .NET SDK 9.0 or later, Visual Studio Code with the C# Dev Kit extension, and access to a GitHub account with GitHub Copilot enabled.
2020

2121
### Configure your lab environment
2222

2323
If you're using a local PC as a lab environment for this exercise:
2424

25-
- For help configuring your local PC as your lab environment, open the following link in a browser: <a href="https://go.microsoft.com/fwlink/?linkid=2320147" target="_blank">Configure your lab environment resources</a>.
25+
- For help with configuring your local PC as your lab environment, open the following link in a browser: <a href="https://go.microsoft.com/fwlink/?linkid=2320147" target="_blank">Configure your lab environment resources</a>.
2626

27-
- For help enabling your GitHub Copilot subscription in Visual Studio Code, open the following link in a browser: <a href="https://go.microsoft.com/fwlink/?linkid=2320158" target="_blank">Enable GitHub Copilot within Visual Studio Code</a>.
27+
- For help with enabling your GitHub Copilot subscription in Visual Studio Code, open the following link in a browser: <a href="https://go.microsoft.com/fwlink/?linkid=2320158" target="_blank">Enable GitHub Copilot within Visual Studio Code</a>.
2828

2929
If you're using a hosted lab environment for this exercise:
3030

31-
- For help enabling your GitHub Copilot subscription in Visual Studio Code, paste the following URL into a browser's site navigation bar: <a href="https://go.microsoft.com/fwlink/?linkid=2320158" target="_blank">Enable GitHub Copilot within Visual Studio Code</a>.
31+
- For help with enabling your GitHub Copilot subscription in Visual Studio Code, paste the following URL into a browser's site navigation bar: <a href="https://go.microsoft.com/fwlink/?linkid=2320158" target="_blank">Enable GitHub Copilot within Visual Studio Code</a>.
3232

3333
- To ensure that the .NET SDK is configured to use the official NuGet.org repository as a source for downloading and restoring packages:
3434

@@ -96,9 +96,9 @@ Use the following steps to download the sample project and open it in Visual Stu
9696
9797
## Exercise scenario
9898
99-
You're a software developer working for a consulting firm. Your clients need help consolidating duplicate code logic. Your goal is to improve code maintainability while preserving the existing functionality. You're assigned to the following app:
99+
You're a software developer working for a consulting firm. Your clients need help with consolidating duplicate code logic. Your goal is to improve code maintainability while preserving the existing functionality. You're assigned to the following app:
100100
101-
- E-CommerceOrdersAndReturns: This is an E-commerce app that processes customer orders and handles product returns. It includes core business logic for validating orders and returns, calculating shipping costs, sending email notifications, logging audit activities, and managing inventory levels.
101+
- E-CommerceOrdersAndReturns: This app is an E-commerce app that processes customer orders and handles product returns. It includes core business logic for validating orders and returns, calculating shipping costs, sending email notifications, logging audit activities, and managing inventory levels.
102102
103103
This exercise includes the following tasks:
104104
@@ -111,7 +111,7 @@ This exercise includes the following tasks:
111111
112112
The first step in any refactoring effort is to ensure that you understand the existing codebase. It's important to understand the code structure, the business logic, and the results generated when the code runs.
113113

114-
In this task, you'll review the main components of the E-commerce order and return processing project, scan the code for duplicate code patterns, and test the code.
114+
In this task, you review the main components of the E-commerce order and return processing project, scan the code for duplicate code patterns, and test the code.
115115

116116
Use the following steps to complete this task:
117117

@@ -123,13 +123,13 @@ Use the following steps to complete this task:
123123

124124
Open **OrderProcessor.cs** and **ReturnProcessor.cs** side by side. These classes represent the core business logic for processing customer orders and product returns respectively.
125125

126-
Notice that the two classes have similar method signatures and processing patterns. This is the most obvious type of duplication, but there are additional, more subtle duplications throughout the codebase.
126+
Notice that the two classes have similar method signatures and processing patterns. This similarity is the most obvious type of duplication, but there are other, more subtle duplications throughout the codebase.
127127

128128
1. Review the Services layer.
129129

130130
Navigate to the **Services** folder and examine **EmailService.cs**, **AuditService.cs**, and **InventoryService.cs**.
131131

132-
You may notice that these services implement similar patterns for handling email notifications, audit logging, and inventory management. Each service has methods that follow similar structures but are duplicated for different business processes (orders vs returns).
132+
You might notice that these services implement similar patterns for handling email notifications, audit logging, and inventory management. Each service has methods that follow similar structures but are duplicated for different business processes (orders vs returns).
133133

134134
1. Run the application and review the console output.
135135

@@ -145,7 +145,7 @@ Use the following steps to complete this task:
145145
- Updated inventory levels
146146
- Security validation tests with various invalid inputs
147147
148-
The application runs 5 test scenarios to demonstrate both successful processing and security validation failures.
148+
The application runs five test scenarios to demonstrate both successful processing and security validation failures.
149149
150150
1. Take a minute to categorize any duplicate code patterns that you observed.
151151
@@ -161,7 +161,7 @@ It's important to understand the existing functionality before making changes. B
161161
162162
GitHub Copilot Chat's Ask mode is a great tool for analyzing complex codebases and identifying subtle duplication patterns that might not be immediately obvious. In Ask mode, Copilot acts as an intelligent code reviewer that can analyze multiple files simultaneously and identify both obvious and hidden (code logic) duplications.
163163

164-
In this task, you'll use GitHub Copilot to systematically identify the various types of duplicate code patterns in the e-commerce application.
164+
In this task, you use GitHub Copilot to systematically identify the various types of duplicate code patterns in the e-commerce application.
165165

166166
Use the following steps to complete this task:
167167

@@ -193,7 +193,7 @@ Use the following steps to complete this task:
193193
194194
1. Take a minute to review GitHub Copilot's response.
195195

196-
GitHub Copilot should identify the `Validate()` method duplication and the similar patterns in `CalculateShipping()` methods. It may also note similar patterns in relation to audit logging, error handling, and payment/refund processing.
196+
GitHub Copilot should identify the `Validate()` method duplication and the similar patterns in `CalculateShipping()` methods. It might also note similar patterns in relation to audit logging, error handling, and payment/refund processing.
197197
198198
1. Update the chat context to specify the **EmailService.cs** file.
199199
@@ -209,7 +209,7 @@ Use the following steps to complete this task:
209209
210210
1. Take a minute to review GitHub Copilot's response.
211211
212-
GitHub Copilot should identify the duplicate logic for handling order confirmations and return confirmations. This includes a templated approach to preparing and sending emails. GitHub Copilot may also identify duplicate patterns related to helper methods and console output.
212+
GitHub Copilot should identify the duplicate logic for handling order confirmations and return confirmations. The response includes a templated approach to preparing and sending emails. GitHub Copilot might also identify duplicate patterns related to helper methods and console output.
213213
214214
1. Update the chat context to specify the **AuditService.cs** and **InventoryService.cs** files.
215215
@@ -225,7 +225,7 @@ Use the following steps to complete this task:
225225
226226
1. Take a minute to review GitHub Copilot's response.
227227
228-
GitHub Copilot should identify patterns like audit entry creation/validation/storage in AuditService, and inventory validation/updating/logging in InventoryService. GitHub Copilot may also identify duplicate patterns related to helper methods.
228+
GitHub Copilot should identify patterns like audit entry creation/validation/storage in AuditService, and inventory validation/updating/logging in InventoryService. GitHub Copilot might also identify duplicate patterns related to helper methods.
229229
230230
1. Ask GitHub Copilot to perform a comprehensive duplication analysis.
231231
@@ -235,7 +235,7 @@ Use the following steps to complete this task:
235235
@workspace Analyze the entire ECommerceOrderAndReturn codebase and identify all forms of code duplication, including method-level, service-level, and architectural pattern duplications. Prioritize the duplications by impact and refactoring difficulty. Describe an approach for consolidating this code.
236236
```
237237
238-
After analyzing specific files, you can get a broader view by asking GitHub Copilot to include the entire codebase in its analysis. The increased scope can reveal additional duplication patterns, such as similar error handling, logging, and validation logic across multiple files or layers. Having a single response that informs and prioritizes your refactoring strategy is often helpful.
238+
After analyzing specific files, you can get a broader view by asking GitHub Copilot to include the entire codebase in its analysis. The increased scope can reveal other duplication patterns, such as similar error handling, logging, and validation logic across multiple files or layers. Having a single response that informs and prioritizes your refactoring strategy is often helpful.
239239
240240
> **NOTE**: The `@workspace` and `#codebase` keywords tell GitHub Copilot to include the entire codebase in the context of its analysis. The `@workspace` keyword is only available when using GitHub Copilot in the Ask mode. The `#codebase` keyword can be used in any mode (Ask, Edit, or Agent).
241241

@@ -261,21 +261,21 @@ Use the following steps to complete this task:
261261
262262
Cross-reference GitHub Copilot's findings with your own observations. Ensure that you understand not just what is duplicated, but why these patterns exist and how they should be consolidated while maintaining the business logic integrity.
263263

264-
GitHub Copilot's Ask mode is particularly powerful for identifying subtle duplications that go beyond simple copy-paste scenarios. It can recognize similar logical patterns, equivalent business rules implemented differently, and architectural duplications that span multiple files.
264+
GitHub Copilot's Ask mode is good at identifying subtle duplications that go beyond simple copy-paste scenarios. It can recognize similar logical patterns, equivalent business rules implemented differently, and architectural duplications that span multiple files.
265265
266266
> **NOTE**: The analysis generated during this task is used to inform the refactoring strategy that you implement in the next section.
267267
268268
### Consolidate duplicate logic using GitHub Copilot Chat (Agent mode)
269269
270-
GitHub Copilot's Agent mode enables you to assign complex, multi-step refactoring tasks that span multiple files and architectural layers. The agent can autonomously create new files, modify existing code, and implement comprehensive refactoring strategies while keeping you informed of its progress.
270+
GitHub Copilot's Agent mode enables you to assign moderately complex, multi-step refactoring tasks that span multiple files and architectural layers. The agent can autonomously create new files, modify existing code, and implement comprehensive refactoring strategies while keeping you informed of its progress.
271271

272-
In this task, you'll use GitHub Copilot Agent to systematically eliminate the duplicate code patterns identified in the previous task, starting with the most straightforward duplications and progressing to more complex service-layer consolidations.
272+
In this task, you use GitHub Copilot Agent to systematically eliminate the duplicate code patterns identified in the previous task, starting with the most straightforward duplications and progressing to more complex service-layer consolidations.
273273

274274
Use the following steps to complete this task:
275275

276276
1. Switch the GitHub Copilot Chat view to Agent mode.
277277

278-
When using Agent mode, GitHub Copilot can make autonomous changes to your codebase. Agent mode is particularly useful for complex, multi-step refactoring tasks.
278+
When you use Agent mode, GitHub Copilot can make autonomous changes to your codebase. Agent mode is good at moderately complex, multi-step refactoring tasks.
279279

280280
To change modes, locate the mode selector (typically in the bottom-left corner of the Chat view) and select **Agent**.
281281

@@ -309,13 +309,13 @@ Use the following steps to complete this task:
309309
310310
The agent's progress should be visible in the chat as it completes the assigned task.
311311
312-
To assist the agent as the task is being processed, provide permission to continue or supply additional context as needed. For example, if the agent asks for permission to Build or Run the application, select **Continue**
312+
To assist the agent as the task is being processed, provide permission to continue or supply more context as needed. For example, if the agent asks for permission to Build or Run the application, select **Continue**
313313
314-
The agent will accomplish the following during this task:
314+
The agent completes the following steps during this task:
315315
316316
- Create a new **ValidationService.cs** file in the Services folder
317317
- Extract the validation logic into a reusable method
318-
- Update both processor classes to use the new service
318+
- Update both processor classes (to use the new service)
319319
- Remove the duplicate private validation methods
320320
- Verify functionality with a successful build and test run
321321
@@ -387,9 +387,9 @@ GitHub Copilot Agent excels at complex, multi-file refactoring tasks that requir
387387
388388
### Test the refactored E-commerce orders and returns code
389389
390-
Manual testing and verification is crucial to ensure that your refactored code maintains the intended business logic and functionality. A successful refactoring process should achieve the intended goal (such as consolidating duplicate code logic) while producing identical behavior to the original implementation.
390+
Manual testing and verification are crucial to ensure that your refactored code maintains the intended business logic and functionality. A successful refactoring process should achieve the intended goal (such as consolidating duplicate code logic) while producing identical behavior to the original implementation.
391391
392-
In this task, you'll verify that the refactored code maintains all original functionality and that the consolidation has been successful.
392+
In this task, you verify that the refactored code maintains all original functionality and that the consolidation was successful.
393393
394394
Use the following steps to complete this task:
395395
@@ -399,7 +399,7 @@ Use the following steps to complete this task:
399399
400400
1. Run the refactored application and capture the output.
401401
402-
The application should run all 5 test scenarios exactly as before:
402+
The application should run all five test scenarios exactly as before:
403403
404404
- Initial inventory display
405405
- Valid order processing with complete workflow
@@ -429,14 +429,14 @@ Use the following steps to complete this task:
429429
- **Maintainability**: Changes to business rules now require updates in only one location
430430
- **Readability**: The code structure is clear and logical
431431
- **Reusability**: Shared services can be easily extended for future requirements
432-
- **Extensibility**: New features can be added with minimal impact on existing code
432+
- **Extensibility**: New features can be added with minimal effect on existing code
433433
434-
Manual testing verifies that your consolidation efforts have achieved the intended goal: eliminating duplicate code while maintaining system functionality. The architecture now provides a more maintainable foundation for future development, where business rule changes can be implemented in a single location rather than requiring updates across multiple duplicate implementations.
434+
Manual testing verifies that your consolidation efforts achieved the intended goal: eliminating duplicate code while maintaining system functionality. The architecture now provides a more maintainable foundation for future development, where business rule changes can be implemented in a single location rather than requiring updates across multiple duplicate implementations.
435435
436436
## Summary
437437
438438
In this exercise, you learned how to use GitHub Copilot to consolidate duplicate code in an application. You explored the E-commerce Order and Return Processing System, identified duplicate code patterns, and used GitHub Copilot to refactor the codebase for improved maintainability and readability.
439439
440440
## Clean up
441441
442-
Now that you've finished the exercise, take a minute to ensure that you haven't made changes to your GitHub account or GitHub Copilot subscription that you don't want to keep. If you made any changes, revert them as needed. If you're using a local PC as your lab environment, you can archive or delete the sample projects folder that you created for this exercise.
442+
Now that you finished the exercise, take a minute to ensure that you haven't made changes to your GitHub account or GitHub Copilot subscription that you don't want to keep. If you made any changes, revert them as needed. If you're using a local PC as your lab environment, you can archive or delete the sample projects folder that you created for this exercise.

0 commit comments

Comments
 (0)