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.
The Right Way to Use AI for Writing Maintainable Code
Sous-titres (700 segments)
Today I'm going to show you how to
properly direct an AI to write code for
you. And in my opinion, not enough
people are doing this. What I show you
will massively improve the quality of
the code that you produce with AI. Make
sure you stick around to the end because
I have something big planned for this
year. It ties directly into what I talk
about today. When I hear people talking
about writing code with AI, I always
hear stuff like, "I made this working
app in 10 minutes," or, "It just took me
a few hours to develop this amazing
dashboard and now I have 10K monthly
recurring revenue." Well, first, let's
be real. There's much more to running a
business than just having a working app.
That's almost like a side note next to
having to do all the other stuff like
marketing, sales, finances, taxes,
accounting, etc. Trust me, it's not that
easy. Second, if your mindset is, hey, I
just want to ship stuff that works,
well, you're going to have a big problem
in the long term. Designing your
software properly has always been
important. And with AI writing more and
more of our code, it's even more
important today. Think of design as your
main tool for managing complexity. When
your system is less complex, AI
understands context better, your prompts
become simpler and clearer, and the code
it generates become something that you
can actually maintain and keep improving
almost indefinitely. Let me show you
exactly how to do that using a real
interaction I had with Chat GPT while
working on a code example for another
video. Now, obviously, you can use any
AI coding assistant. It doesn't really
matter. I use chat GPT a lot because
it's pretty good and I also use it to
help me write script outlines. And by
the way, I never literally say what chat
GPT produces. I mainly used to generate
some talking points and then I rewrite
it a ton because well, it's never
exactly what I want. For this particular
interaction with Chad GPT, I was working
on a video covering the fluent interface
design pattern. So now you know what
video is going to come out in a few
weeks. It's not really about the actual
code here. I just want to show you the
interaction I had with Jad GPT about
this and what you can do as well to
improve the code that you write with AI.
So it starts with an example that I let
Jad GPT generate that is some sort of
animation system and as you can see
there is an animation class it has steps
like moving, rotating, scaling these
kind of things. There's an animation
runner that uh uses uh TK canvas to show
an animation. It has a couple of
methods. Uh there's uh the methods here
like moving, rotating, etc. And then we
have a method for running the animation
where it goes through each of these
steps and then updates the shape. And
finally, a demo where we have some
animation object and we call some method
on it. And and by the way, this is the
whole idea of the fluid interface
pattern where you can call these things
in sequence, similar to the builder
pattern, but slightly different. So
that's basically the starting point that
I let it generate. Now, if you just
focus on code that works, you're
probably pretty happy with this and
you're like, okay, well fine, let's use
that. But as you'll see in a minute, I
actually spent a lot of time tweaking
the details and letting it rewrite stuff
and change things. And that's really
important step to take. So a bunch of
text that it generates. Let's see what I
write. I write modify the design so that
actions are not all separate method in
the class. I also don't like the huge if
statement in the run methods. So already
I'm uh looking at this code and thinking
oh actually I don't really like this.
You know this is a bit messy because if
we want to add more actions well this
becomes even larger. You may remember
the registry design pattern I talked
about a while back that can help solve
this. Another thing that I asked to do,
I didn't really like having all these
methods being part of the animator
class. So, let's see what it comes up
with. So, now it turned each animation
step into a command class, which well
kind of makes sense. And then it can
loop through the commands and run an
apply method on each step. So, what does
this look like? So, we have now an
animation step protocol. Well, nice.
That introduced some abstraction. we
have our steps like move, rotate, scale,
fade, etc. So that's already an
improvement in a sense from the version
before where basically all the actual
transformations were part of methods in
the animator class. So these are now in
separate classes. So we improved the
design which is nice. And then animation
has steps. We have a play method that
runs these things. And then it did
something weird which is that it now
defined separate functions and then it
uh monkey patched these into the
animation class which is a bit uh
awkward. That's not really what I meant.
And for the rest there's a couple of
minor changes as well. Doesn't really
matter. So I didn't really like that. So
I wrote okay make the extension methods
part of the animation class after all.
And then I asked it an abstraction
question. Is there a way to make the
animation step classes independent of
animator? Uh why is that important?
Well, if you look at animator, you see
that it gets a list of animation steps.
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
Commentaires (0)
Connectez-vous pour CommenterInscris-toi pour débloquer toutes les fonctionnalités
Suis ta progression, sauvegarde du vocabulaire et entraîne-toi
Mode interactif
Quiz
Rponse correcte :
Vidéos liées
Late Night with Seth Meyers
Quiz
Rponse correcte :
Les quiz apparaissent pendant que tu regardes la vidéo
Astuce mémo
Dans cette vidéo
Apprendre les langues gratuitement