Functions for cleanup of code

I have been just getting more and more into shaping my addons into something more useful for myself and after watching a video short on Youtube I got to thinking about what I am working with.

Does it make sense to make smaller functions for similar things that occur across many operators like polls or basic common parts like checking if the selection is an object and with material and nodes etc. Should I be doing this to streamline the code more, or is it expected that a novice is going to draw out a lot of steps to get working operators?

edit: like many times using things in the execute like scene = context.scene and obj = context.object. That right there after making so many operators, I should have made a simple function that stated that and reused it across some 30 or so operators, right?

It’s not uncommon… Infact, the scripts from Blender do this quite often, like for example a base class with just a poll function that works in a very specific environment, and then all other classes inherit from that class (as in the old nodeitems_builtins.py); or just the poll functions that are reused in factory calls (as in node_add_menu_*.py).

1 Like

That gives me hope that I’ll be able to reduce the clutter here and get things organized better. I’m still redoing things as I find them.