Bestand wählen
Merken

Why you don't need design patterns in Python?

Zitierlink des Filmsegments
Embed Code

Automatisierte Medienanalyse

Beta
Erkannte Entitäten
Sprachtranskript
hi everyone and it I want to tell you a little story of course is not about myself it will be a story of a Python developer on not so long ago there was a Python developer and all he's carrier that lasted already has several years he righted a few thousands of lines of code
and he was uh in love with his favorite framework and she became so proficient in the tools he used daily that he even became a mentor for his teammates and and he praised all the tools he used because they were able to solve all these problems he deal dealt with in daily work and it's after all he was quite good and this really boosted his self-confidence and this isn't surprising on of course knowing a framework was not his only assets and to practice writing this rigorously and like TDD whenever it was applicable she was doing his best to make sure that the cold here Itten was not only correct and well tested but also readable and easy to understand by any other teammates and every nite before falling asleep he was reading is enough by them to write a cold to that would never violate any of its versus but in other words he was doing his best and he was expecting the other teammates did say and the same thing and
thank them the he was assigned to a new projects that changed everything I think well despite the fact that our hero was proficient with his tools and you know them inside out but they were not so well suited for the project he was assigned to because how valuable this experience maybe when the weight of the project there it's very business part is far outside this framework and its it can no longer be be solved by this framework essentially so he started to create his own classes his own modules and fuel also form abstractions and he felt that they were clumsy and they do not be as good as the wealth fault components of the framework used daily so you see these frameworks are sets of powerful building blocks the if you use them for a problems that they were created for your fine and you shouldn't bother any other options not the problem arises when there is a there is an issue that they simply don't fit and you try to winger no effectively a screwdriver think using a hammer and for example what would be the gender would for if you did that needs to use its models at all so what's left I don't know the views that the inflated the since then and the routine and that's all any other uh reach capabilities of gender on its use so why would you do that and the problem wiII our developer developer was stock was that he lacked the thinking outside the box beyond his manual and luckily he noted this problem early enough that 2 came up with an idea of asking someone may be more experienced may be more interested in software engineering and he had a friend a Java developer and he asked her for device what should I do if my tools are not good enough for me for this particular problem and he said she said take a look at these and important they are meant to be reusable concepts to produce elegant codes and nice solutions and are based on many years of experience with people that are much smarter than we are the so he wrote to the design patterns to bed 24 years old book and try to implement some of those using examples there however that even bother us are not like libraries or tools that he doubts so far so they are not too easy to use easy to use solutions that you just importing your code and start using they are more likely sites like drafts for solutions if you have this particular problem and they say it's like you have ontology and then you can use them but they are just just all clients they are not ready to use the
maybe you're thinking what are the good for it's good for you if they are written in some old books uh bison C + + guys where there's a funny thought about IT namely our brand has some kind of an easier and the 2004 2 years or so uh we forgot about old concepts all that yes and then you discover them again and it's like 0 my god this is so amazing who for example let's take an N IO and its coroutines yeah cool idea but they even look at except it's nothing new because the this is a almost 50 years old now and it has been around in seventies on other we just now getting it to the Python and another thing to consider when you you think about others is that the of the applicable today and well the book was written 24 years ago which there were different tools in charge instead of light and so by then simplifies a lot of things and this is what this talk will be about more about the tools and less about the design patterns because you will see that some of them are also present in by them but they are the invisible object can differentiate 1 from another because they're sold so simple but but the
main benefit from design patterns or at least the learning their application in by and in some limited way but before you do extend your tool box as a programmer and as a result become not only at the Python programmer but at the programmer in general OK so let's start with the 1st part of and there is
sometimes considered on the part of a single atoms this is a situation when you have a class and in any moment of the lifetime of the program you need only 1 instance of a given class only 1 object in a sense there may be several reasons for that maybe all the objects will be the same so why should I bother my create new things every time and maybe there is a business the motivation behind is that there would be no more than 1 object or maybe creating object costs a lot states so the fine and you just want to avoid it to get some speed up and for such cases we can use a single atom pattern and beside uniqueness there's also 1 requirement namely you need to have a clear way to get an instance and know that this is a single a sort of go blink a little you may find following solution and uh this uses the magic down there and you me don't uh that this using during creation and so this solution the comes down to using at class level at tributes that will story or only instance and eventually returned it's whenever it's the necessary in using this is
quite simple you just read as usual as you would like to create the other objects and of course you can use this implementation in your programs but please don't call yourself by can users anymore because In all there is 1 with use flaw I can see this and to in this is that it's not clear for you a client of this class if he creates a single at on if it's really and unique object because we use and user while syntax for creating a new object so you might get surprised if you that you really used getting is the same thing over and over again a slightly better approach is to use a class class to his disadvantage this is more the and it also does not block you from
creating unusual instance but well you could do the same clearing that class-level instances of viable but we don't want to go that far on however since we have and it's 2017 there is a simpler way and actually has been around in by them for several years I guess or more and this is you can just chewy
at an instance and in your module and later in your coat just important that object instead of class and this will achieve a try the same thing I yeah so I told you that some patterns are present in Python and this is true about single from that this is not an obvious fact but there was a creature in Python that you use it countless times and actually meets the requirements for cigarette on and this creature is called a module so let's consider this and after importing amount to at least once there is exactly 1 instance of it insist molecules dict object you can very easy and very clearly get an instance of a module using import statement and if you need you can re-create the instance using free so this actually ask something to this pattern so the conclusion about seeing that on his that using most simplest solutions there would be a way out instead of creating some classic classes and if I'm speaking about modules there was another part and that the very gets simplified thanks to them and this is for state on let's say we have a project that is consisting of many distinct components and we can quite easily assigned them to some groups responsible for certain functionalities for example we have the group with users that is responsible for getting user authentication and so on we have a group responsible for blog posts creation retrieving and other staff and we have some things related to getting advertisements based on the continent and that of connection between these classes might look like this and I don't have to tell you that this is a terrible idea because you get the tight coupling be tween these classes and any time you want to try to change something in a class that has many connections with others then there is a probability then you will break things this also had very complicated to get the desired functionality because you may not know what's what's behind this the subsystem now and this is what the fascinates this is an issue what Fossett to address and you introduce in original other and an extra class that will be your interface to the entire submodule you are no longer allowed to use discusses directly under no circumstances all request that go to these sub system must go through their phosphate the and of course you can go along with default implementation like using the class solver and creating other class not perhaps this is over engineering on the engineers solution by if all you need is just a top-level package that will do get a bunch of functions inside I had just look how clear it looks comfort to the idea of models but the only thing you use outside this package is imports from this init file everything that's in this sub packages is hidden you may not use it outside and this is how you hide the complexity of probably very complicated advertisements subsystem so
this button is it doesn't sound like very original or something but it is it helps you organize your code and there is very little need for class and by the way if you can do is the same in the plane was you another pattern is so I comment at common is an object-oriented Kolbeck and the original implementation assume that it will be helpful for example doing the graphical user interfaces because you see when you will want for example have on the reaction clicking an item the menu and you don't want to pass to many information today graphical interface with the same reasons as the phosphate so you don't want to have too many connections in your system and the condo was meant to pass and configure during runtime your things on it's interface to assume that you have only 1 adult which is executed and the thing that uses comment would just run executes when it needs to uh of course you buy them is overengineered because we can use just a plain function to achieve the same thing and since functions our 1st clusters in sync byte on which means that we can create a by function during runtime we can pass it to another function and we can return it then there is no need to create a class but I reminded this word it's quite different times where the basic building block was class so you have clusters everywhere and if
everything that's your Collins is doing is just the calling other functions of another object so if some parameters then maybe you can use the standard libraries do these uh which is found close partial and this 1 because it just prepare eco-label object and that will be accessible later to to use
and and by the conclusion we do rarely stuff like this in Python which means making graphical user interfaces so this is the bottom of very little usage in by the right now and another part the is a visitor and this this is actually adopted in Python and it's easy to use but for a certain amount of problems so let's say you have a complicated nested structure that we need to traverse and for each such note we would like to execute our own logic and this is an example of abstract syntax trees and this is your called represented a substructure and this is really use of violent and other a link there's which get your coat turn them into such structure and then for each node in the desert distinct logic for example at the root element is always a module and this is represent the whole cold but the 1st thing you have this import statement and this is the a represented as distinct note yet and violent has different checkers different strategies and different guidelines for any of these elements so is much more clear to just separated and this is what visitors about is it's about mean getting know what is this node and separating dispersing from others I if we had a static typing just like in job you know we could just implemented like this we would have an metals visit and they arguments what's the point us type is this implementation about can we get a clear distinction about what what to do next on yeah of course we don't have such things in Python and the 1st nite implementation will ammounts to using you had big if other statements which I have to out to you that this is ugly and this is gross quickly and it's slow on luckily we can use the dynamic nature of Python and create functions that we will call them later us uh as usual and methods and after we assemble and that its name we can just get it from our object and call just use will function and this will work fine to but having by these freedom I'm having at least and
3 . 4 we have this single dispatch functionality uh which so this is the closest to what we can get comparing to job well so it's it directing implementations Bher argument by uh its usage is quite complicated get it step by step so 1st of all we implement the single dispatch and we get at the full implementation of course is the default if we did not have a specialized version for this time will be once the rise exception that this no is for this thing and yeah then we
will start implementing our all specialized in implementations using and take a look at this uh decorator because we don't use single dispatch we used the visit decorator that reduce the and this is the greater gets the only argument which is a type a type of a 1st argument of this function and to whenever you call a visit with a type of uh like in this place then this reduced search function will be called and yeah unlikely this has a minor and major disadvantage and namely cannot be uses in classes because there is always the 1st argument is a class and it would have to be re-implemented by hand to the In such cases
yeah OK and the last design pattern is decorated and decorate the uh part and it's not so were truth where might think of when you few reward decorator it's not that decorator function by on and it will become more clear when I was showing examples and now uh some requirement it can extend the behavior of a given object during the run time and it can be used multiple times with different decorator patterns and no order is not important they will shoot work in the same way or at least have a meaning desired so a decorator uh when you decorate an object you have to get the same thing but which means as the user of class you shouldn't be aware that this uses of decorate Soviet any there is any at tribute on the object than it should be also presented a decorator in and for example if we have such class then has 2 methods uh get text and get number and we would have to we would like to decorate 1 of them
and by adding some bolts HTML mark-up then we have also to Ray implemented the other function which is also which is of course redundant and this is just writing a code for for are called for making functionalities uh
but what happens actually if we request and activity in the class and we use the doctor on fundamentals on classes and it's fields are just attributes and this is a logic we can plug in so 1st at all by calls a special Dundar that attribute Matilde and this looks for properties in the object itself if it wasn't found then down the get after that I know wonderful meaning is called and by the full thing just around raises an exception that this property was not found and uh looking for properties is by the dictionaries that are per class and per object level and carry the the the same properties present on class and an object than an object goes around has priority so to get the quite a simplified we can just implement the method we need and for any other thing we just return their stuff from the original object and this removed frees you from need to implement all this unnecessary stuff on can we do to get the full compatibility would also have to implement the other metals but that's a different story against so to sum
up the by is a very flexible tool much different from what we have no almost there 25 years ago and many of these things you might finger either redundant or extra arts adjust for it uh but in by and there is some there are multiple places 1 we can plug in our all logic and customized of nearly every aspect of creation of objects to run time however the very important quick question arises is magic they showed you do in some limited way is worth the effort should we use really the magic well it depends on the readability uh something new in there are cases when using this stuff will spare some effort and any other things that we just created no I see a fancy by the feature let's use it it's a a probably wrong idea and and therefore if things from me that I want you to take from this presentation to become a better programmer in general so 1st of all we get to know with your tools and you know them well and this is like a vocabulary like having a name for everything you see the the 2nd way is to get inspiration from other languages and communities because there is not much interesting fight on the community in general in software engineering there's not much of dogs on this topic subject and conferences there's not much books and the last thing I haven't spoken area is to know a business domain of a project because if you know your tools you have a vocabulary if you get inspiration from the languages you know there's sort of engineering staff you you have a grammar but the real value Ariel meaning what you do is in this point so even if you write it beautiful called in the know all the tricks and you still won't be able to solve the problems of your business of a company work for and this is all for nothing and this is just a sum-up and my name supersymmetry sky I work for as takes next the biggest suffer and by them house In Europe I blog on the red currants collected uptake and that's all folks
fusion we have time for about 2 to 3 week mission so wizard which you wish you all no everyone's on we have there's 1 so it's less of a question but once the more common of you because of in my
opinion actually I come from which our development of community and design that is a really important also realize that really important implies that some of the sort that the new mentions sorry I would give a choice but my of my question for you comment is a you said that design patterns are not really important pies but of the trees we patterns and the Gang of Four book on I'm sorry like other actually really not important or other important to implement sometimes or just forget about them so what's your opinion on the design patterns and importance of high and you really don't want to sorry OK so the new title was like the design patterns on unimportant implies but honestly but is it important to learn these and implement them or I'm sorry I can't really make my question OK so your questions about is dwarf to learn and operates so essentially uh I think that this is a tricky part for this experience people here because they they learning unnecessary stuff and then there is a gap in our community and this is on an established set of who well fault the best practices I think this should be prepared by someone may be and this should be well uh propagated throughout the community so they do not have to learn from other going from 23 years of books in because they are not relevant today so we need just a new set and counter part for pi OK so anyone has the question politicians note well when it's time for landlords and and
Intel
Software
Freier Ladungsträger
Facebook
Softwareentwickler
Gerade
Code
Web Site
Gewicht <Mathematik>
Quader
Klasse <Mathematik>
Applet
Gebäude <Mathematik>
Framework <Informatik>
Code
Computeranimation
Client
Informationsmodellierung
Umwandlungsenthalpie
Programmbibliothek
Zusammenhängender Graph
Softwareentwickler
Leistung <Physik>
Softwareentwickler
Sichtenkonzept
Ontologie <Wissensverarbeitung>
Abstraktionsebene
Gebäude <Mathematik>
Entwurfsmuster
p-Block
Modul
Menge
Konfiguration <Informatik>
Spannweite <Stochastik>
Menge
Geschlecht <Mathematik>
Mereologie
Projektive Ebene
Wort <Informatik>
Entwurfsmuster
p-Block
Software Engineering
Fitnessfunktion
Resultante
Objekt <Kategorie>
Programmiergerät
Subtraktion
Quader
Güte der Anpassung
Grundsätze ordnungsmäßiger Datenverarbeitung
Koroutine
Entwurfsmuster
Computeranimation
Momentenproblem
Klasse <Mathematik>
Einfache Genauigkeit
Systemaufruf
Implementierung
Ordinalzahl
Computeranimation
Übergang
Objekt <Kategorie>
Client
Mustersprache
Mereologie
Optimierung
Instantiierung
Information Retrieval
Web log
Stab
Klasse <Mathematik>
Gruppenkeim
Implementierung
Komplex <Algebra>
Computeranimation
Informationsmodellierung
Modul <Datentyp>
Mustersprache
Endogene Variable
Zusammenhängender Graph
Default
Modul
Demo <Programm>
Schnittstelle
Einfach zusammenhängender Raum
Lineares Funktional
Befehl <Informatik>
Klassische Physik
Physikalisches System
Objektklasse
Elektronische Publikation
Modul
Web log
Objekt <Kategorie>
Bimodul
Authentifikation
Projektive Ebene
Ext-Funktor
Instantiierung
Aggregatzustand
Ebene
Objekt <Kategorie>
Klasse <Mathematik>
Synchronisierung
Code
Computeranimation
Metropolitan area network
Standardabweichung
Code
Mustersprache
Programmbibliothek
Cluster <Rechnernetz>
Einfach zusammenhängender Raum
Lineares Funktional
Parametersystem
sinc-Funktion
Gebäude <Mathematik>
Rechenzeit
Physikalisches System
p-Block
Objektklasse
Objekt <Kategorie>
Funktion <Mathematik>
COM
Client
Wort <Informatik>
Benutzerführung
Information
Bitrate
Ext-Funktor
Subtraktion
Abstrakter Syntaxbaum
Punkt
Natürliche Zahl
Versionsverwaltung
Parser
Implementierung
Element <Mathematik>
Mathematische Logik
Computeranimation
Knotenmenge
Prozess <Informatik>
Minimum
Abstrakter Syntaxbaum
Datentyp
Wurzel <Mathematik>
Datenstruktur
Default
Implementierung
Demo <Programm>
Parametersystem
Lineares Funktional
Befehl <Informatik>
Diskretes System
Applet
Ausnahmebehandlung
Binder <Informatik>
Modul
Mustersprache
Datenstruktur
Rechter Winkel
Mereologie
Strategisches Spiel
Ext-Funktor
Lineares Funktional
Parametersystem
Subtraktion
Datentyp
Rechenzeit
Klasse <Mathematik>
Entwurfsmuster
Zahlenbereich
Implementierung
Rechenzeit
Ordnungsreduktion
Computeranimation
Arithmetisches Mittel
Objekt <Kategorie>
Mustersprache
Multiplikation
Typentheorie
Datentyp
Mereologie
Mustersprache
Ordnung <Mathematik>
Ext-Funktor
Gewichtete Summe
Ausnahmebehandlung
Relationentheorie
Beschreibungssprache
Klasse <Mathematik>
Mathematische Logik
Computeranimation
Übergang
Homepage
Zustand
Implementierung
Attributierte Grammatik
Fundamentalsatz der Algebra
Lineares Funktional
Kategorie <Mathematik>
Ausnahmebehandlung
Systemaufruf
Data Dictionary
Objekt <Kategorie>
Arithmetisches Mittel
Datenfeld
Loop
Zahlenbereich
Attributierte Grammatik
Räumliche Anordnung
Ext-Funktor
Sichtbarkeitsverfahren
Domain <Netzwerk>
Punkt
Stab
Relationentheorie
Formale Sprache
Besprechung/Interview
Formale Grammatik
Supersymmetrie
Rechenzeit
Twitter <Softwareplattform>
Kombinatorische Gruppentheorie
Mathematische Logik
Quick-Sort
Computeranimation
Web log
Objekt <Kategorie>
Domain-Name
Flächeninhalt
Reelle Zahl
Reelle Zahl
Software Engineering
Netzwerktopologie
Menge
Mustersprache
Mereologie
Entwurfsmuster
Softwareentwickler
Quick-Sort
Auswahlaxiom

Metadaten

Formale Metadaten

Titel Why you don't need design patterns in Python?
Serientitel EuroPython 2017
Autor Buczyński, Sebastian
Lizenz CC-Namensnennung - keine kommerzielle Nutzung - Weitergabe unter gleichen Bedingungen 3.0 Unported:
Sie dürfen das Werk bzw. den Inhalt zu jedem legalen und nicht-kommerziellen Zweck nutzen, verändern und in unveränderter oder veränderter Form vervielfältigen, verbreiten und öffentlich zugänglich machen, sofern Sie den Namen des Autors/Rechteinhabers in der von ihm festgelegten Weise nennen und das Werk bzw. diesen Inhalt auch in veränderter Form nur unter den Bedingungen dieser Lizenz weitergeben
DOI 10.5446/33797
Herausgeber EuroPython
Erscheinungsjahr 2017
Sprache Englisch

Inhaltliche Metadaten

Fachgebiet Informatik
Abstract Why you don't need design patterns in Python? [EuroPython 2017 - Talk - 2017-07-11 - PyCharm Room] [Rimini, Italy] Exactly 23 years have passed since release of one of the biggest IT classics - ""Design Patterns: Elements of Reusable Object-Oriented Software"". Contents of the book had considerable influence on dominant programming languages of those days. However, design patterns were not glorified by everyone. Voices of rational critic appeared, pointing out that design patterns are just ways to compensate for missing languages features by tons of clumsy code. If one implements design patterns in Python by the book, they will get code that looks awkward, at best. This talk is to present Python's features that either simplifies or eliminates need for implementing design patterns. Even if you don't know what design patterns are - don't worry. You still may see some new interesting Python's features and their usage

Ähnliche Filme

Loading...
Feedback