The Clean Architecture in Python

  Рет қаралды 109,694

Next Day Video

Next Day Video

Күн бұрын

Brandon Rhodes
pyvideo.org/vid...
pyohio.org/sche...
Even design-conscious programmers find large applications difficult to maintain. Come learn about how the recently propounded “Clean Architecture” applies in Python, and how this high-level design pattern fits particularly well with the features of the Python language and answers questions that experienced programmers have been asking. (An update of my un-recorded talk from PyCon Ireland 2013!)

Пікірлер: 67
@FinallyAFreeUsername
@FinallyAFreeUsername 10 жыл бұрын
Brandon Rhodes has the best talks. Needs his own KZbin series!!
@LambdaJM
@LambdaJM 8 жыл бұрын
fantastic talk.. finally all comes together: clean architecture, pure functions, immutable data structures. Now I am beginning to understand because Brandon shows everything in context of real code. Enlightenment :-)
@hammockguy
@hammockguy 4 жыл бұрын
Dude, I;m so happy to watch that video.
@DanHaiduc
@DanHaiduc 4 жыл бұрын
This is the Grand Unified Theory of Software Design. I never expected that Uncle Bob's framework, which I recently discovered, tends towards the Functional Programming paradigm that I love (which encourages reducing the side-effects to an imperative shell, and having most of the code in a functional core). And this is illustrated in a tiny one-screen sized code! What a fantastic presentation!
@dukiiii
@dukiiii 4 жыл бұрын
The BEST video regarding Clean Architecture. Examples seem easy but it's heavily packed information! Lot of issues adressed here. Thank you Brandon Rhodes!
@diankunzhang907
@diankunzhang907 4 жыл бұрын
rhodesmill.org/brandon/slides/2014-07-pyohio/clean-architecture/ This is the presentation of the lecture from Brandon. Thank you, Brandon Rhodes.
@juandesant
@juandesant 10 жыл бұрын
I specially liked the idea of using generators to split procedural side-effects from iteration. #CleanArchitecture #python #FunctionalProgramming
@hammockguy
@hammockguy 4 жыл бұрын
People need to start to explain things like that. Great lecture !
@pinakadhara7650
@pinakadhara7650 8 ай бұрын
Thank you for this amazing talk. I have watched this video time and again from the beginning of my programming journey and every time I take away something new!
@davidgeorge4944
@davidgeorge4944 3 жыл бұрын
this guy is a genius - every talk is just wow
@michaelfresco2769
@michaelfresco2769 6 жыл бұрын
Thanks Brandon! This talk was absolute genius. I have to watch all your talks.
@ZeCatable
@ZeCatable 7 жыл бұрын
Thank you sooo much, Mister Rhodes!
@jamesgoebel7422
@jamesgoebel7422 7 жыл бұрын
Absolutely great talk. Provides clarity.
@drkarmakid
@drkarmakid 5 жыл бұрын
Wow! Amazing summary of some very big concepts.
@cenntraru
@cenntraru 9 жыл бұрын
I Love Brandon Rhodes!
@michaelfresco2769
@michaelfresco2769 6 жыл бұрын
He is such a good teacher.
@domingochavez14
@domingochavez14 3 жыл бұрын
Absolutely marvelous! Thanks for posting!
@freefood89
@freefood89 10 жыл бұрын
this is so helpful and relevant
@TobiasReeuwijk
@TobiasReeuwijk 10 жыл бұрын
Love python. Now teach me how!
@KhanHannan
@KhanHannan 10 жыл бұрын
Very nice talk on #python and #CleanArchitecture
@cyberhard
@cyberhard 9 жыл бұрын
Excellent talk!
@aaronwilliams6536
@aaronwilliams6536 8 жыл бұрын
brilliant talk
@NormanHarman
@NormanHarman 9 жыл бұрын
Really excellent talk.
@unperrier5998
@unperrier5998 4 жыл бұрын
What he failed to explain is that immutability allows you not have to lock your datascructures. Reember the GIL? Well with immutable objects it wouldn't be necessary and we'd achieve full parallelization when runing pure python code (we'd just have to change the garbage collector not to rely on refcount) But to me the main advantage of immutable datastructures is readbility: you're certain that when you call any thing it won't modify what you give it. Like he said, the sate in FP is entirely defined by the inputs whereas in Python the state is split and burried in many places potentially. In python that's not the case (as in C and Java and all mutable languages): when you give anything to a function, there's no guarantee that the object will be the same after the call. And those bugs are the most difficult to spot and debug.
@neniugrava
@neniugrava 4 жыл бұрын
Technically having the immutability built into the language is better, but his argument is that most of the benefits of this approach can be had by just using a functional design pattern. This is very much like following an object-oriented design pattern in plain C. A lot of this "immutability" is just an abstraction/illusion, anyway. Just put your state as a parameter (data) and voila, even a state machine can be implemented with pure functions. I'm actually interested in this clean architecture pattern for embedded C. Testing with mocks is a hard sell to people who are accustomed to doing all testing at the integration or system level. Organizing code this way just makes sense.
3 жыл бұрын
The key is to get to "immutability" by being performant. Python's list comprehensions is not a tool for that. Views and iterators are.
@borisrunakov1662
@borisrunakov1662 3 жыл бұрын
I don't get it : On 8.34 he is asking how to call find_definition() without doing IO, however I don't see how you 're calling find_definition() on Listing 3 without doing IO either. I can understand that the code on Listing 3 is far more readable, but not the decoupling issue.
@rosskraynak7288
@rosskraynak7288 3 жыл бұрын
In listings 1 and 2, the logic depends on the IO. In 3, IO depends on the logic. Coupling doesn't go away, but it's restructured. I think he mentions something about intentionally isolating coupling to just one function for listing 3.
@andrewbaxter5268
@andrewbaxter5268 3 жыл бұрын
Put the io on the top. Make it a “manager”.
@PanduPoluan
@PanduPoluan 3 жыл бұрын
What you actually want to test is that (1) URL is properly formed and (2) The logic part properly extracts the info from the returned data. The I/O is incidental. With Listings 1 & 2, you can't do that easily; you have to mock. With Listing 3, you can do (1) and (2) easily and separately. In short: Test the _wanted behavior_ rather than testing "a function with a certain name".
@hosseinyaghoubi4284
@hosseinyaghoubi4284 4 жыл бұрын
is there any implementation clean architecture in python?
@ChristopherCabanneWork
@ChristopherCabanneWork 3 жыл бұрын
7:49 "hiding is not enough". We must decouple.
@mctrjalloh6082
@mctrjalloh6082 6 жыл бұрын
Great talk LOL. And did he just explain the MVC pattern here but in another manner ?
@ColinMarquardt
@ColinMarquardt 5 жыл бұрын
Slides: rhodesmill.org/brandon/slides/2014-07-pyohio/clean-architecture/
@FlaviusAspra
@FlaviusAspra 3 жыл бұрын
build_url also introduces a bug, by not returning the new value.
@very_uniq_handle
@very_uniq_handle 8 жыл бұрын
18:47 How am I supposed to test the find_definition() function here?
@Samudbhava
@Samudbhava 8 жыл бұрын
+T Chen answer starts from 26:00
@very_uniq_handle
@very_uniq_handle 8 жыл бұрын
+Kinjal Dixit So, the answer is to use integrated tests? I don't think It is elaborated. Could you show me some code examples if possible?
@WookENTP
@WookENTP 5 жыл бұрын
Tests at the beginning of the talk are not so good either :/
@alexd7466
@alexd7466 3 жыл бұрын
at 40min. congrats, you just invented flow-based programming.
@estmeta
@estmeta 8 жыл бұрын
@6006133
@6006133 7 жыл бұрын
14:37 - this defaulting is bad practice, esp since the default is still something you pull from global scope. Just require the dependency
@gimboland
@gimboland 5 жыл бұрын
Or pay attention to the point of the talk and architect your system such that you don't need do the painful bending backwards of dependency injection at all.
@livskiy
@livskiy 9 жыл бұрын
Крутой чел.
@goshick
@goshick 6 жыл бұрын
so good in content, so bad in sound/video quality :/
@mrfchannel142
@mrfchannel142 7 жыл бұрын
I am sorry, but you are completely missing the point. Mocking Knuth for providing computationally more efficient solution without knowing whether performance was of any relevance for the task is just plain brain dead, sorry.
@valbogda5512
@valbogda5512 5 жыл бұрын
Oh, come on. He wasn't mocking Knuth, he was using him as a crutch to show that expressivity does matter. Knuth is an algorithms guy and thinking about the performance of it all is the mindset that justifies his approach to solving the problem, sure. I also find it a bit ironic that this particular toy problem is almost highly parallelize-able and as such can easily be modified to beat Knuth's solution in terms of performance. Knuth didn't believe in concurrency and for a good reason.
@romanb131
@romanb131 7 жыл бұрын
kzbin.info/www/bejne/envXlplqZpWLl68 How could you even compare 10 pages of Pascal to 6 lines of Shell code ?!?!? It's like comparing fancy car to a junk car logic, they both drive lol Run the fair test for 20 million of pages and time it.
@6006133
@6006133 7 жыл бұрын
16:30 - this argumentation is highly misleading. It creates the impression you end up with a long list of arguments in your high level code, which is simply not the case. Since composition is a thing, your have a dependency graph, and on each level of abstraction you just see that part of the graph. The one place where you see the graph is where you construct it, though for this you do not need some huge framework, some simple factory typically suffices, even for bigger apps. Edit: wow, then you go ahead to suggest patching global definitions is a better approach? I found the talk quite interesting so far, though this really is losing me. What does this argumentation even have to do with the Clean Architecture? It, or Hexagonal for that matter, say nothing about it. Uncle bob also happens to advocate dependency injection. Devs working with dynamic languages should really get over themselves. Design still applies to you. Dependency injection has nothing to do with static vs dynamic or even if your language has the concrete notion of a class. An no, I am not a Java dev. My main language is dynamic. #GrumpGrumpGrump
@TheBlehBlehBleh
@TheBlehBlehBleh 7 жыл бұрын
With composition it is still non-trivial to isolate the node in the graph that you are trying to test, so I think there is still some merit to wanting to deal with pure functions / simple data transformations
@BrandNewByxor
@BrandNewByxor 5 жыл бұрын
This is a simplified introduction to the idea of decoupling your logic from your IO. Once you understand the benefits this has, you're more equipped to understand the clean/hexagonal/onion architecture
@abhilashajha8822
@abhilashajha8822 6 жыл бұрын
And what about the efficiency? Whose code faired better? Python is very slow and inefficient in terms of memory when compared to C++...It is hardly used in any coding competitions where memory and time are constraints.
@twistedsim
@twistedsim 6 жыл бұрын
Abhilasha Jha Most operations are at C speed. You just need to use python correctly
@GlukAlex
@GlukAlex 6 жыл бұрын
Clever algorithm ( or data structure ) almost always beats a fast compiler or whatever tool you are using . Also try to switch to the appropriate Python implementation that suits you the most . Fortunately you have a big choice of what to pick .
@valbogda5512
@valbogda5512 5 жыл бұрын
@@GlukAlex Notionally your argument sounds logical and sound but in practice I personally have never seen it pan out. A dumb C++ or Go will nearly always beat any clever algorithm in Python or any other dynamic language.
@valbogda5512
@valbogda5512 5 жыл бұрын
Efficiency is not significant most of the time. If it does matter then measuring is the only way to justify an alternative approach.
@ericlenorsk2476
@ericlenorsk2476 5 жыл бұрын
Work on real world problem and you will learn that at the end, that rarely matters: machine time is cheap, but programmer's time is massively more expensive.
@WookENTP
@WookENTP 5 жыл бұрын
The "good" examples have code smell all over :/
@DanHaiduc
@DanHaiduc 4 жыл бұрын
Like what?
@6006133
@6006133 7 жыл бұрын
Interesting talk, even though there is some bullshit framing and argumentation at some points. No idea why this is called The Clean Architecture in Python, since it is not about The Clean Architecture at all.
@DanHaiduc
@DanHaiduc 4 жыл бұрын
You are quite the troll. How do the examples not reflect The Clean Architecture? Look at Uncle Bob's diagram at 1:30 - the outside routines that do I/O (web, UI, DB) are called "Plug-ins" by Uncle Bob. They call the inner Controllers and Presenters, which then call Use Case Objects / Interactors, which then call Entities, which are at the center. Since the calls may only go one way across architecture boundaries (towards the Entities in the center), the I/O plug-ins are decoupled from the core, and may change easily. Also, the core does not have to change if its callers change. The same way, Brandon shows us a shell of a program that deals with the exterior by causing side effects, but the core is pure-functional and decoupled. What's not to like?
@DanHaiduc
@DanHaiduc 4 жыл бұрын
Hell, Uncle Bob even started coding in Clojure, a functional language: blog.cleancoder.com/uncle-bob/2019/08/22/WhyClojure.html
@KhanHannan
@KhanHannan 10 жыл бұрын
Very nice talk on #python and #CleanArchitecture
@alexxTMD
@alexxTMD 9 жыл бұрын
Awesome talk!
Python's Class Development Toolkit
45:56
Next Day Video
Рет қаралды 239 М.
Classic Design Patterns: Where Are They Now - Brandon Rhodes - code::dive 2022
51:31
Всё пошло не по плану 😮
00:36
Miracle
Рет қаралды 2,8 МЛН
Não sabe esconder Comida
00:20
DUDU e CAROL
Рет қаралды 22 МЛН
Help Me Celebrate! 😍🙏
00:35
Alan Chikin Chow
Рет қаралды 87 МЛН
VAMPIRE DESTROYED GIRL???? 😱
00:56
INO
Рет қаралды 8 МЛН
Transforming Code into Beautiful, Idiomatic Python
48:51
Next Day Video
Рет қаралды 1 МЛН
Uncle Bob’s SOLID Principles Made Easy 🍀 - In Python!
19:09
ArjanCodes
Рет қаралды 298 М.
Design Patterns in Python by Peter Ullrich
27:31
PyCon Sweden
Рет қаралды 133 М.
threading vs multiprocessing in python
22:31
Dave's Space
Рет қаралды 586 М.
Raymond Hettinger - Super considered super! - PyCon 2015
46:52
PyCon 2015
Рет қаралды 123 М.
When Booleans Are Not Enough... State Machines?
21:50
Next Day Video
Рет қаралды 25 М.
"Clean" Code, Horrible Performance
22:41
Molly Rocket
Рет қаралды 897 М.
Всё пошло не по плану 😮
00:36
Miracle
Рет қаралды 2,8 МЛН