Within this article, you will learn about 4 practical ways that you can use ChatGPT to improve your development workflow. If you want to learn how to write code quicker, read on 🔥🔥🔥
I am happy to admit that I hate creating regular expressions. Throughout my career I have tried to master the regular expression syntax several times, however, on each occasion, I have failed. The main reason for this failure is simple, I do not use the syntax enough to commit it to memory. Additionally, creating certain validations is just plain hard. How do you validate that an email address from any country is valid? Are you sure you know all the rules?
If you are a web developer like me, you will often need to turn to a regular expression to prevent users from adding junk within a form. When you find yourself in this situation, this is a perfect task to turn to ChatGPT for help!
I have found ChatGPT pretty good at creating specific validations for me, however, ChatGPT is not perfect. You should not just blindly trust its results. This is where I would wrap the regex in a method, then get ChatGPT to create some unit tests for that method, and also get ChatGPT to document when the regex does. I have found that this three-pronged approach is a lot more robust, compared to simply copying something you find online.
The same approach is also useful if you need to create a Ci/Cd build script, a docker file, or even define the interval period of a cron job. Obviously, you still need to test at the end of the day, however, whenever you need to build something with a syntax that you hardly ever use ChatGPT allows you to get a more specific answer than Google and Stackoverflow!
We all know that documenting how your code works is a ballache but an essential part of development. It has been proven countless times that developers spend more time reading code than writing it, so not documenting your code in a worst-case scenario might mean it is unusable for consumption! What a waste!
It takes time and energy to create good documentation, however, during this process, a majority of your time will be focused on creating standard stuff that is shared between most projects. This stuff might include things like license model, build commands, repo details, author name, etc...
Instead of wasting your time on the simpler aspects of your documentation, you can turn to ChatGPT to automate the boring bits. Assuming your code is hosted in a public repo, you can ask ChatGPT to automatically create a
readme.md for you. All you need to do is provide ChatGPT with your repos Url and then ask it to generate a
The output documentation will not be perfect, however, it will likely be good enough to save you 5-10 minutes of time each time you need to create a new
readme.md. Over the course of a few years this time saving will add up!
Generate documentation/stub code for badly documented frameworks, SDKs, etc...
This is a follow-up point on documentation, however, the focus of this documentation is on the typewritten (or not) by others! Sometimes you will need to use a Framework, SDK, or package that has no documentation.
One of the worst time sucks on a project is trying to figure out how something works simply because the documentation is bad. In essence, this problem is the reason why this whole blog was created in the first place. My site has now received over 1 million unique users so the data alone proves that when documentation is bad, people turn to alternative sources for help!
When you need to work with these types of undocumented frameworks, you have three options. Bang your head against a wall until you can figure it out yourself. Your second option is to use ChatGPT to generate some documentation for the framework for you which you can then read., Finally, you can ask ChatGPT to stub up the code you need to create for you. In these instances, you may ask ChatGPT something like:
- On "framework/language" how do I make a "feature"
- Explain how this feature works
- Create documentation for junior developers on this topic
These more specific questions are much faster to ask on ChatGPT compared to searching on Google
Automated content generation:
Bored of turning to Lorum ipson whenever you need to add some dummy text within your apps? To spice things up and actually test with real-world data, you can turn to ChatGPT to automatically generate more life-like products, product descriptions, headlines, articles, and other types of content for you.
I think most people think of automated content generation when they think of ChatGPT, however, you might forget to include its power to the dummy and placeholder text you add in development.
Making things more real-life will only improve your testing process and iron out potential bugs that much quicker. For example, a developer might provide ChatGPT with the following input:
ChatGPT would then generate a product description based on the input, such as:
The Executive Suit - Perfect for the busy professional, this all-purpose suit is available in all sizes and made from washable fabric for easy maintenance. Price: GBP 199.99.
The Classic Grey Suit - A timeless piece for any wardrobe, this grey suit is designed to fit all body types and features washable fabric for ultimate convenience. Price: GBP 179.99.
I am hoping that we can agree, by using more accurate real-to-world dummy content within your staging and development environments will only lead to better testing. over the years I've seen countless bugs make it into production, simply because the test text in development was not long or robust enough to trigger styling issues. Using ChatGPT to generate text will mean you are testing against a more real-life scenario which should only help to spot those pesky bugs!
That covers my 5 practical ways that ChatGPT can help you to write better C# applications. Happy Coding 🤘