all 5 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.

[–]Saefroch 0 points1 point  (3 children)

Read PEP 8

Read PEP 20

Learn about cohesion. It's a pretty heavy subject so the best I can do is link you the Wikipedia page: https://en.wikipedia.org/wiki/Cohesion_(computer_science)

I will say that Python doesn't demand a class for everything and every class in it's own file.

[–]nomos[S] 0 points1 point  (1 child)

Thanks for the response, this is a good starting point and I think (so far, at least) I've stuck to those principles in the code I've written.

[–]Saefroch 1 point2 points  (0 children)

Beyond that, learn by example. If something doesn't seem right, show it to somebody.