Skip to content

5 Ways to Boost Your Coding Productivity with Generative AI

5 Ways to Boost Your Coding Productivity with Generative AI

As a Software Craftsman with years of experience in the field, I’ve witnessed the impact of Generative AI on software development since the introduction of ChatGPT in 2023. Through practical application, I’ve identified five powerful ways to leverage this technology to enhance productivity.

The most frequent way I utilize Generative AI is to search for technical information. Traditional search engines require precise terminology, while Generative AI understands concepts and context. For instance, when searching for the principle of method parameter optimization, I ask:

Prompt

What's the name of the programming concept where you should only pass parameters that are actually used by the method? Passing parameters to a method that aren't used by the method creates unneeded dependencies. 

Generative AI understands the concept I’m describing (Law of Demeter) and provides the correct answer, eliminating the need for multiple searches.

2. Efficient Code Generation

Generative AI excels at automating repetitive coding tasks. Recently, I needed to convert a large JSON file into database insert statements. Instead of writing tedious conversion code, I provided the JSON data to the AI with clear instructions for generating MS SQL Server insert statements. This approach saved hours of manual coding time and reduced the possibility of errors.

Prompt:

Use the JSON data provided below and generate insert statements for MS SQL Server to be inserted into the dbo.Users table.

[  
{  
"Username": "musiclover87",  
"Lastname": "Smith",  
"Firstname": "Alice",  
"Birthdate": "1987-06-12",  
"Password": "password123",  
"FavoriteIceCream": "Chocolate Chip Cookie Dough",  
"FavoriteSuperhero": "Spider-Man"  
},  
{  
"Username": "bookworm92",  
"Lastname": "Johnson",  
"Firstname": "Bob",  
"Birthdate": "1992-03-21",  
"Password": "securePassword",  
"FavoriteIceCream": "Mint Chocolate Chip",  
"FavoriteSuperhero": "Batman"  
},  
{  
"Username": "gamergirl01",  
"Lastname": "Williams",  
"Firstname": "Carol",  
"Birthdate": "2001-11-05",  
"Password": "gamer4life",  
"FavoriteIceCream": "Strawberry",  
"FavoriteSuperhero": "Wonder Woman"  
},  
{  
"Username": "techieguy95",  
"Lastname": "Brown",  
"Firstname": "David",  
"Birthdate": "1995-08-18",  
"Password": "techmaster",  
"FavoriteIceCream": "Vanilla Bean",  
"FavoriteSuperhero": "Iron Man"  
},  
{  
"Username": "foodiequeen89",  
"Lastname": "Davis",  
"Firstname": "Emily",  
"Birthdate": "1989-04-29",  
"Password": "delicious123",  
"FavoriteIceCream": "Salted Caramel",  
"FavoriteSuperhero": "Captain Marvel"  
},  
{  
"Username": "traveler76",  
"Lastname": "Miller",  
"Firstname": "Frank",  
"Birthdate": "1976-12-02",  
"Password": "adventuretime",  
"FavoriteIceCream": "Coffee",  
"FavoriteSuperhero": "Thor"  
},  
{  
"Username": "fitnessfanatic98",  
"Lastname": "Wilson",  
"Firstname": "Grace",  
"Birthdate": "1998-09-15",  
"Password": "strongandfit",  
"FavoriteIceCream": "Mango Sorbet",  
"FavoriteSuperhero": "Black Widow"  
},  
{  
"Username": "photographylover85",  
"Lastname": "Moore",  
"Firstname": "Henry",  
"Birthdate": "1985-05-23",  
"Password": "pictureperfect",  
"FavoriteIceCream": "Pistachio",  
"FavoriteSuperhero": "Superman"  
},  
{  
"Username": "musicjunkie93",  
"Lastname": "Taylor",  
"Firstname": "Isabella",  
"Birthdate": "1993-02-08",  
"Password": "musicislife",  
"FavoriteIceCream": "Rocky Road",  
"FavoriteSuperhero": "Black Panther"  
},  
{  
"Username": "sportsfanatic88",  
"Lastname": "Anderson",  
"Firstname": "Jack",  
"Birthdate": "1988-10-30",  
"Password": "goteamgo",  
"FavoriteIceCream": "Cookies and Cream",  
"FavoriteSuperhero": "Captain America"  
}  
]

Output:


-- Inserting records into dbo.Users table

INSERT INTO dbo.Users (Username, Lastname, Firstname, Birthdate, Password, FavoriteIceCream, FavoriteSuperhero)
VALUES 
('musiclover87', 'Smith', 'Alice', '1987-06-12', 'password123', 'Chocolate Chip Cookie Dough', 'Spider-Man'),
('bookworm92', 'Johnson', 'Bob', '1992-03-21', 'securePassword', 'Mint Chocolate Chip', 'Batman'),
('gamergirl01', 'Williams', 'Carol', '2001-11-05', 'gamer4life', 'Strawberry', 'Wonder Woman'),
('techieguy95', 'Brown', 'David', '1995-08-18', 'techmaster', 'Vanilla Bean', 'Iron Man'),
('foodiequeen89', 'Davis', 'Emily', '1989-04-29', 'delicious123', 'Salted Caramel', 'Captain Marvel'),
('traveler76', 'Miller', 'Frank', '1976-12-02', 'adventuretime', 'Coffee', 'Thor'),
('fitnessfanatic98', 'Wilson', 'Grace', '1998-09-15', 'strongandfit', 'Mango Sorbet', 'Black Widow'),
('photographylover85', 'Moore', 'Henry', '1985-05-23', 'pictureperfect', 'Pistachio', 'Superman'),
('musicjunkie93', 'Taylor', 'Isabella', '1993-02-08', 'musicislife', 'Rocky Road', 'Black Panther'),
('sportsfanatic88', 'Anderson', 'Jack', '1988-10-30', 'goteamgo', 'Cookies and Cream', 'Captain America');

3. Seamless Code Translation

Code translation is another area where Generative AI proves invaluable. During a recent project to convert a C# application to Python, we utilized AI in two crucial ways:

  1. Direct function conversion from Python to C#

  2. Complex ORM translation from Entity Framework to SQLAlchemy

This capability significantly accelerated our migration process and ensured consistency across translations.

Converting Python to C#:

Prompt:

Convert the following Python code to C#.
def reverse_string(text): 
"""
Reverses a given string. 
	Args: text: The string to be reversed. 

Returns: The reversed string.

""" 
return text[::-1]

Output:

/// <summary>
/// Reverses a given string.
/// </summary>
/// <param name="text">The string to be reversed.</param>
/// <returns>The reversed string.</returns>
public static string ReverseString(string text)
{
	return new string(text.Reverse().ToArray());
}

4. Automated Code Documentation

Documentation is essential but often tedious. Generative AI streamlines this process in two ways:

  1. Code summarization: Analyzing existing code and providing clear, concise summaries

  2. Documentation header generation: Creating comprehensive method documentation that maintains code quality standards

For example, when documenting sorting algorithms or complex business logic, AI can generate clear, accurate documentation that follows team standards and best practices.

Prompt:

Generate a doc header for the below function adding the header and printing the complete function with the doc header.
def bubble_sort(list_):
  n = len(list_) 
  for i in range(n):
    # Flag to optimize, if no swaps occur, the list is sorted
    swapped = False
    # Last i elements are already in place
    for j in range(0, n-i-1):
      # Swap if the element found is greater than the next element
      if list_[j] > list_[j+1]:
        list_[j], list_[j+1] = list_[j+1], list_[j]
        swapped = True
    # If no two elements were swapped in inner loop, the list is sorted
    if not swapped:
      break
  return list_

Output:

def bubble_sort(list_):
    """
    Sorts a given list using the Bubble Sort algorithm.

    Args:
        list_: The list of elements to be sorted. Elements must be comparable.

    Returns:
        A new list containing all elements from the original list in ascending order.
        
    Example:
        >>> bubble_sort([64, 34, 25, 12, 22, 11, 90])
        [11, 12, 22, 25, 34, 64, 90]
    """
    n = len(list_) 
    for i in range(n):
        # Flag to optimize, if no swaps occur, the list is sorted
        swapped = False
        # Last i elements are already in place
        for j in range(0, n-i-1):
            # Swap if the element found is greater than the next element
            if list_[j] > list_[j+1]:
                list_[j], list_[j+1] = list_[j+1], list_[j]
                swapped = True
        # If no two elements were swapped in inner loop, the list is sorted
        if not swapped:
            break
    return list_

5. Application Scaffolding

Perhaps the most impressive application of Generative AI is its ability to generate initial application structures. Given a clear schema or specification, AI can create:

This capability significantly reduces the time spent on boilerplate code and ensures a consistent foundation for further development.

Prompt:

You are a Software Engineer working at a large corporation. Using the following database schema, generate the SQL scripts necessary to create these tables in Postgres. Then, generate the SQL Alchemy mapping files to use with FastAPI. Lastly, generate a simple web UI using FastAPI to list the orders.
User
- UserId
- FirstName
- LastName
- Address
- Address2
- City
- State
- ZipCode
- Username
- Password
- IsActive

Client
- ClientId
- Name
- Address
- Address2
- City
- State
- ZipCode
- IsActive

Order
- OrderId
- OrderDate
- InvoiceNumber
- DueDate
- ClientId
- UserId

OrderDetail
- OrderDetailId
- OrderId
- Description
- Rate
- Quantity
- LineTotal

Ledger
- TransactionId
- Debit
- Credit
- OrderId
- TransactionDate

Output:

...
I'm saving you from the output, but it generated an entire application using FastAPI.
...

Let’s ask what we can do to improve upon the initial design.

Prompt 2:

That's a great start. What can we do to improve the application design?

Output:
Implement logging for better debugging and error handling.

logging.py (Optional)

import logging

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)

def log_error(error):
    logger.error(f"An error occurred: {error}")

Prompt 3:

Can you implement your suggestion to use Error Handling and generate the code for me?

Output:
You can also define global exception handlers in your main.py file if you want to handle specific exceptions globally.

main.py

from fastapi import FastAPI, Request
from fastapi.responses import JSONResponse
import app.routers.order_router as order_router
from .exceptions import OrderNotFoundException, InvalidInvoiceNumberException

app = FastAPI()

# Include the router
app.include_router(order_router.router)

@app.exception_handler(OrderNotFoundException)
async def order_not_found_exception_handler(request: Request, exc: OrderNotFoundException):
    return JSONResponse(
        status_code=exc.status_code,
        content={"detail": exc.detail},
    )

@app.exception_handler(InvalidInvoiceNumberException)
async def invalid_invoice_number_exception_handler(request: Request, exc: InvalidInvoiceNumberException):
    return JSONResponse(
        status_code=exc.status_code,
        content={"detail": exc.detail},
    )

Best Practices and Considerations

While Generative AI is powerful, it’s important to:

Conclusion

Generative AI has become an indispensable tool in modern software development. By leveraging these five approaches - enhanced searching, code generation, translation, documentation, and application scaffolding - developers can significantly increase their productivity while maintaining code quality.

The key is understanding these tools’ capabilities and limitations and strategically using them to enhance rather than replace human expertise. As these technologies evolve, their integration into development workflows will become increasingly valuable.


Author’s Note: Chuck Conway specializes in software engineering and AI. Connect with him on social media: X(@chuckconway) or visit him on YouTube.



Next Post
4 Lessons from a 30 Year Career in 5 minutes