The video owner has disabled playback on external websites.

This video is no longer available on YouTube.

This video cannot be played right now.

Watch on YouTube

Débloquez les outils d'apprentissage IA

Inscrivez-vous pour accéder à des outils puissants qui vous aident à apprendre plus vite avec chaque vidéo.

Explication de scne Chasseur de phrases Rvision par flashcards Pratique de répétition Répondre
S'inscrire gratuitement
Anglais 27:34 Science & Tech

The Right Way to Use AI for Writing Maintainable Code

Late Night with Seth Meyers · 41,984 vues · Ajouté il y a 1 mois

Sous-titres (700 segments)

00:00

Today I'm going to show you how to

00:02

properly direct an AI to write code for

00:04

you. And in my opinion, not enough

00:06

people are doing this. What I show you

00:08

will massively improve the quality of

00:10

the code that you produce with AI. Make

00:13

sure you stick around to the end because

00:14

I have something big planned for this

00:16

year. It ties directly into what I talk

00:19

about today. When I hear people talking

00:21

about writing code with AI, I always

00:23

hear stuff like, "I made this working

00:25

app in 10 minutes," or, "It just took me

00:27

a few hours to develop this amazing

00:29

dashboard and now I have 10K monthly

00:32

recurring revenue." Well, first, let's

00:34

be real. There's much more to running a

00:36

business than just having a working app.

00:38

That's almost like a side note next to

00:40

having to do all the other stuff like

00:42

marketing, sales, finances, taxes,

00:45

accounting, etc. Trust me, it's not that

00:48

easy. Second, if your mindset is, hey, I

00:50

just want to ship stuff that works,

00:53

well, you're going to have a big problem

00:55

in the long term. Designing your

00:58

software properly has always been

01:00

important. And with AI writing more and

01:03

more of our code, it's even more

01:04

important today. Think of design as your

01:08

main tool for managing complexity. When

01:11

your system is less complex, AI

01:14

understands context better, your prompts

01:16

become simpler and clearer, and the code

01:18

it generates become something that you

01:20

can actually maintain and keep improving

01:23

almost indefinitely. Let me show you

01:25

exactly how to do that using a real

01:27

interaction I had with Chat GPT while

01:29

working on a code example for another

01:31

video. Now, obviously, you can use any

01:33

AI coding assistant. It doesn't really

01:35

matter. I use chat GPT a lot because

01:38

it's pretty good and I also use it to

01:40

help me write script outlines. And by

01:42

the way, I never literally say what chat

01:45

GPT produces. I mainly used to generate

01:47

some talking points and then I rewrite

01:49

it a ton because well, it's never

01:51

exactly what I want. For this particular

01:53

interaction with Chad GPT, I was working

01:56

on a video covering the fluent interface

01:59

design pattern. So now you know what

02:01

video is going to come out in a few

02:03

weeks. It's not really about the actual

02:05

code here. I just want to show you the

02:07

interaction I had with Jad GPT about

02:09

this and what you can do as well to

02:11

improve the code that you write with AI.

02:14

So it starts with an example that I let

02:17

Jad GPT generate that is some sort of

02:19

animation system and as you can see

02:22

there is an animation class it has steps

02:25

like moving, rotating, scaling these

02:27

kind of things. There's an animation

02:29

runner that uh uses uh TK canvas to show

02:34

an animation. It has a couple of

02:36

methods. Uh there's uh the methods here

02:38

like moving, rotating, etc. And then we

02:41

have a method for running the animation

02:43

where it goes through each of these

02:44

steps and then updates the shape. And

02:47

finally, a demo where we have some

02:49

animation object and we call some method

02:51

on it. And and by the way, this is the

02:53

whole idea of the fluid interface

02:54

pattern where you can call these things

02:56

in sequence, similar to the builder

02:58

pattern, but slightly different. So

03:00

that's basically the starting point that

03:02

I let it generate. Now, if you just

03:04

focus on code that works, you're

03:06

probably pretty happy with this and

03:08

you're like, okay, well fine, let's use

03:10

that. But as you'll see in a minute, I

03:13

actually spent a lot of time tweaking

03:15

the details and letting it rewrite stuff

03:17

and change things. And that's really

03:19

important step to take. So a bunch of

03:22

text that it generates. Let's see what I

03:24

write. I write modify the design so that

03:26

actions are not all separate method in

03:28

the class. I also don't like the huge if

03:29

statement in the run methods. So already

03:31

I'm uh looking at this code and thinking

03:34

oh actually I don't really like this.

03:35

You know this is a bit messy because if

03:38

we want to add more actions well this

03:39

becomes even larger. You may remember

03:41

the registry design pattern I talked

03:44

about a while back that can help solve

03:46

this. Another thing that I asked to do,

03:47

I didn't really like having all these

03:49

methods being part of the animator

03:52

class. So, let's see what it comes up

03:56

with. So, now it turned each animation

03:58

step into a command class, which well

04:01

kind of makes sense. And then it can

04:03

loop through the commands and run an

04:05

apply method on each step. So, what does

04:07

this look like? So, we have now an

04:09

animation step protocol. Well, nice.

04:11

That introduced some abstraction. we

04:14

have our steps like move, rotate, scale,

04:18

fade, etc. So that's already an

04:20

improvement in a sense from the version

04:22

before where basically all the actual

04:24

transformations were part of methods in

04:27

the animator class. So these are now in

04:31

separate classes. So we improved the

04:33

design which is nice. And then animation

04:36

has steps. We have a play method that

04:39

runs these things. And then it did

04:43

something weird which is that it now

04:44

defined separate functions and then it

04:47

uh monkey patched these into the

04:49

animation class which is a bit uh

04:52

awkward. That's not really what I meant.

04:54

And for the rest there's a couple of

04:56

minor changes as well. Doesn't really

04:57

matter. So I didn't really like that. So

05:00

I wrote okay make the extension methods

05:02

part of the animation class after all.

05:05

And then I asked it an abstraction

05:07

question. Is there a way to make the

05:09

animation step classes independent of

05:12

animator? Uh why is that important?

05:15

Well, if you look at animator, you see

05:18

that it gets a list of animation steps.

05:21

And if we scroll up, we also see that

Sous-titres complets disponibles dans le lecteur vidéo

Entraînez-vous avec des exercices

Générez des exercices de vocabulaire, grammaire et compréhension à partir de cette vidéo

Vocabulaire et grammaire Quiz de compréhension Examen IELTS Pratique de l'crit
S'inscrire pour pratiquer
Pas encore de commentaires. Soyez le premier à partager vos idées !

Inscris-toi pour débloquer toutes les fonctionnalités

Suis ta progression, sauvegarde du vocabulaire et entraîne-toi

Apprendre les langues gratuitement