Dive deeper into the world of AI innovation and stay ahead of the AI curve! Subscribe to our AI_Distilled newsletter for the latest insights. Don't miss out – sign up today!
ChatGPT's coding style is terrible:
Let's change that.
ChatGPT promised to be our coding savior, but sometimes it feels more like a blast from the past.
Remember those early 2000’s coding books? Yep, it's giving those vibes.
It's like having a sports car with a tractor engine. Great potential, but the performance? Not quite there.
Imagine harnessing the power of ChatGPT but with the finesse of a master coder.
Ready for the upgrade?
Here are 12 Pro prompts that will get you the right results.
As soon as you ask for some coding snippet from ChatGPT, by default, you will get the most basic HelloWorld example.
The more vague your prompt is, the more mediocre your results will be
Instead, specify exactly
Write backend code for Library app that uses Rest to communicate
Cover endpoints for adding, removing, and filtering books by category and date published
Use Java latest version.
Use lambda streams instead of for loops
Use Spring framework
ChatGPT loves to write a lot of code, the way I like to call it “code vomit”
We are no longer rewarded by the amount of code we produce, but by the clarity and principles we follow.
Give chat GPT instructions to
Write clean code
Code needs to be covered with Logging and proper exception handling
Use principles: Kiss & DRY, SOLID
Keep in mind to use design patterns where it is applicable
Using coding instructions I gave you, give me code for each class
Every time ChatGPT writes code you get
This can be good for a beginner but is not something we need for our IDE
Our IDE is already good with importing all the right packages, so let ChatGPT know
When writing code, avoid detailed explanations, just simple bullet points
Don't add import statements, as IDE will do this instead
Your code is not complete if you are not done with tests.
But not just any tests. We want to have unit and integration tests in a
For each class write a unit and integration tests
Use given when then format
For libraries use BDDMockito and AssertJ
Cover happy and unhappy paths
What is the app if we cannot test it without some examples
Instead of creating them manually, ask ChatGPT to create Curl examples we can easily copy to Postman.
For each request, generate curl examples
Now go ahead and use your terminal or copy/paste them to Postman
We don’t want just plain text, instead, we need a quick start guide for developers
Write a quick start guide for developers using markdown.
Imagine this app has been published to github repository
Cover
- Introduction
- how to install app
- how to run it
- how to use it
This app cannot live just in your local environment. Instead, we need a deployment script.
Depending on where you want to deploy your changes, it might be
Or ask ChatGPT to suggest a deployment script
Provide me deployment script for one of most popular cloud providers
Our code for now is living only locally. Let’s ask chatGPT to give us instructions on how to set up Version Control
Provide Github version control setup instructions
CI/CD or continuous integration and continuous deployment is a must-have step for any serious development.
There are plenty of options to choose from, such as
With CI we guarantee we can
With CD we guarantee that we can safely deploy our changes
Provide github actions that for each open pull request we
run the build and run all the tests
Also automatically include sonarqube scans
Also create github action to run deployment on every code merge
Our backend rest service is now running, but the question we need to ask ourselves
For that, we need to execute performance tests, e.g. using jmeter or gatling.
We need to test what is the limit of our app.
Write a load test script for gatling that tests how many book searches we can execute
How can we ensure our app is secure and not open to any threats?
The best way is to run security scans.
Our application might be open for security threats.
Which security scan tools we can use for free and how can we use them.
Give me step-by-step instruction on how to use it.
You have your app running somewhere in the cloud.
But did you optimize it for observability?
We want to make sure our application is optimized for observability
Create guideline and configuration for the cloud environment for
Traceability - tracing request from start to finish
Monitoring - monitoring key performance metrics
Logging - have a centralized logging system
You can find the full prompt here
https://chat.openai.com/share/f0bef1ca-062d-4a22-96aa-9711615329a5
ChatGPT is a tool, and like any tool, it shines when used the right way.
With these prompts, you get a coding assistant that keeps up with the latest trends, ensuring your code is not just functional but also follows modern standards.
Jakov Semenski is an IT Architect working at IBMiX with almost 20 years of experience.
He is also a ChatGPT Speaker at the WeAreDevelopers conference and shares valuable tech stories on LinkedIn.