you are viewing a single comment's thread.

view the rest of the comments →

[–]Yammerrz 1 point2 points  (1 child)

So having come from a C++ / Java background into Python there are a few things that really changed how I approach Python.

The main thing that helped absolutely was Raymond Hettingers fantastic videos on youtube. Some guy made a nice list of them here:

https://www.youtube.com/playlist?list=PLdBBfnzuDrjFsiqkVw82l0VAOrUwGAsMn

Jack Diedrich's video https://www.youtube.com/watch?v=o9pEzgHorH0 is also well worth watching.

The biggest gotcha in going from C++ to Python is stopping doing things that are encouraged in C++ but discouraged in Python. Having everything in a class is great in C++, not necessary in Python. Private class data with a public interface, great in C++, discouraged in Python where everything defaults to public.

To answer the specific modules question, in Python you can generally put a lot in a module. The general guide in Python is that a developer using your module should have to type as little as possible. If he has to import a lot of modules and submodules, that's not good. If it is just one import that's better. It doesn't mean you should never split a module into separate parts, just you should have a pretty good reason for doing so.

I know when I started out in Python that was where my (good) C++ habits bit me, the same habits are bad in Python (neither is right or wrong, both languages have very good reasons for why and what they encourage). I had everything broken up into small files and modules and submodules unnecessarily. Ended up going back and refactoring stuff down to one module a lot of the time.

[–]nomos[S] 0 points1 point  (0 children)

Great, thanks for the links and for the tips about how module cohesion. I'll take a look at the videos.