HACKER Q&A
📣 enmiljon

How to become a better Python developer?


Ok,

So I have been coding Python for almost 8 years know (not professionally). I know the syntax like the back of my hand, however i still struggle with organizing my code/projects.

I have the following problems:

1.When i work with classes am not sure what should be a class on its own, and when to use inheritance. The examples available are pretty stupid e.g Animal -> Dog etc.

2. I do not know when to create a new file, where should my code live? How should i structure it?

3. I seem to get confused by my own code after a couple of weeks when i look at it.

What would you guys recommend me to read/learn? Am looking for some kind of pattern i can work with.

Thanks


  👤 lordkrandel Accepted Answer ✓
I work as a developer at https://www.odoo.com. Generally speaking, a professional software company has some kind of "style", "guideline" and "culture" that guides developers.

It's like building a house. Before you even start, you know you are going to need windows, walls, a roof... being a professional means having built so many houses that you know the order, the required components, how much time it should take and a hint of the cost.

So if you have models like orders, bills, partners, contacts, you probably have a class for each and it's going to be mapped to the database tables somehow. Ýou will need to display the data and make it editable. You carefully plan and then you make space for refactoring, maybe use methodologies like Agile to decide priorities.

Translate this into: authentication, authorization, data storage, algorithms, performance, user experience, import/export and ETL, documentation, tests, customer support, analytics.

If you also are into product, add to that product design, marketing, hiring, supervision...

If you are an expert, you may want to optimize, to make extensible components, to write a DSL, an API, to make collatersl services.

"Clean architecture" is a classic go-to book. You can have a look at the QT framework docs which are very good. This is a good starting link also. https://queirozf.com/entries/how-to-structure-software-proje...


👤 a3n
If you're having trouble organizing around classes, objects and inheritance, classes might not be a good fit for your project.

Consider modules as your main organizing scheme. That's also a decent guide for code file organization.

What goes in a module? The tool(s) that you need to implement your project. Think about what off the shelf tools you wish you had and build those tools/modules.

Use doc strings per module and function, written to your future self, explaining what is being done. The how should be in descriptive variable names and function signatures, with comments where necessary.

Don't over comment. Out of date comments will confuse.