13  AI for coding work

14 AI for coding work

Before we look at what an LLM is, it helps to know what it has changed about coding. The short answer: a lot of the boring middle, and almost none of the careful edges. This chapter sets the practical floor that the rest of the book builds on.

14.1 What you will get from this chapter

  • A concrete sense of where AI saves real time on coding tasks.
  • A concrete sense of where it does not, or actively misleads you.
  • Three habits that turn the time savings into actual quality.

14.2 What changed, and why

Most data-analysis code looks similar across projects. Load a CSV. Clean a few columns. Join two tables. Group by something. Plot. Run a regression. Save a figure. The combinations are infinite; the vocabulary is small and well-documented.

That vocabulary is everywhere on the internet, which means it is in every frontier model’s training data. If you ask a chat AI for “a pandas snippet that loads morg-2014.csv, restricts to ages 18 to 65, and computes mean weekly earnings by sex,” it produces working code on the first try almost every time. The library calls live in its memory.

This is not nothing. Five years ago, that snippet took ten minutes of typing, looking up syntax, debugging an off-by-one, and fixing a typo. Now it takes thirty seconds. Multiplied across a project, the difference is real.

14.3 Where AI is genuinely strong

A short list, picked from work in this book.

  • Boilerplate. Imports, default plot settings, the top of a script.
  • Standard transformations. Filter, group, pivot, melt, merge. The pandas lexicon.
  • Standard models. OLS with a handful of regressors. A logistic regression. A simple time series. The first time you reach for statsmodels or scikit-learn on a project, AI gets you there fast.
  • Translating between dialects. Pandas to Polars. Python to R when you have to. SQL to pandas.
  • Reading unfamiliar code. “What does this script do?” — surprisingly good answers, often better than the original developer’s comments.
  • Writing tests. Generating a small, plausible test for a function you just wrote.
  • Plot tweaks. “Add a title in 12pt, move the legend to the bottom, save as 300 dpi PNG.” The kind of fiddly request that takes ages to look up and seconds to ask.

14.4 Where AI is not strong (or is actively bad)

Equally short. Equally important.

  • Anything that depends on knowing your data. AI does not know your column names, your missing-data conventions, or what your survey weights mean. It will guess. The guess is sometimes right.
  • Causal reasoning. A regression coefficient is not “the effect of X on Y” without an identification strategy. AI uses the language anyway. You will need to push back.
  • Choices that are project-specific. Which observations to drop. What to use as the unit of analysis. Which version of the question to answer. AI will pick a default; the default is rarely what you want.
  • Tasks that require running the code and reading the output to know if it worked. A chat AI does not run anything. Even when it says it does, it sometimes does not. Run it yourself.

14.5 Three habits

These are the habits that keep AI useful instead of expensive.

1. Describe the data, not just the task. “I have a DataFrame with columns state, age, sex, earnwke, uhours. earnwke is weekly earnings in dollars; uhours is usual hours worked per week.” This single paragraph at the top of your prompt prevents most of the bluffing.

2. Ask for one thing at a time. AI is much better at “load and clean” than “load and clean and analyse and report.” Iterate. Each step you can check is a step that does not silently break the next one.

3. Read what it wrote. Even when it ran. Especially when it ran. Look for: did it filter the rows you expected? Did it drop or keep missings the way you wanted? Did the column names it used match your file?

14.6 A worked example

You are looking at the gender pay gap in the US Current Population Survey. You have morg-2014-emp.csv. You ask:

“Load morg-2014-emp.csv, restrict to ages 18 to 65 with positive earnwke and uhours, compute hourly wage as earnwke / uhours, and report mean hourly wage by sex. Columns are state, age, sex (1=male, 2=female), earnwke, uhours, grade92, occ2012.”

You get five lines of pandas. You run it. You print the result.

Two means, one for sex 1, one for sex 2. They look reasonable — a couple of dollars apart. Now you check. Does the row count after filtering make sense? Print it. Did anyone get assigned to neither category? Print df.sex.value_counts() first. Did you mean median, not mean, for an income variable with a right tail? You decide; AI does not.

Each of these checks takes ten seconds. They make the difference between a number you would put in a report and a number that happens to be on your screen.

14.7 Where AI helps · Where AI bluffs

Helps. Boilerplate, standard transformations, plot tweaks, reading unfamiliar code, writing tests, translating between languages.

Bluffs. Column-name guessing on data it has not seen. Causal language about correlations. “I ran this and it works” without actually having run it. The fix is the same as in Chapter 0f: use the harness that lets you check fast.

14.8 Keep this with you, not the AI

  • The shape of the data and what it represents.
  • The boundaries of your sample.
  • The interpretation of every coefficient and every estimate.
  • The decision of when to stop iterating and ship.

14.9 Try this

Pick a script you wrote at some point in the last year. Open a chat AI, paste the script, and ask: “What is this script doing? Are there any bugs or surprising choices?”

Read the answer. Notice which parts are right (often: most of them). Notice which parts are confidently wrong (often: anything that depends on the meaning of your variables). That gap is the chapter, lived.

14.10 AI and me

  1. How did AI support me here?
  2. How did AI fail me?
  3. How did AI extend me?

14.11 Where to go next

What an LLM is, in plain words — the model behind the harness. Worth a chapter; not worth a textbook.