How I Use AI Daily To Write Code (3 Ways) 🤖
Sep 09, 2023 3:01 pm
"Learn how to use AI or you will be left behind"
Man, aren't you tired of hearing that? 😂
Every social media account wouldn't shut up about AI 3 months ago and tried to convince us robots would feed us our lunch through a tube by December.
Luckily I've always had a keen smell for bulls**t 💩
So let's get real...
Here's how AI affected my life so far:
Since everybody freaked out about ChatGPT I've been using it daily
I'm around 60% search engines and 40% AI
("search engines" includes Google and internal company documentation)
Generative AI is the best tool I've adopted in a long time.
Nothing comes close.
I didn't shove it down your throats on social media for 2 reasons:
- Any real advice got drowned in the hype 3 months ago
- I was still learning how to use it myself
With that said...
Here are the 3 real ways I use ChatGPT l at my day job.
Maybe you can use some of these too:
1. Small Refactors
Here's a simple React application (link)
I call it "Build a Word"
Here's what it does.
- There is a word
- You can type text in a box
- When you click a button it adds what you typed to the word
But let's say we want to change the "word" to a list.
Wouldn't be too hard on our own, but I know from experience that generative AI can handle this without a hitch.
Let's ask:
The result from ChatGPT:
Couldn't have done it better myself.
Obviously, this example is artificial. A seasoned programmer could have made that change in less time.
However, I had this work for some impressive refactors that are too long for a Saturday morning newsletter.
Some examples that ChatGPT (shockingly) nailed for me in the past:
Here are two "for" loops that iterate over the same object twice. They can likely be combined. Refactor this code so that the overlapping logic between the two loops happens in a single loop.
This code has a lot of vague variable names. Given the context of the code around it, rename all the variables to be self-documenting and indicative of what their purpose is.
This code file represents an API client. Notice the "logger" declared at the top. Find all areas in this class where a response is returned from the API and use a "logger.debug()" call to print out the full response in a human-readable format.
None of these are ground-breaking or hard to do on your own, but man did it save me some time.
Always double-check the code it generates. Sometimes it is wrong, but why not save yourself the brain power if you can?
2. Deciphering Unreadable Logs
The corporate world is not perfect.
I've seen code bases that print out an API response in Java:
Not ideal... I know.
But we don't judge! I've written undesirable code too. Sometimes it just comes down to the wire.
But when responses get big (and you print like that) things can start to look ugly:
{name: Car1, make: Toyota, model: Camry, year: 2023, price: 25000.0, color: Blue, mileage: 15000, engineSize: 2.5, fuelType: Gasoline, transmission: Automatic, numDoors: 4, numSeats: 5, hasNavigation: true, hasSunroof: false, isFourWheelDrive: false}, {name: Car2, make: Honda, model: Accord, year: 2022, price: 23000.0, color: Red, mileage: 12000, engineSize: 2.0, fuelType: Gasoline, transmission: Automatic, numDoors: 4, numSeats: 5, hasNavigation: true, hasSunroof: true, isFourWheelDrive: false}, {name: Car3, make: Ford, model: Mustang, year: 2023, price: 35000.0, color: Yellow, mileage: 8000, engineSize: 3.5, fuelType: Gasoline, transmission: Manual, numDoors: 2, numSeats: 4, hasNavigation: false, hasSunroof: false, isFourWheelDrive: false}, // ... more cars
Stuff like this is hard to read through all day.
In cases like this (given the data isn't sensitive) I turn to generative AI:
... giant big ugly response ....
Pretty nice, huh?
A massive time saver for me. No more going cross-eyed while digging through massive printouts all day.
3. Guide Me Through The Unknown
A little less "straightforward" but one of my favorite use cases.
AI can be a fantastic mentor.
All you have to do is learn to ask the right questions.
Let's just jump right into an example:
This is a query I ran months ago when I was digging into building data regulation compliance on a service at Amazon.
(Basically, if a customer says "Delete my data" we need to make sure we do)
This wasn't the full route I ended up taking, but it's pretty damn close.
This response got me started looking in the right direction, asking the right questions, and researching the right things.
All from a single, vague, and ambiguous question.
AI will never do all the thinking for you, but man it's pretty good.
I would have killed for something like this early in my career.
A good teacher is available 24/7 – with instant responses.
Amazing.
(Bonus) Alternative to ChatGPT
After poking around with various AI's
Here is my favorite alternative that I use more than ChatGPT nowadays:
Not paid to promote. I just like it.
_________________________
Thank you for reading this week's newsletter.
I appreciate all of you who read to the end.
Book a coaching call with me if you want to chat or have any questions.
Email me at swdlodonnell@gmail.com with any questions
Check out my free course if you are learning to code
Until next week 👋