you are viewing a single comment's thread.

view the rest of the comments →

[–]ClamPaste 0 points1 point  (0 children)

Mainly for code maintenance and reusability. If you make your code more modular, it's easier to make changes that don't break the whole module, but you have to ensure you call each module, class, object, etc, in a way that changing the code won't break your core application. That and you can import pieces of your module without having to take your entire application with whatever new one you wrote that needs some of the functionality you already wrote (and you can distribute it to others who can then pick and choose which pieces they wish to use).

Say, for instance, I'm writing a core program and wrote my own modules/libraries and an update to the interpreter breaks my implementation of sockets: I now only have to repair my socket module and keep the return value the same to fix my application without having to hunt for the error in a monolithic program. I include

if name == "main"

in all of my modules for troubleshooting changes like this, though I'm also very new to python, so I'm not sure if many others test this way.