Why the Plugin Architecture Gives You CRAZY Flexibility

Поделиться
HTML-код
  • Опубликовано: 29 окт 2024

Комментарии • 191

  • @ArjanCodes
    @ArjanCodes  3 года назад +15

    ✅ Get the FREE Software Architecture Checklist, a guide for building robust, scalable software systems: arjan.codes/checklist.

  • @enriquerodriguez9723
    @enriquerodriguez9723 3 года назад +135

    You can make it even more flexible by passing the factory to the 'initialize' method in the plugin from the loader. That way you don't have to import the factory. If the factory changes, you don't have to touch the plugin code at all.

    • @ArjanCodes
      @ArjanCodes  3 года назад +28

      Great suggestion!

    • @Thristle
      @Thristle 3 года назад +11

      Exactly! plugins should just implement a required interface (preferably also announce what version of the main program they are expecting) but not import anything

    • @enriquerodriguez9723
      @enriquerodriguez9723 3 года назад +11

      @@ArjanCodes thanks! Perhaps this video can be a good segway into the topic of clean architecture, by Robert C. Martin, since it uses the idea of building software into pluggable components. You could show how one could implement this architecture in python. Great stuff, keep it up!

    • @pokemusicfan
      @pokemusicfan 3 года назад

      I mean you always have to worry about the register function of the factory still being defined but good idea

    • @Zeedox
      @Zeedox 3 года назад +2

      Wouldn’t you lose type checking in that case? The Factory function call is the place where the data class is checked for compatibility with the protocol.

  • @thomasburette9129
    @thomasburette9129 3 года назад +8

    This is an application of the Open/Closed Principle of SOLID.
    Quoting Uncle Bob:
    “Open for extension. : This means that the behavior of the module can be extended.
    Closed for modification.: Extending the behavior of a module does not result in changes to the source or binary code of the module.”

  • @deez_gainz
    @deez_gainz 3 года назад +43

    Awesome! So far you have been choosing examples that fit well to the object oriented programming paradigm, where you got clear objects like Characters or Customers or VideoExporters. Im wondering if you can discuss and come with a counter example where you would rather not use classes but just functions separated to different files / namespaces. Thanks for great work Arjan!

    • @ArjanCodes
      @ArjanCodes  3 года назад +6

      Great suggestion, thanks!

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz 3 года назад +2

      This should still more-or-less work in languages with no-inheritance-OOP, like Go and Rust (all that I know).

  • @susmitvengurlekar
    @susmitvengurlekar 3 года назад +10

    For complex / long typing hints, you can make custom typing definitions and use them.

  • @SkielCast
    @SkielCast Год назад +1

    Great video as always!
    Some suggestions:
    1. To avoid the type ignore (15:40) I would make the PluginInterface a Protocol decorated with runtime_checkable.
    2. To avoid using global objects, instead of defining the initialize as taking no arguments, I would pass an "App" object exopsing a public API of what can be changed. This may have been too much for this example but it seems like running something without parameters encourages people to use a lot of global vars and polution of the namespace
    3. A more strict and parametrizable way of defining callables (5:25) is using ParamSpec or Protocols with __call__. Maybe instead of using plain dictionaries which are hard to type strictly we could have defined another Protocol called GameCharacterConfig and make GameCharacter have that as an example. That would allow dependency injection of configuration while still keeping everything type safe. When adding a new character, one should not only define a CustomCharacter class but also a CustomCharacterConfig that implements the GameConfig protocol. That way the type of that callable would be Callable[[GameCharacterConfig], GameCharacter]. If more strict typing is needed we could use a TypeVar but I believe it is not needed here.

  • @aliabedi6163
    @aliabedi6163 3 года назад +13

    I really love how you teach an architecture!

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Thank you, glad you like it!

  • @AlphaWatt
    @AlphaWatt 3 года назад +3

    You are the man Arjan! As an intermediate hobbyist developer, your series are all super super helpful. This plugin architecture layout is beautiful.

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Thanks a ton! Glad you're enjoying the content!

  • @theRECONN
    @theRECONN 3 года назад +16

    Honestly, amazing videos! I've only seen 3 videos of yours so far and I was not expecting such great, methodical explanations followed by actual clean, useful code and advice. Moreover, spoken by a person with, what looks to be, an arsenal of experience and insight.
    In the RUclips space, there is plenty of bad coding channels, which for me as a software developer is so frustrating. THIS channel is definitely one of the best I've stumbled upon.
    Keep up the interesting stuff!

  • @JaxxedNesmith
    @JaxxedNesmith 3 года назад +9

    9:30 don't mix broad exception catching for "is my factory function name in the dict" with exception catching from running the factory function itself. If the factory throws a KeyError it will get misdiagnosed as a missing character type.

    • @aflous
      @aflous Год назад

      Exactly! easily fixed by moving the creation and return outside the try/except block

  • @NGrimthrie
    @NGrimthrie 3 года назад +2

    Hi Arjan, really appreciate the videos. A suggestion for a video topic is the motivation behind choosing good architecture and design patterns. I've been reading the Pragmatic Programmer and they start with a section about how all of this is motivated by a desire to increase the "ease to change" code. I see that you understand this and as you often reach the point where you say, "ah now it's very easy to change x without changing y" but your viewers may not explicitly understand this. Thanks again!

  • @alessandroferrari2166
    @alessandroferrari2166 3 года назад +5

    This is neat, indeed! Thank you for providing us with new tools and mental frameworks to expand our software development skills!

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Thanks Alessandro, glad you liked it!

  • @cryp0g00n4
    @cryp0g00n4 2 года назад

    The way you organize code is magical.

    • @ArjanCodes
      @ArjanCodes  2 года назад +1

      Thanks, glad you like the video.

    • @cryp0g00n4
      @cryp0g00n4 2 года назад

      @@ArjanCodes yea itz solid

  • @resatcanerbas3541
    @resatcanerbas3541 3 года назад +1

    Many classes out there but very few of them touch the architecture, and very few of those explain it that great. Great job! Thanks for the euphoria per video!

  • @FabriceNormandin95
    @FabriceNormandin95 3 года назад +4

    Hey! I've got another suggestion: Have you covered the singledispatch function from the functools package in one of your videos before? If not, I'd really recommend it! It really goes hand in hand with the plugin architecture too, since it lets you define generic functions and then the plugins can register their own versions of that function to handle the new classes they create (eg new characters in your example). I personally think it could potentially be a great topic for a future video, in case you're interested!

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Hi Fabrice, thanks for the suggestion, I'll take a look!

  • @LucasMartins-op7oq
    @LucasMartins-op7oq 8 месяцев назад

    plugin architecture is very useful to develop modular and adaptative systems.
    your overview is clarifying and helped to recap it.
    thanks for the video!

    • @ArjanCodes
      @ArjanCodes  8 месяцев назад +1

      Glad you found my video to be insightful! Thank you for the comment, Lucas :)

  • @ACAndersen
    @ACAndersen Год назад

    About 15:40 - To force the IDE Type Checker to accept your typing, you can use `from typing import cast`.

  • @primeix
    @primeix Год назад

    I like the background Picture that says Toss a coin to your code!

  • @sagiziv927
    @sagiziv927 3 года назад +2

    Seems interesting.
    In my code, I recently needed to do the same thing (adding variations without changing the existing code).
    I solved it using inheritance and reflection. I searched for all the subclasses of the base class and in every class I have the name as a static variable. Obviously the main issue is that it requires that all subclasses would be in the same module so they are loaded.
    I might try to use a factory like you did, which seems much cleaner because every subclasses would be in its own module with its own imports.

  • @k98killer
    @k98killer 2 года назад

    I'm implementing something currently that uses a modified version of this to load a plugin from a file path after checking its content hash to make sure it has been validated/authorized. The idea is to make sure that only signed plugin code is run to avoid nefarious code from hijacking the application. (The plugins are actually contracts that specify correspondent time banking relationships, so there is an additional incentive for the system to be hijacked.)

  • @devkhire2989
    @devkhire2989 2 года назад +1

    This was good on Plugin dynamic loading and creating it. You explain it in very simple language. I was wondering whether you have any similar video on building python framework. Particularly on builds and distribution.

  • @hamzahakoun1072
    @hamzahakoun1072 2 года назад

    this channel is a real treasure

  • @XRay777
    @XRay777 3 года назад +5

    Really cool demonstration of how to build plugins in python.
    I am, however, not a fan of the use of Protocols here, since it is easy to miss adding the initialize method. It is also not explicit that the registration in the factory should occur in there.
    I prefer the more explicit solution of having a base class (say RegisteredCharacter) that implements __init_subclass__ to automatically register its derived types in the factory ;)

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Great solution! I agree that’s a really nice way to implement autoregistration.

    • @virtualraider
      @virtualraider 3 года назад

      I also have to agree that protocol use is actually making the code more esoteric.
      I really enjoy your earlier videos when you can see everything tied in nicely in the IDE. But here it doesn't help you auto discover these relationships and requirements.
      Protocols seen like a lightweight solution that might help when execution speed is of the essence, but it seems like too much of a tradeoff against ease of development. Am I overreacting?

  • @joaopedrorocha5693
    @joaopedrorocha5693 Год назад

    Cool! I think i've started implementing a project with an architecture that reminds this one ... but without the importlib mechanism. Thanks!

  • @djl3009
    @djl3009 3 года назад

    Thanks for another great video. I liked the creative use of the PluginInterface class to provide useful static type info for a dynamically loaded module (plugin).

  • @dedebenui
    @dedebenui 3 года назад

    thank you so much for your lessons on decoupling and composition, it helped me a lot in my projects and made refactoring/improving components of my application much easier !

    • @ArjanCodes
      @ArjanCodes  3 года назад

      Great to hear! I'm happy the videos are helpful.

  • @pthube
    @pthube Год назад

    Thank you very much for teaching design patterns and architecture, I think these are critical components to be a good software engineer..

  • @Medan1993
    @Medan1993 3 года назад +1

    In english translation of Witcher series Jaskier's name has been translated to Dandelion for easier pronunciation and easier reference.
    Anyway beside thanks for sharing this stuff, will certainly have that in mind when I add new projects in the future.

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      I probably still won’t be able to pronounce that correctly, haha.

    • @Alche_mist
      @Alche_mist 3 года назад

      In Czech, the bard is Marigold. Which obviously clashes with Triss's second name when comparing to English - it's Triss Ranuncul in Czech.
      Note: Czech is very close to Polish and our translator was amazing - Sapkowski himself once (in the far history before the Witcher games and series) stated that only Czech and Polish readers read what he wrote.

  • @vorniy
    @vorniy 3 года назад +3

    Instead of type: ignore, you can use the cast function from the typing module

  • @Ziggity
    @Ziggity 3 года назад +1

    "Toss a plugin to your code"
    👍🏼👍🏼👍🏼

  • @Tobbzn
    @Tobbzn 3 года назад +12

    This seems like it would cause conflicts if you have multiple modders wanting to edit the same json file. Avoiding such conflicts would probably need a dedicated directory from which you load every json file rather than just a specific one.

    • @k98killer
      @k98killer 3 года назад +1

      Maybe. For Skyrim, there are tools that each compiles a master list of plugins to avoid conflicts, and these use metadata to figure out the load order; if one plugin depends upon another, it cannot be loaded first. This potentially violates the SOLID principle, but at the same time being unable to reuse plugin code violates DRY. Every architecture will have different trade-offs.

  • @ShlomoGottlieb
    @ShlomoGottlieb 3 года назад

    Great video!
    I'd suggest adding those mini code project to a github account for everyone to enjoy.

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Thanks, and good point! I normally put the link to the repository in the video description, but forgot to do it here. It's been added now.

  • @ajflorido
    @ajflorido 2 года назад

    Very nice video Arjan!
    Also just looking for a more pythonic approach, example.py is doing a lot of things (declaring and registering classes) and since this is a plugin approach a "plugin.base" file with all those initial classes (Wizard,Witcher and Sorcerer) from line 12 to 36 could be added and then add it into the json file plugin list as you did with the "plugin.bard".
    All the initial registration from lines 43-45 are no longer needed as well as the lines from 12-36 as they're going to be defined in that "new plugin.base" file, letting the loader (line 52) to handle it
    Really good job, thanks a lot for your work

  • @Phate777
    @Phate777 3 года назад +1

    Hey Arjan,
    than you for the Content. I'm a big fan and I'm really learning new stuff.
    Can you make a Video about Project Structure? Like how to name things, what files belong in what folder? Where to put interfaces, dataclasses etc.?
    I have troubles structuring bigger projects. They start small but then once they are too big they get really messy.

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      Glad you like the content and thanks for the suggestion, Antonio - noted!

  • @andrzejdubiel3263
    @andrzejdubiel3263 2 года назад

    Toss a plugin to your code! Nice one!

  • @nandoaires
    @nandoaires 3 года назад +2

    Arjan, do you have any intention of developing some videos on TypeScript (or other languages)? It would be nice to see your approach on those.
    (The channel is great anyway, congrats and thanks :) )

  • @johanboone2696
    @johanboone2696 2 года назад

    Awesome content, Arjan! Keep them coming!

    • @ArjanCodes
      @ArjanCodes  2 года назад

      Thank you Johan, glad you like the content!

  • @k98killer
    @k98killer 3 года назад

    Very cool. I'll have to experiment with this design pattern.

  • @jordvcs1814
    @jordvcs1814 2 года назад

    This opened my mind. Thanks!

  • @jakefischer8281
    @jakefischer8281 Год назад

    Arjan! YOU THE MAN!

    • @ArjanCodes
      @ArjanCodes  Год назад

      Thank you Jake, glad you liked the video!

  • @nandoflorestan
    @nandoflorestan Год назад

    At 9:17, I see an opportunity to improve the code. The return statement (and calling the character constructor) should definitely be outside of the try block. Always remember to check for this mistake: do not over-catch exceptions.

  • @fierce1340
    @fierce1340 2 года назад

    Awesome video arjan!

    • @ArjanCodes
      @ArjanCodes  2 года назад

      Thank you, Scott, glad you enjoyed it!

  • @csavino
    @csavino 2 года назад

    Awesome videos Arjan ! Nice channel !

    • @ArjanCodes
      @ArjanCodes  2 года назад

      Thanks so much, glad the content is helpful!

  • @josecarlosmendozasosa3109
    @josecarlosmendozasosa3109 2 года назад

    If I could I'll give it ten likes. Mindblowing. Excellent explanation. Thanks.

    • @ArjanCodes
      @ArjanCodes  2 года назад

      Thanks Jose, happy you’re enjoying the content!

  • @luersuve
    @luersuve 3 года назад

    I wrote a mock for an embedded application using python. Since I wanted to implement a way to change the behavior like you showed in this video I also used the importlib module. However, I required a specific name for the files and functions. It is horrible! I will try the plugin architecture. Thanks for the great content!

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      You're welcome, glad you liked it!

  • @ИванНикитин-ч7б
    @ИванНикитин-ч7б 3 года назад

    In fact this is a cross cutting concern thing. Because you can make plugins for any layer not only for domain as in this video.

  • @BrianRussell
    @BrianRussell 11 месяцев назад

    Thanks - great video! One qustion: I've incorporated this into my own project which I'm trying to package with pyinstaller. However the packaged program can't find the plugins folder when import_module() is called, even though I've added it through --hidden-import. Any idea?

  • @munotpratik2009
    @munotpratik2009 3 года назад

    Awesome ! This was really helpful ! I was trying to do something similar for my project

    • @ArjanCodes
      @ArjanCodes  3 года назад

      Thanks, glad you liked it!

  • @Empristis47
    @Empristis47 2 года назад +1

    Thanks for the content. As a developer coming from a Java background, why exactly do we need copy here? Is it just because we want to pop the type and for some reason keep the original dict?

  • @raen714
    @raen714 3 года назад +1

    Do you have any information anywhere about how you set up your IDE? It looks like you're using Visual Studio Code, but I'd love to know what, if any, plugins you have for it in these videos

  • @TheWolverine1984
    @TheWolverine1984 2 года назад

    Could you please point me out to an explanation of what 'Protocol' is and where it's defined? Is it just what interface means in C++ or Java?

  • @manishankarsingh7748
    @manishankarsingh7748 3 года назад +1

    Can we use namespace packaging to create pluggable architecture?

  • @RemotHuman
    @RemotHuman 2 года назад

    This was very helpful, thank you

  • @cheatoffchannel6320
    @cheatoffchannel6320 2 года назад +1

    Nice work thanks!

    • @ArjanCodes
      @ArjanCodes  2 года назад +1

      Thanks happy you’re enjoying the content!

  • @raccoonteachesyou
    @raccoonteachesyou 3 года назад

    That's very neat content. Thank you Arjan.

  • @ravenecho2410
    @ravenecho2410 3 года назад

    definitely had to review this one a bit, but really 😎

  • @zacharythatcher7328
    @zacharythatcher7328 3 года назад

    I’ve been waiting for this one!
    I assume that there should also be some test code that generates the strangest plugin that will compile to pyc and sees your code-base fail gracefully, correct?

    • @ArjanCodes
      @ArjanCodes  3 года назад

      Yes, that's a good way to test various edge cases of what a plugin should or shouldn't do!

  • @orestesom
    @orestesom 7 месяцев назад

    The whole creation of the characters it's pure magic. Congrats! The way the creator_func creates the objects its beautiful!

  • @AnthonyPerot
    @AnthonyPerot 2 года назад

    really nice! However, I'd register the dataclass using a class decorator which takes character_type as argument.

  • @lioneluran
    @lioneluran Год назад

    This looks great and all but, is it just me or these patterns combined make it very hard to create comprehensive unit tests? How would you accunt for your builder behaving as expected with such flexibility while importing modules and classes?

  • @Snookik
    @Snookik 3 года назад

    Zelfs als ervaren dev heel nuttig
    Obligatory: Wanneer komt de TickTick 2015 XNA naar Python editie? :)

  • @huatsonmx
    @huatsonmx Год назад

    most of the peeps here are suggesting, adding, modifying code, FCS, he KNOWS all of it, but he needs to have a base code simple for explanation, just enjoy the masterclass!

  • @twistedsim
    @twistedsim 3 года назад +1

    Nice witcher references
    :)

  • @fschlz
    @fschlz 3 года назад

    This is gold, thanks

  • @presstv
    @presstv 2 года назад

    the tutorial was awesome

  • @nicopic2381
    @nicopic2381 2 года назад

    Here the PluginInterface class is an Interface working exactly like a protocol ?
    I find it strange that « class PluginInterface: » and « class PluginInterface(Protocol): » seems to do the same
    So what the difference ?

  • @nostromo9081
    @nostromo9081 3 года назад

    I have not watched the video yet but I am sure it will be exciting. Thank you Arjan and keep on building :)

  • @themilkpirate
    @themilkpirate 3 года назад

    I learned that try block should be as sort a possible. So it would be good an idea, to move the return out of it, after the except in def create(...). Whats your opinion?

  • @badoli1074
    @badoli1074 3 года назад

    I love your tutorials, you're great at explaining! Just the jump between showing the code and showing you is quite jarring and jumpy sometimes. For a tutorial you're almost doing too much camera work, especially as you're typing really fast (wow!). I'm about half a quick and need to swap between the browser window and my text editor very often to pause the video.

  • @thekgul
    @thekgul 3 года назад

    it’s good to listen to you

    • @ArjanCodes
      @ArjanCodes  3 года назад

      Thank you, glad you like the videos!

  • @brunodepaula5293
    @brunodepaula5293 4 месяца назад

    How do i deal with real world implememtation in which i need a way to deal with the dependencies (external libs) that just my plugin will need to run ?
    Also, plugins will not be in the same path as of my application, specially when I install it as a onefile (using pyinstalller)..so how to deal with the imports?
    Please could you make a tutorial with a more "real example"?

  • @nicolabombace2004
    @nicolabombace2004 3 года назад +3

    While this architecture allows a truly extensible framework, how would you defend the host computer against plugins that contain malicious code?

    • @fat_pigeon
      @fat_pigeon 3 года назад +3

      Sandboxing. Use a declarative plugin interface, and also execute all of the plugins in a separate, sandboxed process. Essentially, the subprocess only has permissions to communicate with the host process. This requires explicitly defining an API for the plugin to call into, which is a good idea anyway for compatibility (plugins will be coded to an interface that you promise to support across versions, even if you refactor the host app), but reduces flexibility (plugins can only modify your app's behaviors in ways you've explicitly planned for) and takes work.

  • @RyanJulyan1
    @RyanJulyan1 2 года назад

    Hi Arjan, Thank you so much for this. It is exciting. I am hoping to use it in a project very soon.
    While looking at your example code, I ran into an error in the loader.py:
    "
    def load_plugins(plugins: list[str]) -> None:
    TypeError: 'type' object is not subscriptable
    "
    It was not happy with the function parameter hint for plugins: "list[str]"
    I was running version 3.8.6 and noticed you were running version 3.9.6. When I upgraded to your version, the code worked perfectly. I was wondering if you could help me on how to find the lowest version of python this functionality would work on is. I am more asking for a method or approach on how to find this out than the specific codebase so that I can empower myself for next time :)
    Thank you for your amazing content and hard work putting these out.
    Kind Regards
    Ryan Julyan

  • @Hubert4515
    @Hubert4515 3 года назад

    very interesting vid, as always

    • @ArjanCodes
      @ArjanCodes  3 года назад

      Thanks, happy you enjoyed it!

  • @pariterre
    @pariterre 3 года назад

    Thanks for this (again) amazing video!
    I was wondering, is there a reason why the new Character do not inherit from the GameCharacter class?
    Thanks again!

    • @djl3009
      @djl3009 3 года назад +1

      I think it is because he chose to use the Protocol class to define the GameCharacter interface instead of ABC inheritance. He provides some guidance on when to use the Protocol class vs (ABC) inheritance in another video (ruclips.net/video/zGbPd4ZP39Y/видео.html). I also found the official Python docs explanation useful regarding the rationale behind the Protocol class: www.python.org/dev/peps/pep-0544/#rationale-and-goals

    • @nandoflorestan
      @nandoflorestan Год назад

      The reason is, GameCharacter is a Protocol. And now you have to go read about protocols in Python.

  • @superbroker.dxb007
    @superbroker.dxb007 2 года назад

    Hi Arjan,
    I subscribed to your newsletter but did not receive the 7step pdf yet

    • @ArjanCodes
      @ArjanCodes  2 года назад

      Did it by any chance end up in your spam? If you haven't received anything, send me an email (support@arjancodes.com) and I'll make sure you receive the guide.

  • @davidmatten8519
    @davidmatten8519 Год назад

    a better version of importlib.import_module would support generics, to be able to specify the return type explicitly

  • @davidmatten8519
    @davidmatten8519 Год назад

    wouldn't a better decoupled plugin design not force the new Character classes to know anything about the mechanism of the plugin factory, but rather just have a factory that searches through a designated directory, instantiating any classes it finds (with certain limitations for safety, perhaps), and registering the classes it finds that implement the given Protocol or ABC, and ignoring/noting any others it finds that do not comply?

  • @TomTrval
    @TomTrval 3 года назад

    Ok this video project looks like labor of love :D

  • @fuba44
    @fuba44 3 года назад

    My python code is the neanderthal equivalent of your modern day humans python code... But I'm learning 🙂... love the channel.

  • @josetapias2339
    @josetapias2339 Год назад

    Hi @ArjanCodes and thanks for sharing your knowledge. I download the project, but when I run it with python3 I got the following error: TypeError: 'type' object is not subscriptable
    in the factory module: in this line : character_creation_funcs: dict[str, Callable[..., GameCharacter]] = {}
    I wonder what I'm doing wrong.

    • @josetapias2339
      @josetapias2339 Год назад

      I found the error: The error occurs because the code uses "dict" instead of "Dict"; also uses "list" instead of "List". the initial letters in lowercase are the built-in datatype but the initial letters in uppercase are the corresponding type. I made this little change and it works.

    • @ArjanCodes
      @ArjanCodes  Год назад

      Glad that you made it work!

  • @digiryde
    @digiryde 3 года назад

    My favorite part. "Toss a plugin to your code."

  • @alivecoding4995
    @alivecoding4995 Год назад

    Isn't there any dedicated library for this?

  • @MMarcuzzo
    @MMarcuzzo 3 года назад

    How does that "raises ValueError(... " Works? From None? That's not usual for me. Thanks

  • @maximilian1344
    @maximilian1344 3 года назад +1

    This was a really cool video! But doesn't this open up our code to malicious code? From my PHP times everything inside me starts screaming when we take a string and pretty much execute it :D. I know this scenario is different because the end user doesn't really see the config file and plugin directory. Nevertheless, we allow arbitrary code to be executed purely by adding a line of code to our config. What are your thoughts on that?

    • @ArjanCodes
      @ArjanCodes  3 года назад +1

      This is certainly possible. It’s therefore also important to have processes in place to protect yourself against that. For example, if a plug-in is to be distributed, you can require to check the code beforehand (kind of what is happening in app stores). You can also limit the things that a plug-in can access via the interface that you provide, but since Python has little protection in terms of access restrictions, this is dangerous.

    • @malteplath
      @malteplath 3 года назад +1

      @@ArjanCodes Python's introspection features will get you anywhere once the main program calls your code. That does not make the architecture invalid, it only means that you will have to have some process to vet the plugins. Like you suggested. There is no way Python and Python code can ensure 100% security against malicious plugins. (I guess this holds for any interpreted language.)

    • @Ryndae-l
      @Ryndae-l 3 года назад +1

      Well, if someone can drop code in your plugin folder, what is stopping them from modifying your base code ?

    • @maximilian1344
      @maximilian1344 3 года назад +1

      @@Ryndae-l simply shipping a malicious plugin from some website and letting the user "install" it, is a lot easier than modifying the base code somehow.
      But thanks for the replys, everyone :)

  • @bocckoka
    @bocckoka 3 года назад

    woo, functional programming!

  • @mcalister1911Ab
    @mcalister1911Ab 2 года назад +1

    seems like an observer pattern with dinamic load to me

  • @hajajmaor
    @hajajmaor 2 года назад

    Why you didn't do the GameCharcter class an ABC class?

  • @arcowo
    @arcowo Год назад

    16:16 instead of "the least horrible way of doing" you should consider it "the lesser evil" 😉

  • @robertbrummayer4908
    @robertbrummayer4908 3 года назад

    Great video

  • @budoray
    @budoray 3 года назад

    Toss A Plugin To Your Code. Noice!

  • @mahikumar8813
    @mahikumar8813 3 месяца назад

    How do you quickly remove the code? What is the trick?

  • @rhafedh
    @rhafedh 2 года назад

    Waw! Nice one :)

  • @adjbutler
    @adjbutler 3 года назад

    Love it amazing!

  • @anhnguyenuc6543
    @anhnguyenuc6543 3 года назад

    Awesome, I've seen you from the Write better Python series, keep it up.

  • @nianeddavid7985
    @nianeddavid7985 3 года назад

    hello, your tutorials sound very interesting to me but i'm having a hard time understanding. It’s interesting sometimes to start from scratch.

  • @FabriceNormandin95
    @FabriceNormandin95 3 года назад

    Great video! (This is the third time I try to leave a comment, they seem to disappear as soon as I write them! Or are they getting removed? Am I going crazy?)

    • @FabriceNormandin95
      @FabriceNormandin95 3 года назад +1

      I was suggesting the "entry_point" feature of setuptools, which is a great way to add plugins from outside your package!

    • @ArjanCodes
      @ArjanCodes  3 года назад

      Sometimes RUclips filters out comments, but I’m not sure how it works exactly. Entry_point is interesting, I’ll take a look, thanks for the suggestion!

  • @miguelvasquez9849
    @miguelvasquez9849 2 года назад

    what exactly does "{!r}" do in 09:51?

    • @josetapias2339
      @josetapias2339 Год назад

      It just calls the repr of the value supplied.

  • @CrapE_DM
    @CrapE_DM 3 года назад

    Interesting. Everything else I've read tries to make their loader search the file structure for plugins, but yours simplifies the loader code a ton by having the plugin be registered in the config file...

    • @ArjanCodes
      @ArjanCodes  3 года назад

      I often like introducing some kind of intermediate data representation to decouple things, in this case a configuration file. Later on, you can write code that automatically generates the config file contents, but the rest of the code doesn’t need to know anything about that.

  • @kamildwyer6012
    @kamildwyer6012 3 года назад

    very nice