Exploring the Future of Coding with AI and ChatGPT
Written on
The Impact of AI on Programming
Recent advancements in artificial intelligence have brought about a transformative change in how developers approach coding. With tools like ChatGPT, users can now swiftly obtain long-form responses and even generate code. This begs the question: Do we still need traditional coding environments like Visual Studio Code, or is it time to move on?
Key Takeaways
In a recent trial with a logic puzzle, I discovered some important insights:
- Context is Crucial: Just as human programmers require context to understand code, AI also struggles without clear comments and self-descriptive variable names.
- Elevate Your Role: Developers should explore ways to integrate ChatGPT into their workflow to stay relevant in the industry. The Visual Studio Code plugin is a promising starting point.
- Emphasize Human Interaction: Software development is fundamentally a collaborative process. Building strong relationships with colleagues can provide a significant edge—after all, you can't share a high five with a machine!
- Stay Calm: There’s likely a few years left before AI can operate independently at scale without human oversight. Legal and regulatory frameworks will need to catch up, and further training for AI systems is still required.
The Visual Studio Code Experiment
The excitement surrounding AI is palpable. To illustrate its capabilities, I took on a coding challenge from CodeWars titled “Take a Ten Minute Walk.” The task was to write a C# function that checks if a provided array of directional commands would result in a walk lasting exactly ten minutes while returning to the starting point.
I input the challenge into the ChatGPT plugin for Visual Studio Code:
To my surprise, within 20 seconds, it produced the following code:
bool CheckWalkLength(string[] walk)
{
if (walk.Length == 10) {
int x = 0;
int y = 0;
foreach(string direction in walk) {
switch(direction) {
case 'n':
y++;
break;
case 's':
y--;
break;
case 'e':
x++;
break;
case 'w':
x--;
break;
}
}
return (x == 0 && y == 0);
}
return false;
}
After some minor adjustments (swapping single quotes for double quotes), the code executed successfully and solved the problem.
Explaining the Code
Next, I asked ChatGPT to provide an explanation of the generated code:
While the explanation was decent, I noticed it could be improved by incorporating more tests to cover edge cases and various input scenarios.
Analyzing the Code
I also ran a code analysis to identify any potential issues:
While the analysis was beneficial, I realized that the AI had actually written the code itself!
Next, I simplified the code by removing comments and descriptive names:
bool Check(string[] walk)
{
if (walk.Length == 10) {
int x = 0;
int y = 0;
foreach(string direction in walk) {
switch(direction) {
case 'n':
y++;
break;
case 's':
y--;
break;
case 'e':
x++;
break;
case 'w':
x--;
break;
}
}
return (x == 0 && y == 0);
}
return false;
}
Upon asking for an explanation, I found it lacking, especially without the context provided by the original comments.
Refactoring for Clarity
I then refactored the code to utilize LINQ for better readability and maintainability:
When I requested an explanation of the revised code, the response was more satisfactory, although I wished for a consistent terminology throughout.
Writing Tests
I also tasked ChatGPT with creating tests for the new code:
While the tests were improved, I still felt additional scenarios were necessary.
Lastly, I challenged the AI to solve the puzzle using only LINQ statements. It managed to do so, although the function ultimately failed to meet the requirements of the challenge.
As we continue to explore the capabilities of AI in coding, it's clear that while tools like ChatGPT are powerful, human oversight and collaboration remain indispensable.
In the video "Can you use ChatGPT in VS Code??", viewers explore the integration of ChatGPT with Visual Studio Code, demonstrating its potential for enhancing coding efficiency.
The video "ChatGPT Inside VSCode. Your new coding partner" further illustrates how ChatGPT acts as an invaluable resource for developers, providing insights and code generation capabilities.
Thank you for joining us on this journey into the future of coding!