r/learnpython • • Jul 16 '20

Where to learn about Python program structure/design?

I'm self-taught in Python and am able to write programs that work, but I still don't feel like I know what I'm doing. Where can I learn about program structure/design?

I usually just start coding and one thing leads to another and pretty soon, I'm done. But I can't shake the feeling that a professional programmer would look at my code and laugh at how haphazard and inefficient it is. Any pointers or suggestions? Or are we just supposed to figure it out for ourselves?

375 Upvotes

57 comments sorted by

View all comments

8

u/life_never_stops_97 Jul 17 '20

I'd also suggest to look up OOP. It makes your programs scalable and really neat.

I was doing a lot of coding in python using functions and that's fine but recently I got an internship and when I see their code I was literally amazed at how they used their python code and made it scalable.
They had a scraping website that scraps stuff and I was amazed to see how everything has a module of it's own. They had their own request module, query manager to pass queries, base scraper that has methods like get_request, post_request, get_form_data , exceptions module and all were connected to each other to do one big thing(Scrape). It felt so right

4

u/dhruvmk Jul 17 '20

Imo you should only use OOP if you can find a way to link two classes using inheritance, that way a lot of code can be saved. If you need to quickly code an algorithm on the fly I'd recommend just using functions. But you are right, OOP brings scalability.

5

u/life_never_stops_97 Jul 17 '20

I agree with you on the part that functions are good if you're solving a leet code problem or just prototyping but most of the time a real world project could be refactored into OOP. It might not be easy to think in terms of how one module would connect to the other one and its definitely not obvious to see that in the first try but it's possible.

3

u/dhruvmk Jul 17 '20

That's very true, most complex systems implement some sort of object oriented paradigm

-2

u/a2242364 Jul 17 '20

I think the way you phrased it is kind of misleading and inaccurate. It should be, "you should only use functional programming or any other design pattern when you need to write up a quick and dirty algorithm or other small program that shouldn't utilize objects and classes". By default, you're mind should generally jump to OOP, and then from there you can determine whether another paradigm would be better suited for the task. I don't disagree with your premise though.

1

u/dhruvmk Jul 17 '20

No, seems like you misinterpreted my viewpoint. A huge problem is misuse of OOP by creating unneccessary classes and producing poorly written code. The idea that your mind should by default find an object oriented method to Implement your project is very wrong and is a poor programming practice. OOP should only be used when you wish to model real life objects and want to create a blueprint to construct the object. As a matter of fact, OOP is being used lesser and lesser nowadays because it still hasn't fulfilled one of it's core purposes (code reusability). Functional programming works in most cases; there's rarely any need to use classes for most projects unless you wish to build a large, complex system where each person in a team can work on building an individual class so everything can easily be linked together.

1

u/a2242364 Jul 17 '20

Functional programming works in most cases;

Just because it works, doesn't mean it's the best way. I guess we can agree to disagree.