Return to Generative AI User Guides

GenAI in Coding Tutorial

Overview

Generative AI coding assistants enhance developer productivity by streamlining the coding process, automating repetitive tasks, and offering debugging and optimization support. They provide real-time code completion suggestions, enabling researchers to focus on experimental design and data analysis. With access to extensive code repositories, these tools encourage the exploration of new coding techniques and innovative solutions in various research fields.

In this guide:

Getting Started

This quick-start guide helps researchers with little programming experience learn coding with an AI assistant’s help, assuming a chosen programming language like Python, JavaScript, or C++. Instead of basic text editors like Notepad, an integrated development environment (IDE) is essential for using an AI assistant. IDEs offer extensive support, including code coloring, library management, and automated documentation.

IDEs should be selected based on what programming languages they support. For example, the Jetbrains IDE DataSpell is a common choice for Python developers, while Visual Code is often preferred for C++ and C# developers. 

2.

Choose your preferred Generative AI coding assistant. In this guide we will focus on GitHub copilot GenAI coding assistant (see here for access details).

3.

Once you have installed your preferred IDE, and gained access to your preferred GenAI coding assistant, you must enable the GenAI coding assistant within your IDE. This depends on your selected IDE and assistant, example instructions of how to do this for GitHub Copilot and the various supported IDEs can be found here.

4.

Launch your IDE and begin a new project. Insert a “Hello World” snippet from here for your preferred programming language (we will assume Python for the rest of this guide). If you type in a comment, e.g.

# Then Print “This is working!”

5.

If you see something like below (in this example, the comment is line 3, then line 4 is the suggested code by the AI assistant), then you will know that your AI assistant is working!

Tips for Prompting

1.

Keep explanations simple and short.

2.

Articulate the logic and steps it needs to follow for achieving your goal.

3.

Experiment with your prompts, and give the AI examples where possible.

Use Cases

1.

Automated Code Generation: Use AI to generate code snippets for data analysis and simulations.

2.

Code from Manuscripts: Generate code by inputting manuscript text into an AI tool.

3.

Data Cleaning: Leverage AI for data cleaning and preparation suggestions.

4.

Code Design: Use AI to suggest code structure based on similar solutions.

5.

Debugging/Optimization: AI suggests code improvements for efficiency and bug fixes.

6.

Documentation/Refactoring: AI assists in creating documentation and suggests code refactoring for clarity and maintainability.

7.

Automated Testing: AI generates test cases and test code to ensure robustness.

8.

Software/API Integration: AI suggests best practices and code for software/API integration.

9.

Scalability: AI identifies bottlenecks and suggests architectural changes for scalability.

10.

Cross-language Translation: AI helps translate code across different programming languages, enhancing team collaboration.

Additional Resources

  • See our resource hub for examples of generative AI used in research and more resources.