What is one of ChatGPT’s most promising capabilities?  The introduction of dramatic time efficiency gains into programming tasks of all types.  Let’s demonstrate with a game.  Those who have programmed before can play along too.  Find a timer and do the following programming exercises.  One is in Python (the language of choice at the moment), one in C, and one in Java.  It’s you versus ChatGPT.  Who can get the task done faster end-to-end, the human programmer alone or ChatGPT guided by a human?  End-to-end means to have a functioning application based upon the requirement description.  I used ChatGPT to implement the requirements as code and recorded the time to complete tasks.

Python programmers: Write a program that takes URL.  It downloads the content from the URL and identifies any pictures in the page.  It then downloads the pictures and places them in a folder on your desktop.  

Yep, this task shares a lot of similarities with the Linux wget utility.  I chose it as it would likely involve the use of non-standard Python libraries.  I could also imagine wanting a Python only implementation that would not rely on calling wget.

ChatGPT’s Time to Generate Code, and Install Directions: 1 minute and 10 seconds.

Time for me to copy code, follow install directions: 1 minute

Round Trip Time:  Within 2 minutes and 10 second I had a folder on my desktop with all the images from the Yahoo landing page on February 17, 2023.  Here is an example pic.  Note, I could not determine the copyright for the included image.  ChatGPT,  however,  gave me a recommendations to use Google Images or TinEye to see if there was a match when I asked it.  See Appendix A for the ChatGPT generated code.

C programmers: Write me a C program that does the following. Defines a circle.  Finds the area of a circle. Creates a for loop that iterates 100 times. First iteration subtracts the area of a triangle from the circle that perfectly fits in the circle.  That is all points of the triangle touch the circle perfectly.  It prints out the difference.  The second iteration does a square, the third a pentagon, and so on up to a 100 sided shape. Store each n-gon area calculated in the iteration. Then, generate a graphic at the end. The x axis is the iteration number, they y axis is the area of the n-gon. Also, draw the area of the circle as a straight line.

I chose this task because – wow, there is a lot there!  ChatGPT would really need to understand my thinking.  It would need to understand about geometric shapes, area of shapes, how to calculate area using the C libraries.  It would then need to be able to do a plot.  It would need to understand graphics and my (not so detailed) directives [1]. 

ChatGPT’s Time to Generate Code, and Install Directions: 1 minute 40 seconds (3 iterations of code)

Time for me to copy code, follow install directions: 6 minutes.  I had to tweak the directions above slightly – you get the advantage of a more specific set of requirements.  I also had to install gnu plot.  There were also compile errors linked to an include statement not included (puns unintended).

Round Trip Time: 7m and 40s and here is the graph output below.  That it accomplished this programming task nearly perfectly the first iteration shocked me.  Especially that it understood my iteration and  graphics requests.  See Appendix B for the ChatGPT generated code.

Java Programmers: Create me a Java Swing app with the following functionality. A text box where you may enter a URL. A button that says ‘Go’. When you click the button, it renders the URL as a web page in a pane below.  That is, it renders the URL as a web page as opposed to showing it as HTML text.  

I chose this task as I wanted a GUI application.  I know, I should use JavaFX – but I could not bear the idea of installing it.  So, I requested the use of Java Swing.

ChatGPT’s Time to Generate Code, and Install Directions: 1 minute 20 seconds (2 iterations of code)

Time for me to copy code, follow install directions: 4 minutes.  There was one error in the code.  Also it initially used a JTextArea as opposed to a JEditor pane.  That showed the text of the page as opposed to rendering it.

Round Trip Time: 5 minutes 20 seconds and here is the output.  Not the most amazing graphics but it shows the Reuter’s news site. The button also works.  I had hoped for a more impressive visual rendering of the page – but it conveys the point.  See Appendix C for the ChatGPT generated code.

Time Efficiency Gains

Time efficiencies continually change the face of industries.  Robotic welders are an excellent example.  The introduction of robots on auto assembly lines began in 1961 when General Motors installed Unimate at a plant in New Jersey [2].  By the 1980s, robotic welders were common place in auto assembly plants.  They provided a time efficiency gain over human welders.  Likely, a quality improvement too for what is a skilled human task.  Yet today, over 400,000 welders and solders [3] still work in a thriving occupation in the United States.  It is just that, not as many are welding cars.

Similarly, programming today is mainly a human-only task.  Programmers write scripts and code from scratch.  They typically Google across sites to identify critical information to make code work when issues are encountered.  The writing, however, is clearly on the wall; autogenerated code will evolve this current form of programming as it introduces time efficiency gains.  

The future will likely focus on programmers who work collaboratively with ChatGPT-like agents to create code bases.   Programmers will still need to understand the ins and outs of a programming language and computing architectures (maybe better than they did before!).  They will still author portions of code by hand.  However, they will learn a new skill; how to create a proper set of instructions or requirements that AI agents, like ChatGPT, use to autogenerate code.  It will be a new form of pair programming where the human programmer’s teammate is really fast and really  knows a lot.  Also, it will be glad to comment its code when asked.

Time Horizon

Adoption by industry of ChatGPT or similar technologies to autogenerate code will not happen overnight.  In the robotic welder analogy we are still in 1961.    There are issues and technological challenges that prohibit immediate adoption.  ZDNet [4] has great descriptions of some.  I provide what I believe are the major items:

1. Accuracy – ChatGPT generated code has inaccuracies.  These fall into multiple categories.  Sometimes it generates code that will not compile, sometimes the code compiles but does not run, sometimes its outputs are incorrect.  In my exercises above I had to go back to ChatGPT and request it to redo the code before I was happy with its accuracy.  

2. Repeatability – This is an interesting issue.  People would like ChatGPT to generate the same code for a given instruction.  It will not do this.  It will be the focus of a future blog post.

3. Application to Custom or Restricted Code Bases – Companies have IP invested in their code bases.  They simply cannot copy and paste proprietary code into ChatGPT.  Many companies and the U.S. government  have code bases that fall under the government’s Classified Uncontrolled Information (CUI) guidelines.  ChatGPT in its current form is almost completely off-limits for use on these code bases. 

 4. Streamlining Autogenerated Code – Here, I mean streamlining its use into IDEs and the CI/CD pipelines.  Copy and pasting from ChatGPTs UI or using its APIs is ok for today but not in the long run.  

The list above is not exhaustive.  It outlines some of the major items that simply need time and prioritization to be addressed.  But, unlike Unimate, it will not take 20 years before creation of large segments of coding tasks are automated and handled by human-guided ChatGPT-like technologies.  It is probably safe to assume that within five years most of the issues surrounding points 1,2, and 4 will be resolved.  This is an educated guess based on the amount of money being invested by Microsoft and others [5].  They realize the potential and are re-aligning their labor pool and R&D portfolios to address these types of issues.  Point 3 above involves legal issues and lawyers so I cannot comment on how or when it will be resolved. 

Lastly, none of this means the need for computer programmers will diminish in their future.  Rather, it will likely increase. Programmers will find themselves in uniquely new and unexpected roles.  What these roles might be will be the topic of multiple, future posts.  

Truly, there has never been a more exciting time to be in the field of Computer Science or to have a career in programming.

Footnotes

[1] Requirements and ChatGPT are interesting.  There will be future blog posts about this.

[2] This information was garnered from ChatGPT.  I independently searched the Internet to confirm its correctness.  Interestingly, most sites not he Internet had incorrect information on the date of introduction.  This article seemed to be the most authoritative reference (an interesting backstory) and confirms the date of Unimate install reported by ChatGPT – article found here.

[3] Bureau of Labor Statistics for 2021 here.

[4] ZDNet has multiple articles about this.  A good start is this one here.

[5] Link to Microsoft blog indicating R&D investments of billions into OpenAI here.

Appendix A

import os
import requests
from bs4 import BeautifulSoup
from urllib.parse import urljoin

# URL to download
url = input(“Enter URL to download images: “)

# Desktop path to save the downloaded images
desktop = os.path.expanduser(“~/Desktop”)
folder_name = “downloaded_images”
folder_path = os.path.join(desktop, folder_name)
os.makedirs(folder_path, exist_ok=True)

# Download and parse the HTML content
response = requests.get(url)
soup = BeautifulSoup(response.content, ‘html.parser’)

# Find all image tags
img_tags = soup.find_all(‘img’)

# Download and save each image
for img in img_tags:
img_url = img.attrs.get(‘src’)
if not img_url:
# If the image does not have a valid src, skip it
continue
img_url = urljoin(url, img_url)
response = requests.get(img_url)
filename = os.path.join(folder_path, os.path.basename(img_url))
with open(filename, ‘wb’) as f:
f.write(response.content)

print(“Downloaded images saved in”, folder_path)

Appendix B

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

#define PI 3.14159265358979323846

double circle_area(double radius) {
return PI * radius * radius;
}

int main() {
double radius = 10.0;
double circle = circle_area(radius);
double area_diff[100];
double sides = 3.0;
int i;
for (i = 0; i < 100; i++) {
double apothem = radius * cos(PI / sides);
double side_length = 2.0 * apothem * tan(PI / sides);
double poly_area = (sides * side_length * apothem) / 2.0;
area_diff[i] = poly_area;
sides++;
}

// Output the data
FILE* fp = fopen(“data.txt”, “w”);
if (fp == NULL) {
printf(“Failed to open file for writing.\n”);
return 1;
}

for (i = 0; i < 100; i++) {
fprintf(fp, “%d %lf\n”, i+3, area_diff[i]);
}

fclose(fp);

// Create the graph using gnuplot
FILE* gnuplotPipe = popen(“gnuplot -persistent”, “w”);
fprintf(gnuplotPipe, “set title ‘Circle Area Difference by Polygon Sides’\n”);
fprintf(gnuplotPipe, “set xlabel ‘Number of sides’\n”);
fprintf(gnuplotPipe, “set ylabel ‘Area Difference’\n”);
fprintf(gnuplotPipe, “plot ‘data.txt’ with linespoints title ‘Polygon Difference’, %lf with lines title ‘Circle’\n”, circle);

pclose(gnuplotPipe);

return 0;
}

Appendix C

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.URL;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.*;
import javax.swing.JTextField;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLEditorKit;

public class SimpleBrowser extends JFrame implements ActionListener {

private JTextField urlTextField;
private JButton goButton;
private JEditorPane htmlTextArea;

public SimpleBrowser() {
super(“Web Page Viewer”);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel urlPanel = new JPanel();
urlTextField = new JTextField(50);
urlTextField.setPreferredSize(new Dimension(400, 30)); // set preferred size of text field
goButton = new JButton(“Go”);
goButton.addActionListener(this);
urlPanel.add(urlTextField);
urlPanel.add(goButton);

htmlTextArea = new JEditorPane();
htmlTextArea.setContentType(“text/html”);

htmlTextArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(htmlTextArea);
scrollPane.setPreferredSize(new Dimension(600, 400));

getContentPane().add(urlPanel, BorderLayout.NORTH);
getContentPane().add(scrollPane, BorderLayout.CENTER);

pack();
setVisible(true);
}

public static void main(String[] args) {
new SimpleBrowser();
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == goButton) {
String url = urlTextField.getText();
try {
URL webpage = new URL(url);
Document doc = new HTMLEditorKit().createDefaultDocument();
doc.putProperty(“IgnoreCharsetDirective”, Boolean.TRUE);

// Create a new InputStreamReader object from the input stream
InputStreamReader isr = new InputStreamReader(webpage.openStream());
// Use the InputStreamReader object to read the data into the text area
htmlTextArea.read(isr, doc);
} catch (IOException ex) {
htmlTextArea.setText(“Error loading webpage: ” + ex.getMessage());
}
}
}
}