TRANSCRIPTIONEnglish

How to deslop your code

10m 37s1,948 mots310 segmentsEnglish

TRANSCRIPTION COMPLÈTE

0:00

Hi, my name's Mike and I am an

0:03

AI-aholic. Hi, Mike.

0:06

I have a confession to make. My last big

0:08

feature that I worked on,

0:09

>> [music]

0:10

>> you know the one, the AI files one, the

0:11

one that I just did a whole big video

0:12

on. Well,

0:14

it's total slop.

0:16

You see,

0:17

I just I just got so carried away with

0:19

the speed of development that AI gave me

0:21

that I just didn't stop. Just stopped to

0:24

think of the consequences.

0:27

Okay, enough of that. So, basically, the

0:29

problem was that I didn't actually truly

0:32

understand what the code was doing.

0:34

Now, don't get me wrong. I understood

0:36

the feature from like a high-level

0:37

perspective, but when I was getting

0:39

requests about specific parts of the

0:41

code, I was kind of like,

0:43

"Yeah."

0:45

And that's not great when an important

0:48

feature like this is on the critical

0:49

path for our users.

0:51

So, I decided, "No, enough was enough.

0:54

I'm going to get my hands dirty and wade

0:56

through this slop to try and uncover

0:58

exactly what's going on here."

1:00

I learned some valuable lessons along

1:01

the way on my de-slopping journey that I

1:03

think are worth sharing. So, stick

1:05

around as I have three actionable things

1:07

that you can do to de-slop your code

1:09

today. And I might even share a skill at

1:12

the end that can help you because, you

1:14

know, the only way to fix AI slop is

1:16

with more AI, right?

1:18

Anyways, once you grab yourself a lovely

1:20

cup of tea, drop me a like and sub,

1:22

we'll get into it.

1:24

Let's just start off with a quick

1:25

reminder of this feature if you haven't

1:27

watched my previous videos on this

1:28

already. But, basically, AI files is

1:31

going to inject this additional prompt

1:33

when you set up a Convex project asking

1:35

you whether you would like to add the AI

1:37

files to your project. Now, AI files are

1:40

guidelines and agent skills that are

1:42

designed to enhance the model

1:43

performance when writing Convex code.

1:45

And as part of this feature, there's a

1:46

new CLI that you can use to update the

1:49

AI files or remove them or a few other

1:51

things.

1:52

Okay, so so far, so good. Seems pretty

1:54

simple, right?

1:56

Yeah, well, the issue is that there are

1:57

a number of different logical flows that

2:00

the code can go through, whether you're

2:02

running Convex dev the first time or

2:04

subsequent times, or you're running from

2:07

the AI files CLI, or you're running for

2:09

the Convex dev path.

2:11

Are you a human, or are you an agent, or

2:14

are you on the CI, or some other sort of

2:16

non-interactive prompt?

2:18

And so, in short, we just have this

2:21

tangle of logic and rules that's just

2:23

hard to follow at the best of times, let

2:26

alone when the code looks something like

2:28

this.

2:29

Yeah, so most of the code here is

2:31

contained in this 1,000-line index file

2:34

uh that I personally find really hard to

2:37

know where even to start when code looks

2:39

like this.

2:41

So, my first step is to break this up

2:43

into smaller files, areas of different

2:46

responsibility.

2:47

So, now I think it's much better. We

2:49

have a number of smaller files that

2:50

pertain to key areas such as the

2:53

agents.md, claude.md, guideline skills,

2:56

etc.

2:57

By the way, as we go through this, I

2:59

just want to note that I didn't actually

3:01

do all this manually by hand. I'm not

3:03

some kind of savage. I just swapped to a

3:06

smaller model, smaller faster model, and

3:08

then I would just queue up a bunch of

3:10

orders, like split this off here, split

3:12

that bit off there, etc.

3:14

Now, maybe I could have given the AI a

3:16

high-level goal such as split this up

3:18

into, you know, sensible uh sections,

3:21

and it would have worked fine. But, for

3:23

me, part of the reason for doing this

3:25

de-slopping process, doing this first

3:27

initial de-slopping process, is for me

3:28

to get a better grasp of where the

3:30

various parts of the code base are, what

3:32

the various functions are. So, this

3:34

little bit of extra manual work

3:36

>> [music]

3:36

>> is acceptable for me at this stage.

3:38

Okay, so now that we've split things up

3:40

a bit and I have at least a general

3:42

high-level idea of the different parts

3:44

of the code base, I began working on the

3:46

actual code itself.

3:48

So, as an example, let's take a look at

3:49

one of these gnarly tangled functions

3:52

that I've been talking about.

3:53

Yeah, so if this makes you go a little

3:55

bit cross-eyed, you aren't alone, as

3:58

that's exactly what I thought when I

3:59

first saw it.

4:00

Not only is it far too long, it's also

4:03

just doing like far too many separate

4:05

things. It's kind of hard to tell where

4:06

one part ends and another one begins, or

4:09

one one part begins and another part

4:11

ends, you know.

4:12

There's also a bunch of this

4:14

nesting and sub-nesting logic in here

4:16

and error handling, which makes me just

4:17

go "Ugh."

4:19

Now, when I encounter a big gnarly

4:21

function like this, the first thing I

4:23

try to understand is, what is actually

4:25

the purpose of this function? What is it

4:27

trying to do?

4:28

So, we actually have a comment at the

4:30

top here, which is handy.

4:32

But, don't forget, you can't always

4:34

trust comments because they can very

4:36

easily go stale.

4:38

But, what it does say is write/update

4:42

all Convex AI files, guidelines,

4:44

agents.md, claude.md, skills, etc.

4:47

Yeah, so a quick scan uh of the code

4:50

here makes me think this comment

4:51

probably isn't stale, which is nice. I'm

4:53

seeing parts that seem to be handling

4:55

the various um different functions as

4:57

mentioned.

4:58

So,

5:00

this most sensible thing that I would do

5:01

next here is to split this into

5:04

different sub-functions.

5:06

And that results in something that looks

5:07

more like this.

5:09

Ah.

5:10

That's much better, in my opinion.

5:12

Now, we have a clear set of things that

5:14

the function's going to undertake,

5:16

extracting out each part to its own

5:17

little self-contained function.

5:19

It's much It's also much easier to

5:20

understand what this function is just

5:22

going to do at a glance and allows us to

5:24

easily make more changes in the future.

5:26

Now, I don't want to bore you guys and

5:28

going through every minor clean code

5:31

practice that I followed here.

5:33

I have a couple of videos on this topic

5:34

already uh if you want to know more.

5:37

But, I do want to just quickly dive into

5:40

this function, read AI config or

5:42

default, as it illustrates a couple of

5:44

things that I'm aiming for.

5:46

Note how we named this function read AI

5:49

state or default. So, it's clear from

5:52

the name of the function what it's going

5:53

to do. And also note that it's going to

5:56

call into this attempt read AI state

5:59

function.

6:00

Right off the bat, note that we named it

6:03

read AI state or default, so it's super

6:06

clear from the name of the function what

6:07

it's supposed to be doing.

6:09

And you can see that it handles the

6:11

various different code paths that could

6:14

potentially come out of this function,

6:16

the [music] attempt read AI state, which

6:18

is actually doing the reading.

6:20

And if we just double-click into there,

6:22

you'll note that this function again is

6:24

is being prefixed with a sensible name

6:26

attempt here, so it indicates that it

6:29

could potentially fail,

6:31

but we are also going to be catching

6:34

those errors [music] and leaving it up

6:36

to you to deal with those errors.

6:38

So, this clear separation of

6:40

responsibilities between the function

6:43

and the caller of that function makes

DÉBLOQUER PLUS

Inscrivez-vous gratuitement pour accéder aux fonctionnalités premium

VISUALISEUR INTERACTIF

Regardez la vidéo avec des sous-titres synchronisés, une superposition réglable et un contrôle total de la lecture.

INSCRIVEZ-VOUS GRATUITEMENT POUR DÉBLOQUER

RÉSUMÉ IA

Obtenez un résumé instantané généré par l'IA du contenu de la vidéo, des points clés et des principaux enseignements.

INSCRIVEZ-VOUS GRATUITEMENT POUR DÉBLOQUER

TRADUIRE

Traduisez la transcription dans plus de 100 langues en un seul clic. Téléchargez dans n'importe quel format.

INSCRIVEZ-VOUS GRATUITEMENT POUR DÉBLOQUER

CARTE MENTALE

Visualisez la transcription sous forme de carte mentale interactive. Comprenez la structure en un coup d'œil.

INSCRIVEZ-VOUS GRATUITEMENT POUR DÉBLOQUER

DISCUTER AVEC LA TRANSCRIPTION

Posez des questions sur le contenu de la vidéo. Obtenez des réponses alimentées par l'IA directement à partir de la transcription.

INSCRIVEZ-VOUS GRATUITEMENT POUR DÉBLOQUER

TIREZ LE MEILLEUR PARTI DE VOS TRANSCRIPTIONS

Inscrivez-vous gratuitement et débloquez la visionneuse interactive, les résumés IA, les traductions, les cartes mentales, et plus encore. Aucune carte de crédit requise.