Working With AI-Powered Developer Experience Tool

How I boost my coding productivity by 400% with ChatGPT and Github Copilot

Ramadhani Baharzah
4 min readApr 7, 2023
https://thenaturehero.com/github-copilot-vs-chatgpt-similarities-and-differences/

In my day to day working as a Software Engineer, I always on the lookout for ways to improve my productivity and write better code. Recently, I stumbled upon the power of using ChatGPT AI and Github Copilot to help me with my coding tasks. In this article, I’ll share my experience and show you how I used these tools to increase my coding productivity by a whopping 400%.

One of the coding tasks that I found particularly challenging was mapping product categories for an e-commerce website. The website had a hierarchical structure of categories, with each category having its own set of subcategories. My goal was to map these categories and display them on the website.

Technical Side

At first, I wrote a simple Ruby on Rails function to map the categories like this one.

class Category < ApplicationRecord
def self.category_map
map = {}
all.each do |category|
map[category.name] = category.broad_category
end
map
end
end

However, I quickly realized that this approach wasn’t scalable and couldn’t handle deeper levels of subcategories. This is where ChatGPT AI and Github Copilot came to the rescue.

I started by explaining my problem to ChatGPT AI. I described how I needed a recursive function that could map product categories with an unlimited number of subcategories. The AI quickly provided me with some sample code to get me started.

chatting with the AI

Using Github Copilot, I worked with the AI to refine the code and make it more specific to my needs. Together, we created a recursive function in Ruby on Rails that could map product categories with an unlimited number of subcategories.

GitHub Copilot generate what I describe

With some adjustments that coming from ChatGPT & Github Copilot, here’s the final collaboration between me and them:

class Category < ApplicationRecord
has_many :subcategories, class_name: 'Category', foreign_key: 'parent_id'
belongs_to :parent, class_name: 'Category', optional: true

def self.map_categories(category)
return [] if category.nil?
subcategories = category.subcategories.map do |sub|
{ id: sub.id, name: sub.name, subcategories: Category.map_categories(sub) }
end
{ id: category.id, name: category.name, subcategories: subcategories }
end
end

Let’s take a closer look at this code. The Category class inherits from ApplicationRecord, which is a base class for models in Ruby on Rails. This class has two associations: has_many :subcategories and belongs_to :parent. The has_many association indicates that a category can have multiple subcategories, while the belongs_to association indicates that a category can have only one parent.

The map_categories function is a class method that takes a category as an argument. It returns an array of categories, including all the subcategories of the given category. The function works recursively by calling itself on each subcategory, until all subcategories have been mapped.

First, we check if the category is nil. If it is, we return an empty array. Next, we get all the subcategories of the given category and map them to a new array of hashes that include the subcategory id, name, and its own subcategories (which are determined by calling the map_categories function on the subcategory).

Finally, we return a hash that includes the given category’s id, name, and the array of subcategories that we just generated.

By using ChatGPT AI and Github Copilot, I was able to quickly create a recursive function that solved my problem and increased my coding productivity. I could focus on the specific requirements of my project and let the AI do the heavy lifting of writing the initial code.

More Things

Absolutely that’s not all. I also found that using ChatGPT AI and Github Copilot helped me to learn and improve my coding skills. By working with the AI and reviewing the code that it generated, I was able to gain a better understanding of Ruby on Rails and programming in general.

Another benefit was the time-saving factor. Writing that recursive function above on my own could have taken several hours, if not days, to complete. However, by leveraging the power of these tools, I was able to complete the task in a fraction of the time, leaving me with more time to work on other important aspects of the project.

Moreover, by using these AI-powered tools, I was able to improve the quality of my code. Github Copilot uses machine learning to suggest code snippets based on context, making it easier to write clean and efficient code. This helped me to write better code faster and avoid common programming mistakes.

Summaries

In conclusion, using ChatGPT AI and Github Copilot has been a game-changer for me as a developer. It has not only helped me to complete coding tasks faster and with better quality but also improved my coding skills and boosted my productivity by 400%. If you’re a developer looking to improve your coding productivity, I highly recommend giving these tools a try. Who knows? You might be surprised by the results, just like I was.

--

--