Smarter Coding: 7 AI-Powered Tips for Productivity

Smarter Coding: 7 AI-Powered Tips for Productivity
Photo by Arian Darvishi on Unsplash

From generating boilerplate code to writing documentation to generating database queries, the possibilities are endless with AI.

If you are a programmer, instead of being afraid that AI will replace you, use AI tools to 10x your productivity so that you can build more in less time.

In this blog post, using real-life examples, I will show you how you can take advantage of Large Language Models (LLMs) to greatly increase your efficiency and productivity as a programmer.

Not only will this make you a much better programmer delivering features and products faster, but it will also increase the value you provide to companies and organizations.

Instead of AI replacing you, you will become irreplaceable by companies.

Can LLMs Replace Software Engineers?

Software engineers and programmers do much more than just write code.

Large Language Models (LLMs) are getting better and better every day. They have become insanely good at knowledge work — the kind of work people thought would take ages for AI agents to master.

However, turning complex product and business requirements into functional code with an intricate system design that scales to billions of users is still difficult to execute for an AI.

Building a scalable piece of software involves lots of human interactions. There are a lot of steps between idea generation and turning it into 0s and 1s. An AI agent alone cannot do that.

This is only for new software. I am not even talking about complex systems that have been built over decades by companies that have billions of users. These systems tend to be so complex that engineers need to spend weeks understanding the system before they can even start writing code.

You cannot just deploy “some AI” to work on these systems.

The point I am making is that it can be scary looking at ChatGPT and Google Bard generating code within seconds that can take people hours to write. However, software engineering is much more than just writing code.

In my opinion, we are still decades away from a world where your average software engineer needs to fear for their job being taken over by AI.

What Tools to Use?

Honestly, it doesn’t matter.

There are tons of AI tools out there for programmers. From LLM chatbots to browser extensions to VSCode extensions, the possibilities are endless.

In this blog post, however, I will mostly look at a select few that I have personally used and loved:

  1. OpenAI’s ChatGPT
  2. Google Bard
  3. Github Copilot

Pick whatever tool fits your workflow the best. Tools are just means to an end.

Now, without further ado, let’s dive into 7 AI-powered tips that you can use to become a smarter coder and increase your programming productivity.

(1) More Interactive Documentation

One of the best ways to utilize ChatGPT or Google Bard is to interactively explore any framework or programming language’s documentation.

Usually, technical documentation tends to be very dense. Sometimes, it can take you hours to narrow down functions and methods that can actually help you.

Manually sifting through documentation and going down the rabbit hole can be very time-consuming.

Instead, you can ask ChatGPT or Google Bard to do the heavy lifting for you.

My most common tech stack when building apps includes — ReactJS, ChakraUI, and FastAPI.

Which of these technologies requires the most documentation work? ChakraUI!

There are just so many things to remember when it comes to UI frameworks. Hundreds of components to learn about, and thousands of customizations to play with. It can be very intimidating.

Now, instead of looking at the documentation, I just ask Google Bard what I want, and it can generate the code for me.

Let me show you a few examples:

Author’s Google Bard console screenshot
Author’s Google Bard console screenshot
Author’s Google Bard console screenshot

As you can see, Google Bard generates most of the boilerplate code for you. You can use this as a base, and then make the slight tweaks required to bring to life the button of your life.

Rather than generating code, if you want Google Bard to help you explore the documentation, that’s possible too.

Author’s Google Bard console screenshot
Author’s Google Bard console screenshot

These are just a few examples of how I use Google Bard to create beautiful UIs in no time!

(2) Boilerplate Code Generation

Similar to the ReactJS code above, you can use ChatGPT and Google Bard to give you a code skeleton that you can build off of.

Most programming languages and frameworks have a ton of boilerplate code that needs to be written before you actually get into your application logic.

These are repetitive lines of code that are better off generated instead of spending your brainpower.

Let’s look at an example.

As I mentioned before, my backend framework of choice is Python FastAPI. Whenever I start a new project and I have a clear idea of what endpoints I would like, I just start off by telling Google Bard to generate the boilerplate code for me. This includes all the “set-up” code and placeholder logic for all my API endpoints.

Author’s Google Bard console screenshot

You can see that not only does Google Bard generate the boilerplate code, it even makes up some mock data that I can use for testing my endpoint.

It doesn’t have to end here though.

You can get more specific with your requests. Here’s a very common thing I do all the time.

Author’s Google Bard console screenshot
Author’s Google Bard console screenshot

Without writing a single line of code, I have the boilerplate code for a working FastAPI server with CORS enabled for testing purposes.

Next step? I directly start focusing on my application logic.

(3) Automate Documentation and Comments

What is one thing that most developers hate?

That would be writing comments and documentation.

As programmers, most of us love building things. We get so obsessed with coming up with brilliant software that we forget to future-proof things by adding documentation and comments.

Sure, we are saving some time and energy now. But, this comes at the expense of grueling pain and long ramp-up time for future engineers working on our projects.

Now, you can use ChatGPT and Google Bard to write both comments and documentation for you. Let’s look at an example.

Here’s a Python backend server I wrote that queries ChatGPT for answers to user prompts. I did not add too many comments intentionally.

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from llama_index import GPTSimpleVectorIndex

app = FastAPI()

# Define allowed origins
origins = [
# Add CORS middleware

async def get_answer(question: str):
    index = GPTSimpleVectorIndex.load_from_disk("generated_index.json")
    answer = index.query(question)

    return {"answer": answer.response}

Now, watch Google Bard do its magic.

Author’s Google Bard console screenshot

Not only can you tell AI to write inline comments. You can also tell it to summarize the logic so that you can maybe turn it into a Markdown file or PDF to check into Github.

Author’s Google Bard console screenshot

Another cool thing you can do is tell Google Bard to draw you a tree data structure with function calls. This really helps visualize complex function chains.

Author’s Google Bard console screenshot

(4) Intelligent Autocomplete with Github Copilot

Unless you are living under a rock, you must have heard about Github Copilot — your AI pair programmer.

Instead of doing a poor job demoing this to you, I will just let you check out their website to see how it works.

TLDR: this is code autocomplete on steroids!

Github Copilot can not only suggest code but also generate entire functions and files in real-time based on what you tell it to do.

It also does a brilliant job recognizing patterns in your code, and then generating the remaining for you.

One of the best use cases that I have found is using Github Copilot when writing in a language you are not too familiar with. It’s a great way to move fast while you learn the language.

There’s a free 30-day trial that you can use. If you are a programmer, please at least try it out once!

(5) Refactor Code

We have all been there — writing lines and lines of code just to make something work, not giving any thought to coding principles like DRY and SOLID that we learned from books and courses.

Once we get it working, we look back at our code, only to lose ourselves in whatever we wrote. We don’t understand our own code.

That’s where LLMs like ChatGPT and Google Bard come in. They can do a great job of refactoring for you.

Here’s some Python code I wrote to interact with a Cassandra database.

from cassandra.cluster import Cluster

cluster = Cluster([''], port=9042)
session = cluster.connect('employee')

#! Reading Data From Cassandra [simple query]
print("Reading data simply..")
rows = session.execute('SELECT * FROM employee_details;')
for employee_row in rows:
    print(f'Meet {}! He lives in {}.')

#! Reading Data From Cassandra [optimized query]
prepared_statement = session.prepare('SELECT * FROM employee_details WHERE id=?')
employees_to_lookup = [1, 2]

print("Reading data using prepared statements..")
for employee_id in employees_to_lookup:
    employee = session.execute(prepared_statement, [employee_id]).one()

#! Writing data into cassandra
session.execute("INSERT INTO employee_details (id, age, city, name) VALUES (99,20,'Chicago','Max');")
session.execute_async("INSERT INTO employee_details (id, age, city, name) VALUES (400,25,'Seattle','Bob');")

As you can see, there are no functions to separate the following logic:

  1. Connecting to Cassandra
  2. Reading from Cassandra
  3. Writing to Cassandra

Now, watch Google Bard do some magic to clean things up.

Author’s Google Bard console screenshot

Now, sure there might be a few errors here and there. But, in my experience, it has been easy to catch these errors and make slight tweaks.

(6) Generate Database Queries

One of the best use cases of AI to boost your programming productivity has to be generating database queries. It does such a great job!

I am used to working with various DBs at once — PostgreSQL, MySQL, Amazon Redshift, Apache Cassandra, Redis, etc.

It’s next to impossible to remember different DB functions and database query designs as I am bouncing from one to another.

Enter Google Bard (or ChatGPT). You can give it your database schema and it can do the following (and more):

  1. Generate mock data
  2. Generate queries based on text input
  3. Execute a query on mock data to show you the output

As usual, let’s run through a real-life example.

At first, I am telling Google Bard about my database schema and it’s generating some mock data to play with.

Author’s Google Bard console screenshot

Then, I can actually tell it to generate queries for me and execute them too.

Author’s Google Bard console screenshot

Sure, sometimes if Google Bard struggles to understand the data types it can start hallucinating. However, if you are very particular about data types, it can do a great job.

When it comes to date and time formats especially, Google Bard can struggle. I would recommend copying/pasting some data from your actual DB to make it clear to Google Bard how your database is designed. You will get the most accurate answers that way.

(7) Debug with Error tracebacks

Lastly, ChatGPT or Google Bard can be your best debugging buddy.

When debugging though, I highly recommend telling the LLM model to cite its sources. Otherwise, it starts hallucinating very quickly.

The best starting point I found is to just copy/paste your error traceback, as well as tell the model about what you are trying to do.

Most likely its first answer won’t help you too much, but that’s a great opportunity to ask follow-up questions and drill down further and further until you reach the root cause.

Closing Thoughts

There you go, folks!

I hope this was helpful.

I will end with the most common disclaimer: both ChatGPT and Google Bard can easily spit out wrong answers.

A lot of the time you will need to manually tweak things afterward, but that’s one of the reasons AI cannot replace software engineers yet.

Use AI as a tool to boost your programming productivity, instead of believing and using everything it generates verbatim.

Want more insights like this?

Join my (FREE) email list of 500+ people for more stories on technology, productivity, self-improvement, and personal growth.

You will get early access to all my Medium work and exclusive access to tons of things I don’t post on Medium!

If you enjoy my writing on this platform, join Medium so you can get unlimited access to valuable and beautiful writings from great writers.