I Challenged AI to a Code-Off! Here’s Who Won.

Everyone's talking about AI writing code these days. But can it really handle anything beyond "Hello, world?" I wanted to see for myself, so I set out to build something more complex – not a full-fledged enterprise app, but something that went beyond the basics and even incorporated security features. That's how I landed on creating a Rahukalam calculator.

For those unfamiliar, Rahukalam is an astrological concept that involves calculating inauspicious periods of the day based on location and sunrise/sunset times. It requires some intricate date and time manipulation, making it a good test case for AI's coding abilities.

I challenged both Gemini and ChatGPT with a simple prompt: "Create code that I can execute from my browser alone to compute Rahukalam once I enter the date and city." And guess what? They actually delivered... mostly.

Here's the play-by-play of my AI-assisted coding adventure:

  • APIs? No problem! Both AI models effortlessly found free APIs for getting latitude/longitude and calculating sunrise/sunset times. Talk about saving hours of research!
  • Logic (almost) nailed it: They even generated the core Rahukalam calculation logic, though it wasn't bug-free (more on that later!).
  • Where humans still reign: I still needed to do some manual work, including: Setting up accounts with API providers and obtaining those all-important API keys. Integrating those keys into the code. Debugging a fair amount of JavaScript (timezones and date arithmetic, oh my!). Implementing a typeahead feature for city names using a public dataset, which involved some back-and-forth with the AI for optimization.

LLM’s role:

Despite the manual effort, I'd say the AI tools handled about 70% of the work. This was particularly impressive considering my "intermediate" JavaScript skills (I'm a decent programmer overall, but JavaScript isn't my forte).

What could be improved:

  • AI Agents to the rescue: Imagine if an AI agent could automatically create accounts with API providers, obtain keys, and plug them into the code. This would be cool! Some providers might offer management APIs for this, but I didn't see any readily available.
  • Testing, testing, 1, 2, 3: I tried to get the AI to write automated tests based on a CSV file of inputs and expected outputs. It suggested using Playwright, but I haven't gone down that rabbit hole yet.

The Verdict:

Despite the hiccups, I was impressed by how much the AI assisted in building this Rahukalam calculator. You can even try it out yourself at https://banurama.github.io/calculate_rahukalam/.

This experiment reinforced my belief that generative AI has the potential to revolutionize coding. While it's not a magic bullet (yet!), it can significantly accelerate development, even for those of us who aren't JavaScript wizards. I'm excited to see how these tools evolve and what new possibilities they unlock in the future!