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
Desbloqueie ferramentas de aprendizado com IA
Cadastre-se para acessar ferramentas poderosas que ajudam a aprender mais rápido com cada vídeo.
Stop Building Ugly APIs: Use the Fluent Interface Pattern
Legendas (410 segmentos)
Let me show you two ways to describe the
same animation. So here's the first
version. So this animation consists of a
number of steps. We rotate, we move, we
scale, we fade, we move again, and we
fade again. And then there's durations
for each of these steps. Second version
looks like this. So it's the same
behavior, but it has a completely
different feel. And the second one is
using a pattern called fluid interface.
In this video, we're going to start with
a small animation engine and make it
cleaner step by step and refactor it
into a fluent API that feels like you're
telling a story in Python. Now, if you
want to learn more about how to design a
piece of software from scratch, I have a
free guide for you. You can get this at
iron./design guide. This contains seven
steps I take when I design new software.
Hopefully, it helps you avoid some of
the mistakes I made in the past.
Iron/design guide. The link is also in
the video description. Now, what is a
fluid interface? A fluid interface is a
style where methods return self. So, you
can chain them. For example, in Python,
that means you could type something like
this,
etc., etc., etc. Now, of course, it's
not a valid code. I'm simply typing it
here, but that's the idea. And the main
goal for this type of interface is that
it's more readable and that it's more
like a flow. So it's not really about
performance or having a clever design or
something like that. You typically use
this interface to write code that
describes a sequence of things to do in
an order that they should happen. And
even if you've never heard of the name
fluid interface, this is probably a
pattern that you've seen before. If you
use pandas for example, uh it uses the
fluent interface on data frames or in
OMS like SQL alchemy, you use it to
construct SQL queries. And finally,
pipeline tools are also a really good
candidate for fluid interfaces. And
these APIs, they feel comfortable
because they match how we think about
transformations. And that's why I picked
animation as a domain to show you how
this pattern actually works. So the way
I set this up is that this is a simple
example application that animates shapes
on a TK inter canvas. So this is my main
file. So the first step is some basic TK
setup like creating a canvas. Uh then I
create a graphics render. That's
something that I built myself. I include
in the code example. Then I define an
animation for a square.
I create a shape of that square where I
pass the animation. So animations are
stored alongside shapes. I do the same
thing for a triangle. So it has some
steps and durations. I then create the
shape of the triangle. Uh then I have
these two shapes. And then whenever I
click a button or touch a key, it will
start the animation by playing a
particular scene. So that gets the
renderer and these shapes. When I run
the script, it shows the canvas. And I
can click on this and then we have these
two animated shapes that I just created.
So like I said, I already created a
simple graphics engine and animation
system for this. The graphic engine is
very basic. It has a convos and it has a
Legendas completas disponíveis no player de vídeo
Pratique com exercícios
Gere exercícios de vocabulário, gramática e compreensão deste vídeo
Comentários (0)
Faça Login para ComentarCadastre-se para desbloquear todos os recursos
Acompanhe seu progresso, salve vocabulário e pratique com exercícios
Modo interativo
Questionário
Resposta certa:
Vídeos relacionados
What Dinosaurs, Pyramids, and the Atomic Bomb Have in Common
Why Humans Only Need To Vaccinate A Few Bats
The Weird Connection Between Antidepressants and Cancer
Build Production-Ready AI Agents in Python with Pydantic AI
Yes, It Really Does Rain More on Weekends
Late Night with Seth Meyers
Questionário
Resposta certa:
Os quizzes aparecem enquanto você assiste ao vídeo
Dica de memorização
Deste vídeo
Aprenda idiomas de grátis