Role of Chat GPT in Computer Programming
Role of Chat GPT in Computer Programming
Role of Chat GPT in Computer Programming
net/publication/369202498
CITATIONS READS
8 687
1 author:
Som Biswas
The University of Tennessee Health Science Center
70 PUBLICATIONS 254 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
All content following this page was uploaded by Som Biswas on 14 March 2023.
Research Article
Role of ChatGPT in Computer Programming.
Som Biswas1,*,
1 Department of Radiology, UTHSC College of Medicine Memphis: The University of Tennessee Health Science Center College of Medicine,
Memphis, TN, 38103, USA
1. Introduction
Computer programming is a complex field that requires a deep understanding of programming languages, algorithms, and
data structures. It can be challenging for developers to keep up with the latest technologies and best practices, as well as
diagnose and resolve technical problems. This is where ChatGPT, a language model developed by OpenAI, comes in.
ChatGPT offers a wide range of capabilities for computer programming, including code completion, correction, prediction,
error fixing, optimization, document generation, chatbot development, text-to-code generation, and technical query
answering. With its ability to provide explanations, examples, and guidance, ChatGPT is a valuable resource for technical
support and its programming-related capabilities can improve efficiency and accuracy for developers and organizations. This
paper will outline the role and capabilities of ChatGPT in computer programming [1][2].
2. State of the art
ChatGPT can be used as a tool in computer programming for various tasks such as:
1. Code Completion and Correction
2. Document generation
3. Chatbot development
4. Text-to-Code Generation
5. Answering technical queries.
It can be integrated into programming environments to improve developer productivity and speed up the coding process.
However, ChatGPT is not a full-fledged programming language and still requires human intervention for more complex
tasks.
python
numbers = [1, 2, 3]
sum = 0
for num in numbers:
sum += num
ChatGPT, recognizing the context of the code, can suggest the following code snippet to the developer:
10 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
python
print(f"The sum of numbers is {sum}")
The developer can then simply copy and paste this snippet into their code to print the result of the sum. In this manner,
ChatGPT can help developers write code more efficiently and quickly.
Role of ChatGPT in Automatically fixing syntax errors and common mistakes with examples
Here's an example of ChatGPT automatically fixing syntax errors and common mistakes:
Suppose a developer is writing a JavaScript function and has made a syntax error:
javascript
function addTwoNumbers(a, b) {
return a + b
}
ChatGPT can detect the missing
semicolon at the end of the return statement
and suggest the following correction:
javascript
function addTwoNumbers(a, b) {
return a + b;
}
By making this correction, the developer can avoid potential syntax errors that may cause problems in their code. In this
manner, ChatGPT can help developers write error-free code more efficiently.
Role of ChatGPT in Providing suggestions for code optimization and refactoring In Providing suggestions for code
optimization and refactoring, ChatGPT can be used to:
1. Analyze code for performance bottlenecks and suggest optimization techniques
2. Identify code duplication and suggest ways to refactor the code for improved readability and maintainability
3. Recommend design patterns and best practices for structuring code
4. Provide suggestions for reducing code complexity
By utilizing ChatGPT in this manner, developers can improve the performance and maintainability of their code, making it
easier to scale and update in the future.
Role of ChatGPT in Providing suggestions for code optimization and refactoring with examples.
Here's an example of ChatGPT providing suggestions for code optimization and refactoring:
Suppose a developer has written a function to search for an item in a list of dictionaries:
11 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
python
def search_item(item_name, item_list):
for item in item_list:
if item['name'] == item_name:
return item
return None
ChatGPT can analyze the code and
suggest the following refactoring to improve
performance:
python
def search_item(item_name, item_list):
item_dict = {item['name']: item for item
in item_list}
return item_dict.get(item_name)
By refactoring the code in this manner, the function will be much faster for large lists since it uses a dictionary to store the
items. In this manner, ChatGPT can help developers optimize their code for better performance.
Role of ChatGPT in Generating missing code based on the context of the project.
In Generating missing code based on the context of the project, ChatGPT can be used to:
1. Analyze the existing code and generate missing code snippets to complete the project
2. Consider the dependencies, constraints, and desired outcome of the project to generate relevant code
3. Use its vast knowledge base of programming languages and libraries to generate accurate and efficient code
4. Learn from the coding style and preferences of the user to make better suggestions
By utilizing ChatGPT in this manner, developers can save time and effort on repetitive tasks, allowing them to focus on
more complex and creative aspects of the project. It can also assist in training new developers and provide a starting point
for new projects. Generating missing code based on the context of the project with examples. Here's an example of ChatGPT
generating missing code based on the context of the project:
Suppose a developer is building a website using Django and wants to create a view to display a list of articles. They have
written the following code:
python
# views.py
from django.shortcuts import render
from .models import Article
def article_list(request):
articles = Article.objects.all()
# missing code here
12 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
ChatGPT can analyze the code and the context of the project and suggest the following missing code to complete the view:
python
# views.py
from django.shortcuts import render
from .models import Article
def article_list(request):
articles = Article.objects.all()
return render(request, 'article_list.html',
{'articles': articles})
By generating the missing code in this manner, the developer can complete the view more efficiently and quickly.
Role of ChatGPT in Document generation for programming
In Document generation for programming, ChatGPT can be used to:
1. Automatically generate documentation for code, including descriptions of functions, classes, and variables.
2. Provide explanations and examples of how to use code, making it easier for other developers to understand.
3. Generate API reference documentation from code.
4. Create technical documents, such as project reports, with ease.
By utilizing ChatGPT in this manner, developers can save time and effort on documenting their code and projects, allowing
them to focus on other important tasks. It can also help to ensure that documentation is up-to-date, accurate, and
comprehensive.
Here's an example of ChatGPT generating documentation for programming:
Suppose a developer has written the following code for a simple calculator:
python return a - b
class Calculator: def multiply(self, a, b):
def add(self, a, b): """
""" Multiply two numbers
Add two numbers """
""" return a * b
return a + b def divide(self, a, b):
"""
def subtract(self, a, b): Divide two numbers
""" """
Subtract two numbers return a / b
"""
ChatGPT can generate the following API reference documentation for the code:
13 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
By generating the API reference documentation in this manner, other developers will have a clear understanding of how to
use the code, making it easier for them to work with the calculator class.
By utilizing ChatGPT in this manner, developers can speed up the process of developing a chatbot, as well as improve its
overall performance and user experience. It can also help to ensure that the chatbot's language and behavior are consistent,
making it easier for users to interact with the chatbot.
Here's an example of ChatGPT in Chatbot development:
Suppose a developer is building a chatbot to assist customers with ordering food. They want the chatbot to handle questions
like "What are the options for a vegetarian meal?" and "Can I get a salad with chicken?"
14 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
python
def average(numbers):
total = sum(numbers)
count = len(numbers)
return total / count
In this example, ChatGPT has taken the natural language description of the desired functionality and generated the
corresponding code. The developer can then use this code as-is or make modifications as needed. Another example is a
non-developer who wants to perform text analysis on a set of documents. They describe the desired functionality to
ChatGPT in natural language as follows:
15 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
"I want to find the most common words in a set of text documents and create a bar chart to visualize the results." ChatGPT
can then generate the following code in response (in Python):
python
import nltk
from nltk.probability import FreqDist
import matplotlib.pyplot as plt
def analyze_text(documents):
words = []
for document in documents:
words+=
nltk.word_tokenize(document)
fdist = FreqDist(words)
fdist.plot(30, cumulative=False)
plt.show()
In this example, ChatGPT has taken the natural language description of the desired functionality and generated the
corresponding code in Python to perform text analysis and visualize the results.
Role of ChatGPT in answering technical queries.
1. ChatGPT can play a role in answering technical queries by:
2. Providing accurate and relevant answers to questions related to programming, software development, and other
technical topics.
3. Offering explanations and examples to help users better understand complex concepts and technologies.
4. Guiding users to relevant resources, such as documentation or tutorials, to help them find the information they
need.
5. Assisting users in diagnosing and resolving technical problems, such as error messages or software bugs.
By using ChatGPT in this way, organizations can reduce the time and effort required to answer technical queries and help
users more quickly find the information they need. This can improve overall satisfaction with support services and help
organizations build a reputation for expertise and reliability.
3. Conclusions
ChatGPT is a cutting-edge language model developed by OpenAI that offers a wide range of capabilities for computer
programming. It can assist in code completion, correction, prediction, error fixing, optimization, document generation,
chatbot development, text-to-code generation, and technical query answering [3][4]. The ability of ChatGPT to provide
explanations, examples, and guidance makes it a valuable resource for technical support, while its ability to perform
programming-related tasks can improve efficiency and accuracy[5]. Overall, ChatGPT is a powerful tool for the
programming community that has the potential to make a significant impact on the field.
16 Som Biswas, Mesopotamian Journal of Computer Science Vol. (2023), 2023, 8-16
Conflicts Of Interest
The authors declare no conflicts of interest.
Acknowledgment
The author acknowledges that this article was partially generated by ChatGPT (powered by OpenAI's language model, GPT-
3.5; http://openai.com). The editing was performed by the author.
References
[1] Phillips, Tanner, et al. "Exploring the use of GPT-3 as a tool for evaluating text-based collaborative discourse." Companion
Proceedings of the 12th (2022): 54.
[2] Lund, Brady, and Wang Ting. "Chatting about ChatGPT: How May AI and GPT Impact Academia and Libraries?." Lund, BD, &
Wang (2023).
[3] Winston, Patrick Henry. Artificial intelligence. Addison-Wesley Longman Publishing Co., Inc., 1984.
[4] Charniak, Eugene, et al. Artificial intelligence programming. Psychology Press, 2014.
[5] Tanimoto, Steven L. The elements of artificial intelligence: an introduction using LISP. Computer Science Press, Inc., 1987.