Appendix 3: Using AI in Coding

Appendix 3: Using AI in Coding#

Introduction#

In the last decade and particularly in the last 2 years, artificial intelligence (AI) has had a large impact on many areas. Coding has been particularly affected, as the latest AI models are capable of generating increasingly complex code fragments from simple language requests. These tools are particularly useful for beginner programmers, who in most cases would be looking to write or modify relatively simple code. Therefore this homework assignment is for you to explore these AI models, hopefully helping you tackle larger and more complicated projects that you otherwise might initially dare!

There are several things to keep to the use of these models.

  1. They perform best when the request is explained as clearly as possibly, with as much context and specifics as possible.

  2. For now, the AI models perform best in writing relatively small sections of code - up to around 200 lines of code. Therefore when tackling something even larger than this, it is worthwhile to split the program in smaller chunks and request AI to write these one after another.

  3. While it is becoming less of a problem, the AI models can still hallucinate, when they do not know something. This is generally in the form of AI confidently using a package that does not exist, or does not have the functionality the code needs.

  4. Human programmer oversight and understanding of the coding project is still a crucial component in this process, and therefore you still need to think along.

There are 3 main AI forms - ChatGPT, AnthropicAI and Copilot.

1. ChatGPT#

To explore models created by OpenAI:

  1. Go to chatgpt.com, create a user

  2. Try asking for a code for the molecular weight calculator. Copy and paste the code into VS Code and try running it. Does it work? You may need to install any packages that the code requires.

  3. These tools are very interactive - you can always request certain changes to the code.

    • In this example you may want to ask AI to write the code without using external packages.

    • Or maybe you want it to write it using only for loops, or only while loops.

    • You could also ask for the AI to write a graphical user interface for easier data input. This will likely require installing additional package, like PyQT.

  4. You can also paste any errors you encounter in running the code back in the conversation and in many cases the AI will be able to guide you through the troubleshooting.

  5. Finally, you can also ask the model to explain any aspect of the code, to increase your understanding. This is very important, as code understanding will be the major component of your final project assessment.

  6. Now start a new conversation and ask it to write something more complex - perhaps one of the project ideas that were offered to you.

  7. Test the code to see if it runs, or if any additional packages need to be installed.

2. Anthropic Claude#

Anthropic is another company that provides high-performing AI models. Go to anthropic.com, register to use Claude AI and try to repeat the same steps as for ChatGPT.

3. Microsoft Copilot#

This is a family of AI models that Microsoft is increasingly integrating in its software, including programming. This is available from VS Code (more explanation needed here.)