So I know anyone who codes is underwhelmed by that post title. Of course it is and we all have known that for some time. But how do I convey that to people who are non-programmers? I found myself a couple weeks ago talking to a person at Cisco and saying that AI tools like ChatGPT are incredible at understanding my intent in code and helping me out, but I felt lacking in making a concrete example that connects to people who don’t live in arrays, lists, and hashes.
Well, today I have an easy low-hanging fruit example to share. I was updating some code on my playoffpredictor.com site where conferences were hard coded in:
$conference = array(
"Air Force" => "G5",
"Akron" => "G5",
"Alabama" => "SEC",
"Appalachian State" => "G5",
"Arizona" => "B12",
I asked Claude.ai to help me pull conference data from a file I have (fbsTeams.json) which has the data in more traditional .json format:
[
{
"team_name": "Boston College",
"conference": "ACC",
"cbs_sports_icon": "BC",
"cfdb_name": "Boston College",
"pp_id": "1"
},
{
"team_name": "Clemson",
"conference": "ACC",
"cbs_sports_icon": "CLEM",
"cfdb_name": "Clemson",
"pp_id": "2"
},
{
"team_name": "Duke",
"conference": "ACC",
"cbs_sports_icon": "DUKE",
"cfdb_name": "Duke",
"pp_id": "3"
},
AI of course wrote the necessary code for me. Here was the prompt I used:
I want to replace the current hard-coded way of defining $conference and instead move it to reading the .json file and populating it from the file. please write the necessary code for me. The file path is /home/neville/cfbPlayoffPredictor/data/2024/fbsTeams.json.
For teams that pull as conference CUSA, Sun Belt, Mountain West, AAC, FBS Independent, I want those all to map to "G5" in the $conference array. I want the logic to be that if the team does not match SEC,B10,B12, or ACC then replace whatever the .json file has with "G5"
And here is the AI code output:
Here is what I mean by intent — no where in the prompt did I say anything about power 5 conferences. But it understands that and wrote the code that way. Stupid tools would just call it ‘filtered_conferences’ or some basic thing like that, but AI is smart enough to understand I want to separate out power 5 conferences and G5 conferences, even though I never used the words power 5.
Of course in 2024 with the destruction of the Pac12 there are now only 4 power conferences, so I edit the code to call it $power4 in my script. But the hard work is done by AI and I just do some fine tuning editing. This is a perfect example of how AI should be helping us in day-to-day mundane coding tasks.