ChatGTP to Help Me Write C# Code: Utility to Sort Files on Disk
Tags: chatgpt, csharp
Published: 2023-12-20 21:49:05


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/twt74d4plqj8uxagxyeq.jpg)_Images Created using **Bing Image Creator**_

## Quick Summary
· ChatGTP is very good, but only as good as instructions given
· Benefits of using AI are time saving as well as reduced cognitive load
· Best use case is generating lower level focused methods instead of a complete system
· Developer must be very familiar with coding best practices
· Best to have a high level design and specifications/expectations to test against
· Design should include method signatures and classes
· Must also consider unit tests as part of the design or specification
· Again, Developer must know his/her stuff, do not JUST copy and Paste ChatGPT
· Used ChatGTP 3.5, Full Visual Studio and C# (left our versions of VS and C#)

Using ChatGTP to create software should be in the arsenal of a modern developer’s tools. Provided the AI is given very specific instruction on creating small very focused methods, a developer gets the benefit of saving a lot of time. A very obvious benefit.

A non-obvious benefit is the brain gets freed up to focus on the higher level system design and ensuring code meets technical specifications. Cognitive load is the word. It means instead of many potential rabbit holes of accidental buggy lower level coding syntax, more time can be devoted to writing tests. AI is very accurate once the instructions are clear.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb0kb49jbsjzlrkqohjd.jpg)_Images Created using **Bing Image Creator**_

## The System I wanted ChatGTP to help me create
A utility to sort a large number of files and folders on a hard drive. I have data that is over 600 GB, mostly videos and documents. Initially arranged in some semi-structured folder system so they can be found easily. I wanted all the files to be grouped by main topic, then if it is a single video or group of videos that belong to a single event. Also I wanted the videos to be placed in buckets of years. For example, 2010–2019 then 2020–2025,2026–2030 etc.

Manually this can be done by hand and surprise, surprise it takes a long time…about 2 days. So, if I want to change the folder structure every now and then, say every 2–3 months, I have to brace myself for days of repetitive folder labour.

So in essence the utility is file system heavy and reading a lot of files, renaming folders, moving big files around.

On a high level the task seems trivial…and it is kind of easy code. Until I started to run into special cases. Missing folder or not structed as expected, Or the folder had a different name. Or some path or phrase used to match to find a folder would clash with another special folder.

Like in most software development “quick tasks” this very quickly turned into some PROJECT.

## How did ChatGTP Perform
It did very well. Pretty much all of the low-level code was written by the AI. I wrote close to ZERO of the heavy duty. In total I spend 18 hours spread over 3 days. Initially I thought I would have been done in 1 day. The development process was as follows.

· I limited ChatGP to only creating very focused methods
· I would think of a method that I needed. The enter the prompt into ChatGTP
· Generated code placed into some “scratch pad” inspected and ONLY copy the relevant methods
· Run an end to end test (Test Runner in Visual Studio) and manually check method is as expected.

ChatGPT did a good job in helping me to be relatively LAZY and not have to THINK that hard on the LOW-LEVEL file system C# code. I still had to inspect almost every line of code it generated. A mini code review for every cycle of asking for new methods to be generated.

## ChatGTP as a CoDeveloper
Overall the AI played the role of a team member who is focused on code while I would focus on higher level tasks such as design, code review and some refactoring.

I did spend 18 hours in total. Too long for the relatively low complexity of this task. Most of the time lost was not ChatGTP but the special cases I would run into.