Trying ChatGPT as a professional software developer

We are a company of software developers that does not sell a product but provides a wide range of services. Our primary service is developing individual software or maintaining existing software for our customers.

Most of us are polyglot developers each sufficiently fluent in a couple of languages. While I see this as a strength it also means that I do not know the idiomatic solution for a task in all ecosystems in use in our projects by heart.

A few days ago I had a remote-pair-programming session with one of our customers and we wondered how to idiomatically trim certain characters from a string in JavaScript. My customer came up with the idea of asking ChatGPT for a solution while I would have asked Google or stackoverflow.

Being curious we took the ChatGPT route and it delivered a correct solution after I clarified what I mean with “trim”:

function trimCharacterFromStartAndEnd(str, char) {
  // Create a regular expression to match the specified character at the beginning and end of the string
  const regex = new RegExp(`^${char}+|${char}+$`, 'g');
  
  // Use the replace() function to remove the character from the start and end of the string
  const trimmedStr = str.replace(regex, '');
  
  return trimmedStr;
}

// Example usage
const originalString = '###Hello World!###';
const trimmedString = trimCharacterFromStartAndEnd(originalString, '#');
console.log(trimmedString); // Output: Hello World!

But from a professional perspective the code was not simple, concise and idiomatic. I intuitively knew there must be a better way.

So I did what ChatGPT does best: I chatted with it to improve the solution to arrive at a solution a was satisfied with:

function trimCharacterFromStartAndEnd(str, char) {
  return str.replace(/^${char}+|${char}+$/g, '');
}

// Example usage
const originalString = '###Hello World!###';
const trimmedString = trimCharacterFromStartAndEnd(originalString, '#');
console.log(trimmedString); // Output: Hello World!

However, you possibly need to handle regex special characters like '.', '*' etc. if they can part of your characters to trim.

Some of the intermediate steps also have their uses depending on the needed flexibility. See the full conversation at trim character from string chat.

Similarily, stackoverflow provides some comprehensive answers you can adapt to your specific situation.

Evaluation

Using ChatGPT can actually provide you useful results. To make the most out of it, you have to be able to judge the solution provided by the AI and try to push it in the wanted direction.

After my experiment our students got the inofficial advice that their solutions should not be worse than what ChatGPT delivers. 😀

Arriving at a good solution was not faster or easier than the traditional developers’ approach using Google and/or stackoverflow. Nevertheless it was more interactive, more fun and most importantly it worked.

It was a bit disappointing to lose context at some points in the conversation, with the g-flag for example. Also the “shortest” solution is longer than the variant with the regex-literal, so strictly speaking ChatGPT’s answer is wrong…

I will not radically change my style of work and jump on the AI-hype-train but I plan to continue experimenting with it every now and then.

ChatGPT and friends certainly have some potential depending on the use case but still require a competent human to judge and check the results.

4 thoughts on “Trying ChatGPT as a professional software developer”

    1. Thanks for this interesting article, and for posting the link to the actual chat. You really had a very interactive conversation to reach your goal.

      I think you can reach it faster if you improve your input with the help of some prompt patterns, such as “don’t assume but specify”, see https://chat.openai.com/share/06cfa670-8f66-4290-9ea8-f9f1fe915cfa. Unless you specify e.g. “on the level of a senior software developer”, ChatGPT will give you the most common code style it has seen on e.g. GitHub, which is far worse than senior software developer level.

      In case you are interested in such prompt patterns, you can take a look at my slides about generating unit tests, https://fg-tav.gi.de/fileadmin/FG/TAV/48.TAV/TAV48_Farago_PromptEngineeringForQA.pdf, or take a listen to the related podcast episode, https://www.richard-seidl.com/podcast-qualitaet-von-und-mit-prompt-engineering/. But even with a toolbox of prompt patterns, your conclusion remains valid: AI is not sufficiently reliable to fully jump on the ChatGPT-hype-train and radically change your style of writing code (unless you call heavy use of Github Copilot radical change).

      In case you have access to ChatGPT+, I highly recommend activating the Code Interpreter, which is also called GPT-4.5 because of its advanced capabilities, see e.g. https://chat.openai.com/share/799602a5-1b15-4fe7-b86d-199967172a0f

    2. Thanks for the link to this interesting talk and the part on the topic. As for now, we can conclude that there is not much change in our profession due to “AI”.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.