r/learnpython • • Nov 05 '20

How does one learn to make well-structured programs? Mine are dumpster-fires.

So I just (kind-of) finished reading Automate The Boring Stuff With Python, and for the past month I've felt like a big-brained super-hero automating myself out of a job (Data Analyst).

The problem is, I feel I missing something along the way. I don't understand the proper way to use functions, what a class is, why people have multiple files in a program, how/why people use GitHub...probably some other things I haven't discovered yet.

They all seem to be related to organization? Is there a "How To Structure Your Python Stuff With Python" book?

478 Upvotes

98 comments sorted by

View all comments

6

u/funkless_eck Nov 05 '20

"Why and how do people use github"

This baffled me for a long time too - then I started using it myself to teach myself. Its really opaque because of the jargon but the basic concept is this:

(I will get some things wrong - im a beginner too - looking forward to feedback on what I mucked up)

  • You have a folder on your computer like c:/users/joe/documents/code/

  • You want everyone working with you to see it and be able to comment and make suggestions on it

  • but you don't want them changing it permanently and be able to undo their changes

  • Enter github. You make a repo / repository. This is a copy of /joe/documents/code. When you make changes to it (you make the background blue) github asks you to name this ("the great blue background change") and commit to this being the latest addition.

  • then you want to push this commit -ed changes to the online copy of your code folder (your repo)

  • but Katie thinks the background should be green - so she makes a branch of the code folder, commits the green changes and pushes them online

  • you all look at the green and blue versions and decide to go with green so you merge that back into the main branch of your repo. (Main used to be called "master" but they're working to drop the slave/master connotations)

  • to carry on using the green background you pull the merged branch of the repo to your local machine. But it stays on the remote online version

9

u/anh86 Nov 05 '20

Git is version control software. It enables an individual or team to make changes to code without altering a working master version. For instance, if I want to fix a bug or add a feature, I can create a new branch off of the master to work from. Once done, I can run tests or get approval on my code before merging it into the master branch. I could even abandon that branch altogether if needed. If I want to create a new version, I could create a new branch for those changes and preserve the previous version code as it was. Git can also help identify and resolve conflicts when multiple parties make changes to the same lines of code.

Github is an online repository that works with Git technology. It provides a convenient way to share code and back it up off-site. You can clone other users' code into your own Git repositories, you can easily push up your own changes or pull down teammates' changes when coding with a team.

1

u/funkless_eck Nov 05 '20

Yes. Git and github are separate. If I understand it correctly - git is more akin to a program or programming language and github is one way to use git. Just like how you can use python on the command line, or in IDLE or in Brackets or in VSCode...

3

u/anh86 Nov 05 '20

Git is simply a technology for tracking code and placing it under version control. You can work with Git in a number of ways (command line tool, GUI tools, etc.). You never have to move any code beyond your own local storage if you don't want to.

Often, however, people want to share or backup code through some remote repository. Github is one such remote repository but you could also host your own server, use Gitlab, etc. These are simply remote repositories in which code under Git version control can be stored or shared.