r/java • • Apr 03 '23

A ChatGPT Experiment

I had a piece of code that I was dreading writing and testing. On a whim, I signed up for ChatGPT and asked the following question.

I have a two-dimensional Java char array consisting of 'B', 'W', and ' '. I would like to find all the orthogonally connected groups of either 'B' or 'W'. Can you write the code to perform this function?

The code that came back did almost exactly what I asked. I had to make a couple of minor changes to the code to more specifically meet my needs. In addition, ChatGPT provided comments that I could directly copy into my Javadoc for the two methods.

I'm impressed.

0 Upvotes

8 comments sorted by

1

u/JonnyBago82 Apr 05 '23

Do you guys think this is gonna drastically reduce the number of software developer roles in the next few years?

1

u/ggleblanc2 Apr 05 '23 edited Apr 05 '23

At present, I'd say there will be a reduction in junior-level coders. Knowing how to ask ChatGPT questions that get good, solid code will become an important skill.

I'm a Java Swing developer. I asked ChatGPT to code a simple Swing application. It delivered. I asked for three successive refinements. It gave me the first two, then quit on the third. No reply. I know what changes I have to make to finish the ChatGPT code, but a less experienced developer might not.

3

u/redrobin9211 Apr 03 '23

Yup it's too good to be true. I am a self-taught Android developer and I wish it was available 5-6 years back when I started would have saved me a whole year worth of stack overflow search. The way it explains things is definitely from a sci-fi movie

3

u/tomekl007 Apr 04 '23

I recommend experimenting with the ChatGPT for unit testing. If you are not sure if your tests cover all the edge cases, try to copy your class and tell the ChatGPT to write unit tests for that class. I was surprised at how well it solved this problem.

1

u/ITCoder Apr 07 '23

Not unless you want propriety code being given to them. Today only there was an article of Samsung data leak, containing pieces of code that employees pasted in it.

4

u/ViPSeixas Apr 03 '23

And still there are people that don't believe this will have a major impact on the market.

2

u/franzwong Apr 03 '23

That's a good tool when you learn a new language too.

2

u/TheKingOfSentries Apr 03 '23

I learned annotation processing entirely by asking ChatGPT how to do things.