It’s clear that developers who master these tools and embrace innovation will stand apart from developers who lag behind and who choose to ignore them. We’ve dug into ChatGPT and found the best use cases and technical prompts so you can start to pair programming with ChatGPT and set yourself ahead of the rest.
In my view, technical documentation is one of the most important aspects of software development. It helps onboard new developers, maintain the codebase, and improve the overall bus actor. However, writing documentation can be a time-consuming and challenging task, requiring a comprehensive understanding of the project and exceptional organizational skills. This can lead to technical documentation being incomplete, outdated, or neglected.
ChatGPT can generate technical documentation for your code following a specific style. This feature can save you a considerable amount of time and effort, allowing you to focus on other essential aspects of software development.
Prompt example for generating technical documentation with ChatGPT
As developers, it’s not uncommon to stumble upon convoluted and confusing code that leaves us questioning its origin (often our own past selves). ChatGPT can help unravel the tangled mess, providing comprehensive explanations for each line of code, making the process of understanding and untangling spaghetti code much more manageable and less daunting.
Prompt: “Based on the provided code snippet or the code located at this URL, could you please generate comprehensive technical documentation? I’d like to include explanations of the code’s purpose, main functions, and any notable dependencies or prerequisites. Here’s the code/reference: [insert code snippet or URL here].”
Use ChatGPT to Help with Reminders and Tutorials
When faced with a complex code snippet, asking for a detailed explanation of its purpose, logic, and intended outcome can be a valuable exercise. ChatGPT can help you deconstruct the code and understand its inner workings, reinforcing your knowledge and familiarity with the concepts and techniques used.
Prompt: “Looking at the following code snippet, could you provide a detailed explanation of its purpose, the logic behind its operations, and the outcome it’s intended to produce?”
Use ChatGPT to Assist with Debugging
Despite having plenty of debugging tools at our disposal, we sometimes find ourselves struggling with code that should work but doesn’t. This can be further complicated by error codes that provide no clues about what’s really going on.
With ChatGPT, you can quickly identify the issue and receive suggestions for solutions, much faster than browsing through resources like StackOverflow. By providing a prompt like “My code isn’t working, can you help me debug it?” along with the code or URL, ChatGPT can help you identify the root cause of the problem and provide you with possible solutions.
Prompt: “I’m trying to [describe the specific action or result you’re trying to achieve] but something’s not working as expected. Could you help me debug it? Here’s the code: [insert code snippet].”
Use ChatGPT to Identify Security Issues
While ChatGPT is not a substitute for a dedicated security expert, it can still help you identify potential security issues in your code, including actual code problems and insecure dependencies. This can speed up development timelines and help produce secure code (especially if you’re a small company and don’t have a dedicated security dev).
For instance, ChatGPT can analyze your codebase and suggest areas that may require further attention. This can help you identify potential vulnerabilities early on, allowing you to take appropriate measures to address them before they become a bigger problem.
Prompt: “I want to make sure my code is secure and doesn’t have any glaring vulnerabilities. Could you do a sweep for potential security issues? Here’s the code or the URL where you can find it: [insert code snippet or URL].”
ChatGPT can provide support in several other areas of accessibility. For instance, it can help identify and suggest improvements for color contrast issues to ensure content is readable for individuals with visual impairments. Additionally, ChatGPT can assist in optimizing semantic structure by suggesting proper heading hierarchy, landmark roles, and ARIA attributes, enhancing the screen reader experience. Furthermore, ChatGPT can provide guidance on responsive design and mobile accessibility, ensuring that your application is accessible across different devices and screen sizes. With its vast language processing capabilities, ChatGPT is a valuable tool for developers seeking to create inclusive and accessible digital experiences.
Prompts: “I’m trying to ensure my code is as accessible as possible, but I might be missing something. Could you give it a once-over for potential accessibility issues? Here’s the code snippet I’m working with: [insert code snippet].”
It’s important to note that ChatGPT is not a substitute for an accessibility expert or thorough accessibility testing. Good accessibility requires a comprehensive understanding of your application and users that goes beyond what can be prompted through input. Nonetheless, it can still be a valuable tool to help identify issues and save you time.
Ask ChatGPT to Generate Pieces of Code
ChatGPT can assist you in generating code tailored to your specific needs. Whether it involves working with multiple files, adhering to a particular architecture and style guide, or customizing the code according to your preferences, ChatGPT can adapt accordingly.
For example, you can ask ChatGPT to create a JavaScript script that prints numbers from 1 to 50 while replacing specific numbers with corresponding words based on divisibility rules. By requesting this task, ChatGPT will generate a script that incorporates the required logic and provide a detailed explanation of how it was implemented. Moreover, you have the flexibility to ask follow-up questions and modify your initial instructions, allowing you to refine and adjust the generated code as needed.
Prompt: “I need a script written in [insert language here]. The task I want it to accomplish is [describe the task in detail – what it needs to do, any specific inputs/outputs, etc.]. Could you draft a solution?”
To give you an idea of ChatGPT’s programming capabilities, it performs well on most of the easy tests in LeetCode, over a quarter of the medium ones, and a couple of the hard ones. While this may not sound exceptional, it’s comparable to most mid-level to senior developers who aren’t particularly focused on competitive programming.
However, the main limitation to ChatGPT’s programming ability remains its understanding of the task itself. For example, in this video, a physics professor asked it to write a program. While its answer was impressive from a programming perspective, it lacked a fundamental understanding of the problem. Most of us don’t deal with such advanced concepts in our everyday jobs, but the issue remains the same. ChatGPT is prone to make incorrect assumptions that lead it in the wrong direction. Still, usually, it can correct itself with your input. Remember that ChatGPT is supposed to be conversational, so if you need it to polish up some parts of the code, you can guide it to a better answer. For example, ask: “The code works great! My only concern is with the complexity of the mapping function. Are you sure that’s the most efficient way to do it?”
ChatGPT may provide correct reasoning but incorrect code, or vice versa, so copy-pasting without much analysis can be problematic. In a way, coding with ChatGPT can feel like pair programming or doing a code review with a very fast and talented junior developer who still requires some input from someone more experienced.
Ask ChatGPT to Refactor and Optimize Code
ChatGPT can be a valuable tool for organizing and maintaining the readability of your code. You can ask it to follow specific guidelines to polish up your code, refactor it according to a given architecture, or optimize it following best practices.
One limitation of using ChatGPT for refactoring is that the training model is a couple of years behind, which means your “refactored” code may lack some modern features or use deprecated code. However, there is a workaround for some of these cases. You can feed ChatGPT the repository URL for your library first and then ask it to use it while answering the prompt for refactoring. This will make ChatGPT aware of the features during the interaction and often leads to a flawless implementation.
Prompt: “I’d like you to refactor some code according to the [insert specific architecture/style guide]. Here are some key areas I think could be improved: [mention any specific areas or aspects you think need improvement, if any]. Here’s the code or the URL where you can find it: [insert code snippet or URL].”
Ask ChatGPT to Convert Code From One Language to Another
ChatGPT is capable of converting code from one programming language to another, functioning as a sort of Rosetta Stone for programming.
For instance, you can use the following prompt to convert Python code to JavaScript: “I have a piece of code here that’s currently written in [current language]. Could you help me translate it to [desired language]? The functionality should remain the same. Here’s the code snippet: [insert code snippet].”
This feature is most useful when learning a new programming language. The choice of programming language typically depends on platform-specific factors and architectural decisions, so it’s not always straightforward to switch between languages.
If you need to fill out a table with dummy data and don’t have a seeder available, ChatGPT can be incredibly helpful. The tool can provide data on any topic you ask it to or even infer the data type required based on the header names. It can also generate data in multiple formats, including CSV and SQL queries.
Prompt: “I’m working with a table that has the following structure: [describe the structure in detail, including fields and data types]. Could you help me generate some dummy data for this table, formatted in [specify format – e.g., JSON, CSV, XML]? The dummy data should align with the field types and represent realistic values.”
Writing tests is a critical aspect of the development process, but it’s also one that many developers find tedious. Fortunately, ChatGPT can generate tests for your code, provided that you explain the expected behavior clearly. However, it’s essential to use this feature responsibly and always double-check the tests generated by ChatGPT, as it may write tests designed to pass, like a lazy programmer.
Prompt: “I’m gearing up to write a script that’s supposed to [describe task in detail]. Before I dive into the coding part, I want to set up some tests for Test-Driven Development (TDD). Could you help me draft a test that checks for these specific aspects: [enumerate points to be checked in the test]?”
ChatGPT is a powerful tool for generating configuration files tailored to your specific stack. It not only generates the file but also explains the key parts of how everything works and guides you through the changes you’ll need to make in your local environment. Additionally, if you need to install a new library or tool, ChatGPT can provide on-demand tutorials to help you get up and running.
Prompts: “I’m setting up a project with [library/framework/tool], and I need a config file that meets these specific conditions: [list conditions in detail, specifying any required parameters, settings, or environment variables]. Could you help me draft a suitable config file?”
ChatGPT can translate conversational input into the precise command or expression you require, while also providing a clear explanation of each part. In my opinion, this is one of the most valuable ways in which the tool can assist you, especially if you struggle with regular expressions.
Prompts: “Create a regular expression (RegEx) that checks for a [pattern], following the format [format].”
Naming is often one of the most challenging parts of programming, but ChatGPT can be incredibly helpful when it comes to suggesting names at any scope level. Whether you need more meaningful variable names based on your code or consistent naming conventions for CSS classes, ChatGPT can assist you. It can even provide suggestions for naming your entire application or project.
ChatGPT is an incredibly powerful tool that experienced developers can leverage to increase their productivity. It can automate processes within your application, help keep good documentation, or even write the actual code. The possibilities are endless, but there are still some tasks that it cannot perform as well as a human yet. In time, it may get there, just like chess grandmasters who could still beat computer programs in the early ’90s, only to be absolutely dominated by them by the end of the decade.
The main limiting factor to ChatGPT’s answers is your ability to prompt the right questions in the first place. Knowing how to prompt the AI and guiding it through answer refinement can become the new Google-fu, so you better start training! Whether you’re designing a virtual assistant, augmenting a customer support system, building educational tools, or even automating content creation, the versatile application of ChatGPT makes it a must-have tool for every developer’s toolkit