How to Use AI to Improve Your Coding Productivity

Blog | August 11, 2023

Pasi Kovanen, our senior software developer, provides an introduction to developer tools utilizing artificial intelligence and offers practical tips to help you begin your journey.

aiHero

Generative AI is a subset of artificial intelligence that has the capability to produce new content, such as images, text or code, by leveraging patterns it has learned from existing data. It presents thrilling opportunities for developers while also posing several pitfalls. In this blog, I'll provide an introduction to the technology and offer practical tips to help you begin your journey.

Large Language Models

Large language models (LLM) constitute a specific category of generative AI that focuses on generating human-like text. These models are trained on vast amounts of textual data and can produce contextually relevant text based on the input they receive. In addition, LLMs can even generate code by learning from extensive programming data.

Never trust the computer

AI code generation offers great potential but comes with critical concerns. Always review AI-generated code for bugs and logical errors. Sometimes AI can even generate code that doesn't work at all, although it may be capable of identifying and rectifying the bugs it generated. I'll provide an example I've encountered in a later chapter.

Additionally, it is possible for LLMs to produce syntactically correct but nonsensical code, a phenomenon referred to as hallucination.

hallucination
ChatGPT hallucinating - The name of Sauli Niinistö's father was indeed Väinö Niinistö, but he died in 1991 and worked as a circulation manager of a local newspaper.

GPT

GPT stands for "Generative Pre-trained Transformer." It is an LLM developed by OpenAI, an organization focused on advancing AI research. OpenAI has developed several iterations of the GPT model, with the latest being GPT-4.

A significant limitation of current GPT versions is that their knowledge cutoff date is September 2021. Consequently, GPT is unaware of any events or developments that have taken place after that time.

ChatGPT

ChatGPT is a conversational application leveraging the capabilities of GPT-3.5 and GPT-4 models, making it an advanced chatbot for various interactive tasks. It can be accessed via a web browser or through an API.

Users can access ChatGPT powered by GPT-3.5 for free. For enhanced capabilities using the newer GPT-4 model, you can subscribe to ChatGPT Plus at $20 per month.

GPT-4 was trained using a much bigger dataset and is, for instance, capable of solving complex scientific problems, understanding images, and accessing certain plugins, such as PDF generation. However, GPT-3.5 performs well in many software development scenarios. You can also access GPT-4 for free using Microsoft Bing. More details on this will be provided later.

chatgpt
Example discussion with ChatGPT.

Use cases

The versatility of ChatGPT makes it a valuable tool in various scenarios. Some examples:

Code generation: Request ChatGPT to generate code for you.

Code review: ChatGPT is capable of offering valuable suggestions, identifying bugs and providing help with potential solutions.

Code assistance: Describe your issue, read the answer, and ask follow-up questions if needed—it's like using Stack Overflow in an interactive way.

Understand code: Ask ChatGPT to explain what a specific piece of code does.

Refactoring: Bring legacy code up to date, simplify complex code or let AI generate tests.

Assistance with tools: ChatGPT can provide guidance on how to perform specific tasks with tools like Git.

Example discussion with ChatGPT

Below is a conversation I recently had with ChatGPT, when I wanted to add a chart to a React application.

"Recommend a charting tool for React"
ChatGPT returns a list of six chart libraries and a short introduction for each. I select Recharts.

"Create an example component using Recharts"
ChatGPT generates code for a JavaScript component that creates a bar chart.

"Use TypeScript"
Component is converted to TypeScript.

"Switch to line chart"
Chart type is changed.

"Turn off animations"
Interestingly, the updated component version is causing an error.

"That didn’t work, I got an error: …"
ChatGPT apologizes and rectifies the issue.

Data Privacy

OpenAI is not transparent on how it may use customer data, and companies are struggling to prevent confidential data from ending up in ChatGPT.

Never share sensitive data with ChatGPT. By default, all of your conversations with ChatGPT are stored on OpenAI's servers. There has been an incident where user generated data was mistakenly shown to other users.

OpenAI API

OpenAI also offers an API for accessing its LLMs. In addition to creating your own AI powered applications, access to the API is needed in order to use GPT-powered code generation in e.g. an IDE. One example of such a plugin is ChatGPT by Genie AI for Visual Studio Code. It enables you to get help from ChatGPT directly from the IDE, without needing to paste the code to the browser.

API usage is charged based on tokens. A token is a basic unit of language that AI models process. It can be a character, word or part of a word. There is a Tokenizer tool with which you can test how many tokens a text consumes.

Pricing of the API depends on the model. New users receive $5 worth of free tokens upon account creation, with tokens expiring after three months. Heavy users can easily burn several euros in a day.

Data sent via the API is stored for 30 days.

Code Interpreter

ChatGPT Plus also offers Code Interpreter functionality as a plugin. It’s a sandboxed Python environment to execute code to perform various tasks. Some examples you can use Code Interpreter for:

  • Do data analysis of datasets using Comma Separated Values-files (CSV)

  • Extract text from images using Optical Character Recognition (OCR)

  • Generate QR Codes

  • Convert files between different formats, e.g. Word to PDF

  • Solve complex math equations and produce graphs

Google Bard & Microsoft Bing

ChatGPT isn't the sole player in this arena. For instance, both Google's Bard and Microsoft's Bing Chat provide comparable functionality. Bard is driven by Google’s own PaLM 2 LLM, while Bing leverages the power of GPT-4. Both services are free to use at the moment. The example discussion above works also with both Bard and Bing.

Accessing Bing Chat may require using Microsoft Edge browser at the time of writing; however, Safari and Chrome may also work.

Coding assistants

Coding assistants are software tools that help developers write code more efficiently using features like autocompletion, error detection, code suggestions and code generation. Two popular generative AI-based coding assistants are GitHub Copilot and Amazon CodeWhisperer.

They work in similar ways: write a comment describing what a function should do, or start to write a function with a descriptive name. Assistant will show you a code suggestion that you can accept with the tab key.

codewhisperer
CodeWhisperer suggestion after writing function name.

GitHub Copilot

Developed jointly by GitHub and OpenAI, GitHub Copilot offers a plugin for various IDEs. It comes in two paid plans: Copilot for individuals at $10 per month and Copilot for business at $19 per month, with a 30-day free trial.

Copilot can be used with numerous languages and frameworks, but it’s promised to work especially well with Python, JavaScript, TypeScript, Ruby, Go, C# and C++.

Data privacy settings vary depending on the plan. By default, Copilot for Individuals saves source code on the server, while Copilot for business discards code snippets after suggestions are returned.

There is an ongoing lawsuit regarding whether Copilot violates legal rights, as it has been trained using code from public repositories on GitHub.

Amazon CodeWhisperer

CodeWhisperer is very similar to Copilot. It is based on an LLM generated by Amazon.

Also CodeWhisperer offers two plans: Individual (free) and Professional ($19/month).

Most supported languages are Java, Python, JavaScript, TypeScript, C#. There are also other languages CodeWhisperer supports code generation for. Additionally, CodeWhisperer excels in AWS-specific tasks, including the creation of configuration files.

While CodeWhisperer Professional does not store or use user data for service improvement, AWS may store data snippets by users of the Individual plan if the default settings are not changed.

Conclusion

Generative AI and AI-powered code generation have opened up exciting possibilities for developers and users alike. A great way to start experimenting is to create a free ChatGPT or CodeWhisperer account and start playing with it. However, as these technologies continue to evolve, it is crucial to be aware of their benefits, limitations, and data privacy concerns.

The cover photo was generated using Bing Chat with the following prompt that was formulated using ChatGPT:

Generate an image that visually represents the concept of using AI to enhance coding productivity. Depict a seamless integration between a human coder and an AI-powered tool. Show a diverse range of programming languages and tasks being collaboratively executed by the human and AI, symbolizing efficient code generation, error detection, and assistance. Convey the idea of progress, innovation, and collaboration in the field of coding with a modern and dynamic aesthetic.

Want to know more?

Our expertise is at your service. Whether you’re starting a new project or need assistance with an existing one, we’re here to help.

Say hello to get the ball rolling.