r/AskComputerScience • u/waycoon • Jun 07 '21
How to go from simple Python scripts to properly engineered programs?
First of all, I do not have a SE or CS background. I do however have a degree in Data Science. During my studies, I've used Python mainly in Jupyter Notebooks and occasionally regular Python files.
I feel like I am at a point where I am not a beginner in Python, however when I try to move from short scripts or notebooks to larger hobby projects(like bots). I find it hard to write good code and structure it in a way that's efficient.
A friend of mine mentioned that I should look into Object-Oriented Programming. Which seems like a good direction. However, when I look at other people's work I still see them doing things that I have never learned before. Like creating virtual environments and structuring their directory system in logical ways. Including libraries and packages. Usually, they use __init__ files and store their functions in utils files. They always use version control and often run their programs through batch files.
I am wondering if you guys know of any useful resources that provide an overview of all these methods to create properly engineered software. Right now I am looking things up on the internet as I encounter them. But I believe I am still missing a lot of useful information that I haven't thought about. And when I look up software engineering tutorials I always end up with introductory programming courses, which is not what I am looking for.
6
u/ghjm MSCS, CS Pro (20+) Jun 07 '21
If you want to learn software engineering theory, then Software Engineering: A Practitioner's Approach by Robert Pressman is the standard text. But it won't give you language-specific details like how Python modules and init files work and when and how to use them.
If you're looking for a more hands-on, "I need to know how to structure this software project that I have right now" type knowledge, really the only way is to make contact with more experienced Python developers who are willing to help you. If you don't have senior devs at work, there are public Slack instances and so forth. Maybe you can work through it yourself by looking at "good" projects and figuring out what they're doing, but the why aspect of it will be hard to get without talking to people.
4
u/MrRosenkilde4 Jun 07 '21
Robert c. Martins Clean Code is a really great book for learning this skill.
3
u/headlessgargoyle Jun 08 '21
The problem is "properly engineered" means different things to different people, and often it depends on level of experience and what specifically has bit them.
Anyway, for what you've described as your level:
Tooling wise, look into git for version control, it's pretty industry standard. Git fork or sourcetree provide nice UIs if you'd prefer a UI to CLI. Github and some other places allow for free private repos, use them. Consider looking iinto docker for virtual environments, and docker compose once your environments are large enough, however this may not really be necessary for you right now, consider if it makes your life or the life of someone consuming your code easier before diving headfirst into it.
OOP is a solid way to model problems. Modelling problems necessarily drives how you structure your code. From there, there's generally two main paradigms to code structure: "logic / stack" or "business / entity" (just what I've heard them called). This writeup has a good overview of the difference, though is heavily biased towards business organization. They use java, but frankly it's similar enough in any language. Personally, I recommend logic for small projects with a transition towards business a project grows larger.
Learn from your own mistakes- go back to old solutions you designed, what would you do differently now that you know more? You don't have to actually improve the solution especially if it's now unused, but think about what you did in a less than ideal fashion. Also learn from other's mistakes- find out why people do what they do, were there alternatives? What were the upsides and downsides?
1
Jun 08 '21
python is a horrible language teach yourself software engineering with. choose yourself a strongly and statically typed language and start doing projects, inspecting other people's projects etc. you can learn c++ from here learncpp.com
0
u/S-S-R Jun 08 '21
Agreed. Although I think for learning proper programming Rust would be better, since the compiler complains about everything.
2
u/sandmasterflash_ Jun 08 '21
That’s a good way for a beginner to hate programming for a long time
1
Jun 08 '21
honestly it could be friendlier than 527283zw73528 template depth error reporting from gcc for a beginner
0
19
u/secretpoop75 Jun 07 '21
This is not specifically for Python projects but is nonetheless a great resource. https://missing.csail.mit.edu/