# Object orientation - do or don't?

**URL:** <https://forums.plex.tv/t/object-orientation-do-or-dont/21139>\
**Category:** Dev/API Corner\
**Tags:** plugin-dev\
**Created:** [September 7, 2012, 6:00pm UTC](https://forums.plex.tv/t/object-orientation-do-or-dont/21139 "2012-09-07T18:00:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shirk](https://avatars.discourse-cdn.com/v4/letter/s/839c29/32.png) [@shirk](https://forums.plex.tv/u/shirk)\
**Post date:** [September 7, 2012, 6:00pm UTC](https://forums.plex.tv/t/object-orientation-do-or-dont/21139/1 "2012-09-07T18:00:40Z")

</div>

Hi,  
  
as some users on the form may know I’m maintaining the EyeTVLive plugin which allows to watch streams from an Elgato-device and access EPG from within PLEX.  
  
Since most updates from the 0.9.5.X series PMS did break my plugin in one or the other way I seriously thought about reworking my code.  
  
  
  
I came across this part (in the still horribly outdated dev-docs):

> [@](#):
>
> Because plug-ins are executed within the framework’s runtime environment, the code structure is more strict than in a normal Python program. All of the plug-in’s code needs to be contained within functions. Although it is generally safe to initialize simple variables with types like str, int or bool outside a function, anything more complicated (especially involving framework functions) may produce unexpected results or fail completely. This is because the runtime environment needs to be fully initialized before using any of the framework methods, and code in plug-ins that exists outside a function is executed as soon as the plug-in is loaded. Any code you want to execute when the plug-in loads should be put inside the Start() function. More information can be found in the functions section.

  
  
My plugin right now consists of multiple files along \_\_init\_\_.py which in their own respect implement critical parts of the functionality.  
Most of this code is written in oo-fashion encapsulating functionality in classes like EPGParser or M3UParser etc. - up till the latest PMS releases this seemed to work just fine.  
The plugin is running in elevated policy so importing was not a difficulty.  
  
However starting with the 0.9.5.X PMS releases I got more and more error logs which showed stuff like 'runtime not fully initialized' along with strange  
exceptions when calling methods on my classes.  
  
One case for example was EPGParser.py which in turn imported the systems 'time' module - this would sometimes cause the initialization error above..  
  
  
What is a generic advice from you other plugin devs?  
My plugin is complex enough to warrant more than one file and I really like the clean code interface I get by using classes.  
However if the PMS runtime is getting between me and working code then maybe it's time to go back to pure functions?  
  
Any recommendations / experiences are welcome :)

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/plex/original/3X/2/a/2acb9765406f63293d357b4ec509ec39aa28f2ad.png) [@system](https://forums.plex.tv/u/system)\
**Post date:** [December 20, 2019, 10:14pm UTC](https://forums.plex.tv/t/object-orientation-do-or-dont/21139/2 "2019-12-20T22:14:10Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
