Chapter 8. Coding
In this chapter, we’ll dive into some handy coding techniques. We’ll start with the bread and butter of coding—playing around with functions and classes. Then, we’ll get our hands dirty with a bit of refactoring, tidying up messy code and making it run smoother. We’ll also show how to work with and create data. Then we’ll check out some AI tools that can help create fancy frontends without breaking a sweat.
Reality Check
AI-assisted programming tools are pretty cool, right? But let’s not kid ourselves. They’re not the magic wand that can solve all our coding problems. Why? Well, these tools are like those students in class who only learn from public notes. They’re trained on a mishmash of code from all over the internet, and let’s be honest, not all of it is top-notch. What does this mean for you? Sometimes, you might get code that’s more bloated than a Thanksgiving turkey or as maintainable as a house of cards. And sometimes the code is just plain wrong, doesn’t do what you need, or, even worse, leaves your front door wide open for hackers or the hogging of your network resources.
Let’s look at an example where ChatGPT produced messy code. Figure 8-1 shows code for merging two sorted lists into a single sorted list.
This AI-generated code does correctly merge two lists, but it ...
Get AI-Assisted Programming now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.