Using Generative AI for programming
Using Generative AI For Programming
The rise of generative AI
- Generative AI is the new hotness in the whole IT field
- Generative AI models
- …learn the patterns and structure of their input training data
- …generate new data that has similar characteristics
- a.k.a. write a prompt, and you get text/code/images/videos/music/etc
- Large Language Model (LLM) is a form of generative AI
- Used often in a chat-like interface
- OpenAI’s GPT series is a LLM, a technology that fuels the popular ChatGPT chatbot
GitHub Copilot
- GitHub’s paid code auto-completion service that is advertised as AI pair programming
- What is it really?
- Autocomplete on steroids, $10/month
- See Copilot here in action
- It looks like magic, right?
- This could be useful for generating basic boilerplate code
- But wait, there’s
var
variables there… - Old JS! Shouldn’t be used nowadays!
- You might know this, but not everyone knows that
- But wait, there’s
How does generative AI work?
- All AI models need data
- GitHub Copilot is trained on your public GitHub code
- GPT-3 is trained on 17 GB of text, GPT-4 on 45 GB
- AI does not know when it’s wrong, when it’s using bad practices
- TBH, it does not know anything
- It just returns an answer that best matches your prompt
- It might be exactly what you need, but it also might not
- TBH, it does not know anything
- The future of AI is worse: At some point, AI will be taught on AI-generated code
- The quality of the result worsens!
Is ChatGPT any good?
- Okay, we know the risks. What’s ChatGPT good for?
- Let’s ask ChatGPT!
- Summary:
- Makes mistakes
- Doesn’t understand context
- …And I somewhat disagree the pros 3-5
Using ChatGPT professionally
- Do note that GPT-3 and GPT-4 (the paid version, $20/month) are not equal in terms of quality of results
- I asked two senior developers who’ve used ChatGPT professionally for its pros and cons
- Some comments I got:
- “I don’t usually use it for writing code, but for other stuff”
- “It makes some mindless tasks way faster”
- “Not always right, but surprisingly often!”
- “Works for some languages, but not all”
Example use cases (Dev 1)
1) Finding causes for error messages * ChatGPT can the cause for a given error message faster than a developer * You give code & error message -> ChatGPT gives fixed code as a result * Gotcha: This works when you are working on something that someone else has worked on before
2) Explaining architectural solutions * Examples: * “How to set up a service in AWS for x number of people” * “How to set up an event based service”
Example use cases (Dev 1), cont.
3) Reading documentation for you
- Make a summary of a long documentation! 4) Writing regexes 5) Writing helper functions
- “Make sure this string is 4 characters long”
- “Give me input validation for x”
- Always test the results with care
Example use cases (Dev 2)
1) Give high-level specs for a program * “I should do software in framework X that should do Y” * ChatGPT gives a basis for the software * This is a good starting point for writing your software * …but rarely even a single line of the basis are left in the final software! 2) Help you understand code you can’t fathom at all * “Convert this to Python!” 3) When you have to write something you’ve never written before
- But don’t trust it on this
- If the programming language is strict about its syntax, ChatGPT results are generally better
- Rust is good, C++ bad
- Also: Does not work with C++ well because there is so much badly written or obsolete C++ on the Internet!
Let’s also remember these words from Linus
Generative AI is here to stay
- I don’t believe for a second generative AI will make programmers obsolete
- It won’t go away, though, and it will change the nature of some programming
- It’s a new tool, and in a field where we get new tools every year, it’s good idea to keep your mind open for new tools
- It’s not a silver bullet, however
- It can make you bypass learning altogether
- And you NEED to understand code in order to use AI tools effectively
- It can make you write worse code
- …but it can also make you a faster programmer.
- …and a faster programmer is a better programmer!
- It can make you bypass learning altogether
AI is a good servant, but a bad master
Reading & Watching
- Practical AI - Mitä jokaisen tulisi tietää tekoälystä
- Tekoäly on hyvä renki mutta huono isäntä - näin algoritmit muuttavat yhteiskuntaa ja arkeamme
- Patrick Boyle: Is AI Actually Useful?
- Tom Scott: I tried using AI. It scared me.
- Business Insider: ChatGPT has been losing its mind and no one seems to know why
- Erik Hoel: Here lies the internet, murdered by generative AI