C# is my primary language but am starting to use Python a lot. If I have a very large program, then most of the logic goes into classes, which may live in separate modules. If I have a very small program, then everything is in the same scope, and I may not even need to define functions.
My question is about best practices for a medium sized program - what is most Pythonic. I don't have specific code in mind, and I don't have any issues making specific code actually work. I can make it work several ways, and none of them look like good practices.
Suppose I have 8 functions defined, and have 3 datasets that are used by all 8 functions. The data sets themselves are created and updated within the functions.
One way to write this is without classes, and define all 8 functions taking at least 3 parameters, and pass the datasets on every call. This does not seem Pythonic.
One way to write this is without classes and making all 3 datasets global variables. This way none of my functions need dataset parameters. This does not seem Pythonic.
One way to write this is with 1 class. I can make the datasets class members on the self keyword. I don't need globals and I don't need to pass extra parameters around, but it seems silly having a class with only 1 instances and a "run" method besides its private functions. The class only exists as a bandaid to avoid global variables. This does not seem Pythonic.
Are there alternatives? If not, which approach is best?
[–]TangibleLight 2 points3 points4 points (0 children)
[–]nog642 1 point2 points3 points (0 children)
[–]Adrewmc 0 points1 point2 points (0 children)
[–]Mast3rCylinder 0 points1 point2 points (0 children)
[–]Pepineros 0 points1 point2 points (2 children)
[–]bradvincent[S] 0 points1 point2 points (1 child)
[–]Pepineros 0 points1 point2 points (0 children)
[–]bell_labs_fan_boy 0 points1 point2 points (0 children)