4.5: ChatGPT for SWE

ChatGPT and its use cases

In this section we will aim to discuss and delve into the plethora of use cases offered by ChatGPT and how it can help to improve developer efficiency. It has been said by many that ChatGPT will replace developers, Rocket doesn’t believe this to be true. At the end of the day ChatGPT is actually managed and run by developers, while ChatGPT can make developers more efficient it could never completely replace developers. However, we do understand and see that developers that do use ChatGPT may increase pressure on developers who do not. ChatGPT isn’t the answer to all problems, instead it’s a fountain of knowledge that can produce a response based on the sum of all information it has been fed. This means that depending on which version you are using you may actually get different results.

Code Generation

It should be noted that ChatGPT can develop code, but it requires very specific queries and prompting which can be useful for learners and developers who are looking to become more efficient. Don't fall into the habit of using ChatGPT for everything has generally you wont be able to use it during an interview.

Documentation Diving

Despite not always having access to it, ChatGPT can empower a developer, consider what ChatGPT is and one of its use cases becomes obvious. A great use of ChatGPT is to employ it when navigating documentation or exploring an API, instead of having to digest and search through documentation or web pages you can prompt and question ChatGPT. The responses given the right guiding questions can amaze you, ChatGPT is able to produce relevant examples along with explanation and usage patterns. This can save time for teams exploring and implementing new technologies within their application.

By using ChatGPT in this fashion developers can easily learn new concepts and implementations, enhancing their knowledge in order to stay up to date with the latest trends and build mvp applications. In fact developers are even able to generate code using ChatGPT so they have a boilerplate and sample which they can work into an existing project and alter as required. It should be noted that ChatGPT can often produce code that is incomplete or needs to be refactored to fit the current project.

Expose Inefficiencies and Fix Bugs

Another great way to use ChatGPT is to check your code for inefficiencies or bugs, use it as a brainstorming soundboard, it will often inform you of interesting approaches to potential solutions, its even possible to uncover new perspectives if you use ChatGPT in this manner. To utilise ChatGPT in this way one would need to explain the current implementation as well as issue such that ChatGPT can provide debugging strategies or solutions. While you can find great solutions using ChatGPT it is important to understand what you are implementing into your application, especially when questioned during a sprint review.

There are many ways that one can use ChatGPT to improve their code and development cycle, while it is an important tool to utilise Rocket still recommends reaching out to team mates and peers to brainstorm concerning difficult bugs or implementations. If your team is unable to resolve the issue its possible that you then communicate the issue to relevant communities or even providers when facing bugs.

As a leaner at Rocket Academy, we advise you to utilise ChatGPT, but not to be dependant on it. If you are struggling with an explanation that is provided, do some research to understand the underlying points that ChatGPT tends to glass over. With this in mind if you want to explore using AI tools to help with your work consider using Github Co-pilot to develop code to implement.

To use co-pilot for free, you can try sign up and indicate that you are a part of Rocket Academy's coding bootcamp by showing a invoice that is fulfilled. This will allow you to utilise Github's generative AI tool to write code, tests and much more. To explore what is possible please look into this link, to signup please follow the instructions here.

What are prompts?

To use ChatGPT you will need to prompt, this is the foundation of communication between the AI model that is ChatGPT and humans. Users will need to provide detailed instructions and queries to produce the relevant and desired output from the model. It is important to understand the capabilities of ChatGPT within the domain that you use it, this will ultimately save time during querying.

A prompt is the input provided to ChatGPT to express the desired context for the query being stated. If one is able to effectively prompt users can guide the AI model to produce brilliant responses. Users can prompt in a variety of ways, you can post prompts as sentences, questions or even by instruction. The structure and formula of the prompt is vital for accurate and relevant responses.

Here is an interesting resource to delve into the world of ChatGPT prompts, it provides some examples per industry that you can model to make your queries. In anycase what follows is some advice on how you can prompt ChatGPT.

Contextual Details

To get the best results from ChatGPT developers will need to provide the relevant information within the queries so that the AI tool is able to understand the specific context and scenario. Try your best to include background information, specific facts to use or leverage as well as user preferences this can help to generate an accurate response.

Specificity is an important factor while using ChatGPT, one could create a simple and generic prompt like so:

'Write a JavaScript function that will add two numbers together'.

Here is the response:

While this code is decent, it might be written in the style, syntax or function name, so we can refine the prompt to be more detailed:

'Write a JavaScript function called 'combineNumbers' that uses arrow syntax, this function should add two numbers together, pass in the default values of 4 and 10 if no numbers are provided'

Here is the response:

Feed in content or Reference Material

There are times that providing context isn't enough to generate an accurate response to your query, this is because ChatGPT is unable to browse the web unless you've a paid subscription or plugin. If you want to reference specific information you may need to provide the content. If you need Domain-specific knowledge you will need to include it when prompting. If you want a response written in a particular manner, you can share content to ChatGPT to keep writing consistent. Feed in accurate and verified information such that ChatGPT has reliable responses. Include any specific guidelines or rules that ChatGPT needs to follow. If you are looking to a modern answer that is not based from the year 2021, I would advise you to provide additional data.

Do not feed ChatGPT sensitive personal or company information, as once you prompt with it, it becomes available to all users.

State the Desired Context and Task

Be as explicit as possible when querying on ChatGPT this facilitates detailed and focused answers. If you want ChatGPT to write tests for a portion of code or test in a specific way, define this when you prompt.

For example take the combineNumbers function we developed earlier, we could use ChatGPT to write some unit tests for the application.

Here is an example prompt:

"Please write some Jest JavaScript unit tests for this function, const combineNumbers = (a = 4, b = 10) => a + b; provide at least 5 tests for the function."

Here is the response:

Provide Parameters, Control Variables, Specify Format

Define a guide for your response, define the boundaries of the response, how much do you want back as a response. Do you want a detailed explanation or some code samples and implementation information? ChatGPT is great for developing responses within the defined parameters.

Verify any information that ChatGPT provides as a response, at this stage, ChatGPT is notorious for providing inaccurate information.

Explicitly state how you want to format your response, you might be after a pros and cons list or a 6 paragraph 500 word essay, with an introduction, body and end. This can help ChatGPT to develop a helpful response for your query.

Leveraging ChatGPT within Applications

When developing applications you might want to give your users some AI assistance, by creating an application that captures a users inputs you can prefabricate prompts that can be edited by users. This will result in unique responses depending on the input of the user. It is possible to generate many types of queries for your users to utilise, you could also let users directly prompt the AI model. While this is an interesting feature to implement this can incur heavy charges depending on the service your application leverages. That being said, the feature is at the mercy of the ChatGPT server and its server maintenance, as the feature relies on the ability to query.

Conclusions

ChatGPT, as a language model developed by OpenAI, is undeniably a remarkable tool for developers to leverage in their work. Its ability to generate coherent and contextually relevant responses makes it a valuable resource for addressing queries, exploring ideas, and assisting with various coding tasks. However, it is essential to recognise that ChatGPT, like any AI system, has its limitations and potential inefficiencies. It may occasionally provide inaccurate or incomplete information, and its responses should be critically evaluated. While ChatGPT can greatly enhance productivity and creativity, it is crucial for developers to exercise caution, validate its outputs, and leverage their own expertise to ensure the accuracy and reliability of the final results.

The paragraph above was generated using ChatGPT, while Rocket Academy accepted 95% of the answer, we had to preform some minor edits before publishing this generated portion. With this in mind Rocket Academy, believe that developers should utilise ChatGPT to speed up development cycles and explore new avenues of implementation. Use ChatGPT to dive into unfamiliar documentation, to develop simple prototype code, use the tool to reduce repetitive tasks like creating unit tests and leverage the tool to gain a better understanding of an implementation. But, Rocket reminds you, do not become to dependant on ChatGPT, always check the generated responses and do additional research into the explanation's received.

Last updated