Learning programming - only what you really need

27: Starting to set up a local development environment - Python in VSCode

Video


Summary

One of the most intimidating parts of starting out on one’s journey of learning programming can be setting up a development environment: getting a programming language installed, a text editor, a package manager, and so on. It never quite becomes pleasant, but over time, you get kind of used to dealing with annoying configuration errors, and learn how to solve them. But when things don’t work right when you’re a beginner… it can be tempting to just give up there.

In an attempt to head off such problems, it is my opinion that it makes sense to have an experienced software developer help you set things up the first time through. Along these lines, in this video I use Chrome Remote Desktop (a free tool that lets you remotely take control of someone else’s computer, with their permission of course) to help my friend set up a development environment for Python in Visual Studio Code (VSCode), a popular free text editor.

Timestamps

  • 00:00 - Introduction
  • 05:23 - Chrome remote desktop
  • 06:15 - Versions of programming languages, Python specifically
  • 10:02 - Configuration management is unpleasant and is easy to mess up
  • 13:10 - Command line basics
  • 20:16 - Package managers
  • 27:15 - System environment variables, PATH
  • 29:40 - Downloading Python with package manager
  • 40:57 - Text editor: VSCode
  • 44:06 - Python in VSCode
  • 50:20 - Bugs relating to the Chrome Remote Desktop connection - can skip unless you’re interested in watching the debugging process

Content

Chrome remote desktop

  • Setting it up, figuring out how to use it, etc.
  • One of the options for letting someone else remotely control you computer. Great for IT help for friends and family too, if you have become a go-to computer help person. (OTOH, if you hate constantly getting roped into helping people with their computers, you may not want to tell people of this option!)
  • Makes it easiest to get a new developer set up, since someone experienced can run through the setup steps directly. Installing and configuring things can be a larger barrier than first apparent to getting new developers up and running, and it can be really discouraging to want to learn programming hands-on only to get blocked for hours or days by obscure configuration-related errors. (New people don’t have as much general debugging/troubleshooting experience either, making these errors a bigger deal for them than for seasoned veteran programmers who will just shrug and instantly Google them).
  • Package management and configuration management are some of the most unpleasant parts of software engineering, IMO. Having people start with them is thus less than ideal.

Command line basics

  • No need to spend lots of time getting into messy details regarding operating systems and shells, etc. For our purposes, we’ll just start by navigating around the file system on the command line.
  • Three starting commands:
    • ls
    • cd
    • clear

Package managers

  • Let you manage and update software from the command line
  • Popular with software developers for managing development packages and frameworks, and really shine there. Many also support normal applications too (like browsers, text editors, etc.).
  • Can be scripted like all other command-line programs, but also support updating all installed software at the same time in bulk (so they are already inherently advantageous relative to many other installation management approaches). Manual update wizards can be a thing of the past.
  • For example: Chocolatey on Windows, Homebrew on Mac, various on Linux (e.g., apt on Ubuntu)
  • https://community.chocolatey.org/courses/installation/installing?method=install-from-powershell-v3

Downloading Python with package manager

  • https://community.chocolatey.org/packages/python
  • Automatically grabs the most recent version, sets up environment variables properly.
  • I don’t remember if the Python .exe/.msi GUI installer wizard makes everything “just work” out of the box (PATH environment variable, etc.), since I’ve installed Python via choco on the last several computers I’ve worked on. Maybe?

System environment variables, PATH

  • Environment variables for an operating system are kind of analogous to variables that live within a function’s scope.
  • You can only run executable files that are “on your PATH” = specified in the system environment variable called PATH. It is a list of file locations that are (or contain) executable files = programs that can be executed.
  • A common gotcha that can cause issues is that after installing something in a shell, you have to either reload environment variables with a command or exit out of the shell and open a new instance for the PATH environment variable to get updated after you install something. Otherwise the shell will say that it can’t find the new thing that you want to run.

Text editor: VSCode

  • Text editors with good plugin support and Integrated Development Environments (IDEs) proper are more-or-less interchangeable nowadays. IDEs (or the text editor plugins that have “IDE-like” functionality) statically analyze all the code in your project and let you do some useful things like renaming a variable everywhere in your codebase, or jumping to where a function is defined, even if it is in a different file from the one you are presently in.
  • Using something that lots of other people use means good plugin support and good out-of-the-box defaults. So I’d recommend that most people use something that is pretty popular and well-maintained.
  • I use VSCode (https://code.visualstudio.com/) professionally in my job, and I think it’s pretty great.
  • We’ll go over some recommended plugins and such later, as well as useful hotkeys

Python in VSCode

Video transcript

0:02 - hey guys so today is march 23rd and we are picking back up in the programming
0:08 - series here now my friend and i have had a rather long discussion about how we want to continue and proceed moving
0:14 - forward in particular we’re going to try to formalize some things and so uh you know thus far we’ve been doing
0:21 - some of the more basic stuff in programming like uh variables and loops and conditionals and things and as we
0:27 - move into some of the more advanced topics um and especially as we’re trying to kind of get things scaffolded set up
0:33 - for the real world we’re going to try to pick up the pace a little bit um so of course this is going to be good because it means that my friend can get a job
0:39 - faster hopefully and also that we can just finish things more rapidly in general so
0:45 - we spent a lot of time discussing some ideas that will go into this and uh of
0:50 - some of the things we settled on uh well we are going to try to go through a curriculum more formally
0:56 - so uh thus far i have kind of just been coming up with things on the fly i’m
1:01 - trying to make good example problems as we go um but we’ve decided here to try
1:06 - to make things a little bit more formal and that’s gonna involve several things so
1:13 - in particular here i’m going to be making a a plan here for us getting things done
1:20 - uh in the readme uh let me see let me hide beating controls
1:26 - there okay that’s better um and then uh so
1:31 - sorry i lost my train of thought um so i will be posting teaching videos some days of the week and then we will be
1:37 - meeting um on the other days so alternating days here uh to go over
1:42 - practice problems that we’ve assigned and then assign new practice problems so this is gonna be homework basically and then once we finish uh stuff we’re gonna
1:49 - have tests so this is gonna be set up a little bit more like a more formal academic class thus far we’ve been pretty informal but
1:56 - tests are a very important part of academic procedure they let you know how you’re doing in your learning what
2:02 - you’re doing good on what you need more work on and they help identify areas that you aren’t understanding and so
2:09 - we’re going to basically set up more assessments and more tests and have a more defined structure and some of the
2:16 - structure here should help in terms of schedule pressure you know if we have deadlines where we’re going to try to
2:21 - cover things by it’ll help for me it’ll help for my friend who’s learning in this process and basically we’re just going to try to be a lot more formal in
2:27 - general so one of the issues that we’ve run into uh in the last little bit is we’ve been
2:33 - going on our online ide experience is that we keep running into this problem where the debugger and the
2:38 - online ide isn’t working completely properly now to be fair to them uh supposedly it’s a feature that’s beta
2:45 - right now so not considered stable in release but that’s kind of a problem because debugging is important uh
2:51 - especially as we get into more complicated things here um so what we’re going to be trying to focus on for the
2:56 - initial bit here uh we have that thing where i’m going to be making teaching videos and we’re going to alternate days
3:01 - in that well that’s going to pick up kind of once we have everything set up here and specifically once we have everything
3:08 - set up in terms of visual studio code so a development environment for my friend locally and then also a version control
3:16 - with git and github and sourcetree you know all of this version control software here
3:22 - that way we’ll be able to share code in a repository and so i can come up with practice exercises and push to the
3:28 - repository and he can pull down the practice exercises and work on them locally and then push up his changes and
3:35 - i can look at them and so we’ll get to practice with version control uh as we go on moving forward here that’s the
3:41 - goal here but for the first few days until we get all of this infrastructure set up until we get the framework set up
3:46 - we’re going to be working together um right now i’m actually recording my screen in zoom and we have a chrome
3:54 - remote desktop session going on um so we’ll shift into the slides here that i prepped for today this is real real
3:59 - brief i might come and flush these out a little bit more i’m going to be trying to be more formal like i said though um so today on the 23rd uh these are the
4:07 - things in our outline here so i don’t know how much of this will actually get through uh first is we’re going to talk
4:13 - about chrome remote desktop a little bit that’s what we have setting up here uh then i’m gonna go over just some basic stuff on the command line using command
4:19 - lines moving around on the command line we’re gonna go over package managers uh at the operating system level we’re
4:25 - gonna download python with the package manager check the system environment variables and specifically the path variable
4:32 - which tells you uh what you can and cannot execute basically what
4:38 - just how you have name spaces in python another programming language this is kind of like the name space for
4:44 - applications on your operating system uh then we’ll talk about text editors and specifically vs code that’s probably the
4:50 - one that we’ll end up using here talk about python and vs code virtual environments for python and visual
4:55 - studio code setting up a launch configuration file for our project that is python and visual studio code uh then
5:02 - we’ll go over python packages the python package index uh the pip package manager
5:07 - for python and then we’ll talk about package dependencies at the project level and how you store these things in
5:12 - a requirements file here requirements.txt so just tons of stuff this is all basics of getting python set
5:19 - up locally developing locally um so lots to go into this um
5:24 - so we’ll start off here with chrome remote desktop so this is actually my first time using it too um but it seems
5:31 - to be working okay uh you know we had one slight hiccup was we were having audio echo over the call because we
5:38 - already have a call set up over zoom is how we’re screen recording here and then audio was also getting picked up over
5:43 - the chrome remote desktop tab so i just muted the tab and that fixed that and the reason why we’re doing this is
5:50 - because it should make it easiest for a new developer to get set up if someone experienced is just sitting
5:56 - there and installing everything in the correct order rather than having to type everything out into some long
6:01 - complicated guide if someone can just briefly take over control of the keyboard and the mouse well we can make
6:08 - things go faster just by installing all of the right things in the right order here um
6:14 - so uh along these lines before we go you know before we actually get farther
6:19 - i will check out here see if we have python installed already locally
6:25 - so i was actually planning on having us install it with a package manager um because that is very much the
6:32 - software engineering sort of way to um install things so
6:37 - packages packages packages python so looks like you already have two versions of python installed now are
6:43 - you okay uninstalling these uh just for the sake of going through this tutorial here
6:49 - um if we do it my way is the way i’m most familiar with and then i know things will be set up correctly that way
6:56 - um so we’ll go ahead and uh actually quite hoping that we don’t have
7:02 - to restart your computer in this that would be unfortunate um but if we do we do um
7:09 - so it looks like you have python version 3.10.2 and then an earlier python version looks
7:15 - like 3.6 um so i’ll just briefly ramble here while we’re waiting for the installation to go
7:22 - uh so all uh programming languages have versions their programming languages are a form of software themselves
7:28 - now python in particular uh you may have heard of python 2 and python 3. um so
7:35 - python had significant breaking changes between version 2 and version 3 of python and so
7:41 - the most current version of python at the time of speaking in 2022 is python 3
7:46 - um and basically you can’t run python 3 code in
7:51 - python 2. it just doesn’t work um so not portability between these two versions
7:57 - but python three code in general um you can run
8:02 - older code from python three so like code from like python 3.1 point
8:08 - something well we’re in 3.10 now but code from 3.1 will run in 3.10 so it’s backwards compatible um within version 3
8:16 - of python um and so you can have multiple versions installed at the same time like you see
8:22 - here uh we’ll get into this more when we talk about virtual environments but it’s actually a very very
8:28 - significant issue in software development because you if your project is developed in a
8:34 - specific version of python but whoever downloads your project has a later version of python and they try to run
8:41 - your project with that well what happens if something breaks because of that right so matching python version to the
8:46 - version of whatever your project is in is actually quite important um and
8:52 - so for that purpose uh python lets you set up what we are going to call virtual environments which
8:58 - is basically you put everything in a box um it it’s in its own container all of the stuff that you need for your
9:05 - application will be contained in this container for your application and it’s going to ignore any
9:11 - other python stuff that you have on your system so each application has its own box that
9:16 - has everything in it and so um in some ways this is kind of inefficient because if your application
9:22 - uses a package and another application uses the same package even if it’s the exact same package exact same version
9:29 - each one of them will have their own copy of it because it will be in the box for each one does that make sense um so
9:36 - we do try to like scope limit things sandbox things um so that you don’t get interference um that’s what we’re gonna
9:43 - do here as well so we’re gonna get rid of all the python versions for now um and just so that we’re starting from
9:49 - a clean slate so this one was actually a 32-bit version here
9:54 - we’re not going to worry about the difference for now it doesn’t really matter too much for our purposes so
10:01 - right now just continuing to ramble as we go on here um installing programming
10:07 - languages and text editor support for programming languages and libraries for them
10:13 - this is a pretty huge headache um as you’ll come to see it’s one of the least pleasant parts of being a software
10:20 - developer is you have to manage your configuration uh your programming uh like the languages you have installed
10:25 - and what versions of everything and managing packages i mean we have better tools for it now
10:30 - than in the dark days but it’s still kind of unpleasant um because it’s easy
10:36 - for things to get messed up and if you ever have to go track down like a package reference
10:42 - that’s not correct or something that’s causing errors in your project is really annoying
10:49 - my team at work we have a back-end project and a front-end project which we’ll get to eventually when we talk about web stuff
10:55 - but we have packages in both places and updating the package dependencies and stuff is probably one of the most
11:01 - bug-prone steps that you’ll that you’ll be involved in um and it can cause all sorts of weird
11:08 - behavior and bugs and it’s easy to mess things up and uh well this a long way of saying that you
11:14 - want to be making sure that you understand why we sandbox things in their own
11:20 - environments for python applications what the benefit of that is uh why we would want to version lock things uh
11:26 - we’ll get into all of this in more detail so don’t worry if you’re not tracking so much right now um but
11:33 - this is a reason why um you need to be careful in terms of like what versions of programming languages
11:40 - and stuff you have installed it’s not just python so java is another programming language so
11:46 - java has a runtime and also the development kit so a stable version of java that lots of
11:53 - stuff runs like java 8 but you can install java 12 you know so that’s several versions ahead
12:00 - and guess what same deal here java 8 code may not necessarily run in java 12. at least i don’t think so some
12:07 - things are backwards compatible but not all the time it really depends but versions very very very important when
12:12 - you’re developing software because your code will only run for a specific version at a specific point in
12:18 - time with specific package libraries as well and anytime any one of those variables changes your code might not
12:25 - work anymore so changes here typically called something
12:31 - getting deprecated so if something gets deprecated then
12:37 - what that means is is that something that used to be implemented as like a feature of the programming language
12:43 - is no longer there um so if something gets deprecated it basically means you can’t use it anymore
12:50 - um it’s been it’s been taken away um also new things get added and sometimes functionality gets changed as well
12:57 - so all of this together compose what we call breaking changes and anytime breaking changes happen
13:03 - suddenly code that used to work won’t work anymore in the new environment um
13:09 - so as we finish uh with all of this let me briefly go over
13:15 - um let’s see yeah let me briefly go over command
13:21 - line stuff um so right now we were uh download we were uninstalling old versions of python and what we’re going
13:28 - to do in just a sec here is um actually i can look at the slides on i can look
13:34 - at the slides on your computer as well
13:40 - maybe hopefully things haven’t crashed here
13:46 - um you still hear me right yeah okay and there we go never finished i
13:53 - guess it’s just being kind of slow yeah we can look at the slides on yours all right so um that was us finishing to uninstall so
14:00 - before we go farther i’m going to open a command prompt on your computer so um
14:06 - programmers and command lines um i guess we can go ahead and open a powershell here see
14:11 - if you are an admin on your account it looks like it or
14:19 - maybe
14:24 - what is this saying right now it’s not saying anything but
14:30 - um you have security prompt that should be
14:36 - popping up being like well you see it
14:42 - yeah um i think there may be some latency here um from it it actually
14:49 - shows me um a screen asking me to
14:55 - uh okay the launch of the app so [Music] like
15:01 - i don’t know how to explain it it it shows a security window asking me whether
15:06 - one so it doesn’t seem to me like i can control your window anymore um okay okay okay
15:16 - that’s can you control it now
15:22 - it looks like you can uh i mean you’re going to want to go
15:28 - back to where we are um this is where we are i don’t know can
15:34 - you let me let me uh
15:47 - hmm technical difficulties see i it says i’m
15:52 - in insert mode right now i don’t know precisely what that is what i want to do is be able to send
15:59 - see stuff i do is not getting sent
16:07 - my seats have to do with the um the partial
16:13 - uh no uh let me see if i can it looks like you you’re
16:18 - moving you’re moving the mouse [Music]
16:26 - well i still doesn’t seem like it’s moving to me okay let’s see now i am
16:33 - okay it’s moving in is powershell maximized for you not not yet no
16:41 - so is it just a powershell thing maybe it’s just a powershell thing yeah okay so i can access your chrome
16:48 - fine um but the second i open up powershell
16:55 - yeah can i oh okay you know what maybe powershell is a no-go um
17:01 - let’s try just there’s another powershell that’s not an administrator well that won’t work oh that’s what i’m
17:07 - wondering i’m wondering if maybe perhaps um can you can you close out of the
17:13 - powershell yourself can you take over yeah get rid of that um
17:20 - okay um let me see if i can just do normal powershell
17:27 - see i was wondering if the commands will work here so can i do this can i control this window okay yes i can control this
17:33 - one looks like so perhaps just because okay so
17:42 - wow so much lag
17:47 - okay so um have you ever done things on the command line before no
17:53 - okay so um you know how uh normally we have a file structure like
17:59 - if we go into windows explorer um you have a set of files in windows explorer here
18:05 - and you have folders and stuff right um so you know you have desktop downloads
18:11 - documents these are all folders you can access well it turns out that you can access all of this stuff from the
18:17 - command line as well so there’s two commands that we’re going to be going over today on the command line uh one of
18:22 - them is called ls ls stands for list and so you see right here this says ps and
18:29 - then c colon slash user slash odichinmardiwodo so that’s your name here
18:34 - and this represents the directory that we’re in this represents the folder that we’re in just like in windows explorer
18:41 - okay so ps stands for powershell we’re in the powershell prompt right now and when we type in the ls list command
18:49 - inside of this directory what it does is it prints all of the things inside this directory
18:55 - and so um basically uh you can see over here that
19:01 - uh some of these things are directories and some of these things are not directories so you see how
19:08 - everything here that has a d probably directors looks to me so like desktop and documents and downloads are all
19:14 - directories and so if we want to change directories there’s another command for that called cd cd stands for change
19:21 - directory right and ls stands for list and so um if we want to go into another
19:27 - directory uh we can cd into uh let’s go in downloads from now and
19:32 - you can if you press tab it will complete for you it will like complete the path and so
19:38 - now that uh another command you can run clear clear will clear everything that’s on the screen of the powershell uh right
19:46 - here so we just cleared that so now we are in you see how the path has changed now right we’re in the downloads folder
19:53 - and if we type ls again now wow you have lots of stuff in the downloads folder right
20:00 - so that is what that is what um the basic commands are here so clear
20:07 - clears the screen here cd lets you change from directory to directory and ls prints the things in the directory
20:14 - does that make sense so far yes yes okay so why i pulled powershell up here was
20:20 - because um one of the easy ways to manage um
20:26 - to manage the installation of uh programming languages and frameworks and
20:31 - stuff is to use what’s called a package manager um so
20:37 - these are very very common on linux they are not so common on windows and mac
20:43 - because many people use windows and mac primarily through a graphical user
20:48 - interface so mac os of course is actually running on a flavor of unix and windows is running on the windows
20:54 - kernel these are different operating systems linux is properly built on unix as well so linux
21:01 - and mac os are actually similar to each other more than they are to windows um but all of these things can use a
21:08 - package manager that you run on the command line so one of the benefits of this is that you are able to script
21:14 - things uh now that you’re learning programming you can use things uh in a programming language to automate things
21:21 - if you use a command line tool so of course people who are a little bit more what we would call power users
21:27 - well they tend to like package managers better because rather than having to manually go and update things or have a bajillion
21:33 - files that all have their own updaters that take your system resources and
21:39 - stuff you can manage everything from you can manage everything uh from the
21:45 - package manager itself so we’re gonna go ahead and open this link here this is to a package manager for windows called
21:52 - chocolaty um so this is the one that i recommend i use this on windows fine it makes it really
21:59 - easy to to basically install
22:04 - programming languages and uh other libraries and files and stuff and so
22:11 - uh we’ll see i don’t know if this will work as we are aren’t in a
22:17 - admin powershell instance here so i’m going to go ahead and copy the command here this is the command to install
22:24 - to install uh chocolaty for windows here so we’re gonna install it using a powershell script um so we’re in powershell here
22:31 - um i’m gonna paste this now um it’s what i just did i pasted it and now we’re gonna press enter we’re gonna
22:37 - see if it works or not um
22:43 - okay so it is looks like looks like we are uh we are going here um so
22:50 - um uh so downloading stuff on the command line usually looks something like this
22:55 - you know you’ll have something running as you download and it’ll show you uh things you’ll get text printed um
23:01 - so uh let me see more on package managers um something very useful the package
23:07 - managers let you do is they let you download and update all of your software all at once
23:13 - please run from an elevated prompt okay
23:19 - so looks like this is something that we are going to need to run in
23:24 - uh an admin prompt so so if we go ahead and close out of this
23:32 - you can take over the keyboard and stuff again go ahead and open an admin version
23:37 - of powershell and then using um
23:42 - using this command the command here you can copy paste this into the admin
23:48 - powershell and try running it from the admin powershell instance is everything i just
23:53 - said make sense yes
24:09 - okay and we’ll see if it goes this time
24:18 - now i can’t mess with this window i don’t think because it’s an app
24:24 - yes i can see it and it looks like it’s working fine but um
24:29 - no i’ll kind of make you drive here for a little bit
24:34 - [Music] okay so you see that warning up there it says
24:39 - warning it’s very likely that you will need to close and reopen your shell before you can use choco choco is just the abbreviations the
24:46 - command name here um so hmm
24:52 - sorry um i need to allow this but i i don’t know oh
24:58 - it might be that i don’t know i mean let’s see if it
25:03 - actually failed first uh so uh just ignore things for now um
25:08 - and um okay so i’m gonna take back over here we’re gonna go back to chrome
25:16 - well actually can you go back to chrome here briefly yeah okay so
25:22 - uh let’s see if i can do things again yes i can okay so this was the package manager itself um so before we go on let
25:28 - me let me sing the praises of package managers just a little bit there will be a period of discomfort here
25:34 - as you are a little bit unfamiliar with updating things on the command line but
25:39 - something that is very very useful is that if you start uh using a package manager to track a lot of your software
25:46 - distribution so maybe your browser your text editor other things like that you can run something like choco update
25:54 - or a package manager that’s used all the time on linux is on like ubuntu and stuff is called like apt app so like
26:01 - apt-get update apt-get upgrade uh you’ll run these commands and then it will automatically download and patch all of
26:07 - the software that you have on your system and so it’s very convenient for keeping things up to date security wise
26:14 - and also uh you know it’s quick um so i won’t absolutely force you to do this
26:20 - but one of the benefits of downloading especially especially programming languages with a package
26:26 - manager is when you have a setup script it will make sure that all of the environment
26:31 - variables for your system are set up properly and i will explain exactly what that means in just a second here
26:37 - so the next thing that we’re going to do is we’re going to install python using the package manager here like this
26:42 - now it’s been a while since i installed python like manually as i recall manually sometimes you might install it
26:49 - i can’t remember if it gets the variables right um and uh if everything just works the
26:55 - first time my recollection having installed programming language maybe not python java uh uh c plus plus other
27:02 - things is that sometimes you install the programming language and then things don’t just work you have to go figure out why they don’t work why can’t you
27:08 - use the language um and i haven’t had that problem since i’ve done this okay so now we’ve installed
27:14 - um chocolaty now you remember that warning that we got um we got a warning that said you might need to restart your
27:21 - shell before the command will be recognized right this is what i say right here um so a
27:28 - common gotcha that can cause issues when you’re in a show so that’s what powershell is that’s what a command
27:34 - prompt is uh you’ll hear them called shells and terminals these are things where you’re
27:39 - interacting with your operating system on the command line um so a shell reads
27:44 - these things called environment variables so when your operating system is running uh you know how functions
27:51 - have scope we’ve talked about function scope and programming right um so think in an analogous way that an
27:58 - operating system when you’re running like windows or mac os or linux an operating system has a set of variables
28:04 - and stuff it can access too sort of i mean we’re being very hand-wavy but that’s basically what it’s
28:10 - like and so one of the environment variables is this one here capital p a t h path
28:17 - and what your path is is it represents all of the things that you can execute
28:22 - so for you to be able to run a command on the command line that command has to quote unquote be on your path
28:29 - and what that means is this is the set of things that your operating system knows i can run this um if a user types this
28:37 - on the command line and presses enter i know what this thing is i know what code i need to run when this command gets
28:44 - called that’s what it means for it to be on your path and so the path environment variable is a set of file locations uh
28:51 - separated by semicolons i think i’m pretty sure it’s semicolons um so you have a set of file locations
28:57 - so it would be like slash user slash your username some other directory until you get to an
29:03 - executable file if you’re on windows um and what these things represent is these
29:08 - are the programs that your operating system knows how to run um and so for our purposes here installing a
29:14 - programming language like python what we want to be able to run python that needs to be an application that we can execute
29:20 - so that we can tell the system hey i want to run python and i want to do this thing or i want to do that thing
29:26 - or i want to run a script with python well we need the operating system needs to know oh i know what python is um and
29:34 - so to do that python needs to be on your path that is the jargon used here it
29:39 - needs python needs to be on your path okay so here is the command in chocolaty to download python but why i was pulling
29:45 - this slide back up here was we’re going to have to actually reopen our shell here um so if you go back to your admin
29:51 - command prompt and you try to run the choco command in fact we can even do it here um if you go
29:57 - to the chocolatey page and you try to run like taco install python i kind of doubt it will work um
30:05 - okay so you haven’t closed out of this one right this is still the same shell that we installed chocolaty right
30:12 - yes okay so go back to chrome and then go to the tab i think it’s the second tab
30:19 - um for installing python 3 okay and then you see that
30:25 - that command so you copy that and let’s try it here in our
30:32 - okay so it’s probably going to tell us uh we can’t find choco
30:38 - well okay well never mind and sometimes it’s smart um
30:43 - it depends um sometimes it will dynamically reload the environment variables um but
30:49 - you see this is all you have to do you know how when you install uh
30:54 - uh software with something called an installer you know how like you would download a file that’s like dot exe or dot msi and then you have to like
31:02 - go through a wizard and it has like steps and stuff um this is the programmer version of that
31:09 - basically um so this might not mean a lot to you but it shows you all of the dependencies it’s
31:16 - downloading right now so we’re downloading python version 3.11 this is the most recent python version it’s
31:21 - downloading some of the redistributable packages that are dependencies for it um it’s setting up some extensions and
31:28 - stuff for chocolatey it shows you everything it’s doing right now a lot of people aren’t going to care about this information whatsoever right and even
31:34 - for me look i mean i’m a programmer i’ve done stuff with this doesn’t mean very much to me either right but it’s kind of
31:40 - cool that it is there okay so it says this package wants to run this thing
31:46 - note if you don’t run the script installation will fail to confirm automatically next time use dash y or
31:53 - consider choco feature enable dash n allow global confirmation okay so
32:00 - what we are going to do is you see how um if you
32:06 - you see those letters that have brackets around them like the y and yes the a and all so
32:11 - we’re going to type capital a here well actually you should type capital a we want to say yes to all of these things
32:17 - so what it’s going to be doing is and then press enter um it’s going to be asking you for permission to do things
32:23 - here um to install this thing or that thing and if you don’t do yes to all
32:29 - uh what it will do is it will ask you each and every time and so then you’re gonna have to keep sitting here and babysitting the installation
32:35 - um and so now it’s installing all of these things that it downloaded initially and um
32:44 - uh well i mean you can read the output there um so this is how installing and updating uh
32:51 - software on the command line looks um now part of why i’m having us do this isn’t because
32:57 - the normal installer installation wouldn’t work or you wouldn’t be able to do it that way but uh you’re gonna be a
33:03 - software developer now right um it’s not entirely a bad thing for you to start speaking the language of computer
33:09 - programmers and i’m not telling you you’re not a real programmer if you don’t use this or whatever like there’s
33:15 - none of that nonsense we don’t need to be elitist about it but this is something that software developers tend to be kind of
33:21 - enthusiastic about right of all the human beings in the world we are the ones who who do things like this
33:27 - uh not all of us but some people um additionally uh knowing how to move around your file system on the command
33:34 - line with those commands that we talked about earlier here so cd lets you change directories ls lets you
33:41 - uh you know see things in the directory and then you will be able to execute
33:46 - things when you’re in the same directory which we didn’t do but that’s another thing you can do this is
33:51 - again uh many normal people will use the file explorer or some other graphical file uh
33:58 - system explorer to look at the files on their system but you can also do it on the command line um
34:04 - and so these are just uh tools for you to pick up uh because eventually you will probably need to do some things on
34:11 - the command line as a programmer um so when we get into uh version control systems like git
34:17 - git git has a command line version now uh i will show you the command line version and then we’ll probably almost
34:23 - never use it again because uh you can use git on the command line it works fine but there are some
34:29 - advantages to using a graphical program for it such as it shows you all the differences between files completely automatically
34:35 - in a nice pretty gui um so uh one of the nice things though about
34:41 - command line stuff is that you can actually use it in uh programming scripts um so so-called shell scripts
34:47 - that run in your shell you can basically write snippets of code that will execute
34:53 - certain commands in a certain order right and it’s really really powerful because it lets you automate things um
34:59 - so even things that you can access with a graphical user interface it’s very very nice if they have a command line
35:05 - utility or a cli is what they’re called command line interface that lets you interact with the program on the command line
35:11 - because suddenly then you can write you can write scripts that do things with the program um
35:19 - okay so it’s still going you see um there’s lots of files in python and you’ll notice that it’s downloading the
35:25 - 64-bit version here that means that you are running a 64-bit version of the windows operating system we don’t need
35:32 - to worry about that so much right now uh in fact i won’t even go there but
35:37 - basically there’s different kinds of uh different kinds of computer architectures here um 64-bit
35:44 - systems are different than 32-bit systems and so when code is running on your computer it needs to actually be
35:50 - specifically running in the 64-bit architecture like not all code is completely portable so when code gets
35:56 - translated down into ones and zeros it will only run on a specific kind of computer the specific kind of computer
36:03 - for the ones and zeroes that it made this time so you’ll have these things called compilers for compiled languages that
36:09 - will take code that looks like you know code you know like variable x equals
36:15 - something and it will turn that into statements the computer understands uh first it goes through something called
36:20 - assembly then it gets from assembly translated down into machine language which is just ones and zeros and then it runs on your computer um so
36:28 - we’re not going to talk about most of that for now we’re just going to kind of wave our hands and make pretend that all that stuff happens and we can just
36:35 - wave our magic wand because for us programming and high level programming languages we don’t really care that much
36:40 - um computers do some magical stuff to make it all work um all right so let me go uh while we’re
36:46 - waiting for this to finish installing okay it says it has been installed uh restricting write permissions to
36:51 - administrators we’ll see how much more it has here okay so it says here environment
36:57 - variables it says environment variables like path
37:03 - have changed close reopen your shell to see the changes or in powershell just type refresh environment so you want to
37:10 - type that refresh env
37:20 - okay and what that means is that uh we have uh
37:27 - printed or we have now updated the uh path here so um type in python three and then do dash
37:36 - dash version so and then space
37:43 - is space after python 3.
37:51 - oh you don’t need a space after the dashes just before the dashes yep
37:58 - okay press enter
38:10 - well interesting
38:16 - try doing the same thing but just with python rather than python 3.
38:30 - well maybe we should try closing the shell and reopening it we want to make sure that we can actually access python
38:36 - here
38:51 - so try the same thing then
39:00 - [Music]
39:06 - okay there we go so i guess the command here is python so not python 3. i can’t remember a
39:12 - difference differs by which operating system you’re using um so
39:17 - you see now but we typed in python and dash dash version and now it returns something it tells us that the python
39:23 - version we’re using is three point eleven point whatever that is um
39:28 - that release right okay so now it says we have python accessible and uh
39:33 - specific to us so if you can x out of this shell i think we’re good for now here um
39:39 - specific to us now we have python installed and it’s on this thing called our path that represents the set of
39:46 - things that the operating system knows what they are so you saw the second time we did it the operating system knows
39:52 - what python is now right so we give python as the name of the
39:57 - application and then we pass that the thing on the command line there with the dashes is called a flag it’s called a
40:02 - command line flag we give it the flag version it tells us hey i want to i want to check the version of this
40:07 - um and so we do python dash dash version it spits us back a version of python that means that the operating system
40:12 - knows what python is it’s on the path it’s something that it can execute all right so thus far what we’ve done
40:19 - is we’ve talked about package managers at a high level right i’m not going to force you to do this this is something
40:24 - that i’m enthusiastic about as a software developer lots of people are uh it’s cool lets you automate things right
40:30 - so this is kind of just g whiz information for you um but installing it with chocolatey like this means that it
40:36 - automatically sets up the environment variables for you does some of the configuration uh so i’m a big fan of
40:41 - package managers especially for programming tools i don’t think it matters so much like browsers and stuff but programming tools specifically i
40:48 - think package managers are great so we downloaded python with the package manager it automatically set things up on our
40:54 - system and now we see that we can access python so that’s where we are right now uh the next thing that we’re going to do
41:00 - is look at vs code some so i think you probably you might already have a vs
41:06 - code uh we’ll check here so uh maybe actually i’ll go to search here
41:12 - and uh i do ps code let’s see yes you do have visual studio code
41:19 - all right so um uh uh let me see just briefly on text
41:25 - editors so text editors are the the things that we as software developers use to write our code in um
41:32 - you may also hear the word ide uh ide is an acronym stands for integrated development environment um
41:40 - honestly most text editors now have plugins that make them ides so you can use these things more or less
41:45 - anonymously um an ide contains things that like basically analyze your code and let you jump around in your code uh
41:52 - we’ll get to all of this soon uh once i go over some hotkeys and stuff in vs code for you to use i like jumping
41:59 - to the definition of functions things like that um so uh text editors these
42:04 - are going to be the tool that you spend a lot of your time in as a software developer um you know outside of version
42:09 - control stuff and uh whatever system you use to track your tasks uh like agile task management systems like jira
42:16 - or devops depending on your platform uh we won’t go there for now um but uh text editor
42:22 - is very important for us um now visual studio code is great because lots of
42:27 - people use it and for that reason it has really good plugins uh since there’s like millions and millions and millions
42:33 - of people using it some people have poured a lot of time into making the experience in it good and it has a lot
42:40 - of good out of the box defaults so a lot of stuff just works pretty well
42:45 - like you don’t have to configure stuff it just works uh basically as soon as you install stuff um
42:51 - so i use vs code professionally in my job we use it for our front end stuff we actually use visual studio for a lot of
42:57 - our back and stuff in c sharp because that’s another microsoft ide specifically set up for c sharp stuff
43:03 - but we use vs code for our angular project angular is a javascript front end and uh i mean i use vs code anyway
43:10 - for myself when i do markdown uh stuff with markdown files um so uh vs code is
43:15 - a text editor um i think it’s a pretty great one uh you know in terms of text editors you may have also heard of
43:21 - something called sublime text it’s another text editor um survive text is also quite good um
43:28 - of the text editors that are like text editors you may have also heard of things like vim and emacs those are some
43:33 - of the power user uh command line like linux type text editors
43:39 - uh there are people who would who would roast me for saying this but i would avoid them um things like vs code if you
43:46 - want to use vim key bindings you can it has a plug-in for that but it’s just way more user-friendly for like 99 of human
43:53 - beings that don’t care that much about the other stuff um so i would stick with vs code um as long as you don’t have
43:59 - preferences you can just take my word for it vs code is one of the best um so
44:04 - okay so we have vs code open now um now for us specifically
44:10 - uh let’s see what packages you have here extensions so
44:15 - uh well it looks like you already have the python extension here so
44:21 - uh so pylance gives you the ide type
44:27 - features for python specifically um and it looks like you installed all
44:32 - of these things so ah and i see this was the
44:38 - looks like something relating to that uh project that uh you’d mentioned from before right this web scraper thing yeah
44:46 - um looks familiar there i didn’t read too much about scrapey but it looks like it’s a python package for doing web
44:52 - scraping so maybe we can go on your file system here
44:59 - and uh oh it looks like you already have some python set up here so uh for now i’ll
45:06 - just go into downloads and maybe we’ll just make a new folder and downloads here um so
45:12 - let’s do there’s our slides that we’re doing here
45:18 - let me just make a new folder
45:23 - i’ve got to click not on something specifically new folder [Applause] now looks like you have visual studio
45:29 - installed too um so we’ll do this
45:35 - right so on example okay so we’re going to make a new directory here
45:40 - and then in vs code over here we can go to the explorer here
45:46 - uh right now oh so yeah you’re you’re currently in the reply this is the uh zip file that
45:54 - they sent you uh for this application uh well for now we’ll just click on new
45:59 - file so uh well that’s not where we want to do it um
46:07 - well let’s let’s just
46:14 - can we just close it’s like leave it completely [Music]
46:20 - one second i pressed the wrong thing i was just gonna we can go open that empty directory that we just made right
46:25 - so right now you’re in this folder here which contains um
46:31 - uh all of the stuff from that example application that they sent you for web scraping but now i just i just switched
46:37 - folders so we just made that empty folder called python dash example um
46:42 - this is fine um so now we’re in this folder you see if you don’t have any files so we’re gonna go ahead and add a file here
46:48 - and we can call it uh or we can just call test.com okay so
46:54 - we’re gonna add a python file test up by like this and then we have the file we double click on it now we’re in test.pi
47:01 - right and so we could do something like this right um
47:07 - uh and so this is our test.pi file okay so now if we
47:13 - press f5 to run this uh
47:20 - and then debug create a launch json file
47:35 - okay so we just ran it says hello world right um so let’s go ahead and do this now um i’m skipping ahead a little bit
47:42 - um so visual studio code uses uh things called json files so json is a file type
47:49 - um uh it’s a uh sorry it’s a syntax for organizing information it has lots of curly braces
47:56 - and stuff okay so um
48:02 - huh how do i get out okay so
48:07 - um this is our uh this is our
48:13 - uh configuration here so we have the current file here um
48:18 - right you know i don’t want to talk about this now maybe i don’t want to talk about this now um
48:24 - so basically uh you can configure how you want things to run uh using this file here called launch.json
48:31 - um so right now we’re in a python file called test.pi if you ever want to change which file gets run by default um
48:37 - so we’re on the run panel here see this thing has got a bug on it and then an arrow this is our run and debug panel um
48:44 - i’ll do more when we do vs code stuff specifically but you show and hide the sidebar with control b
48:50 - uh if you are on any anything in the sidebar you can
48:55 - pull it up by control shift d will automatically take you to the debug menu and then if you just want to run stuff
49:01 - if you just want to run stuff no matter where you are you press f5 um those are real real briefly that’s some
49:09 - of the execution stuff here okay so we just ran our file hello world so there you go you have python setup great right
49:16 - so what we’re going to shift into now um uh for the rest of our time here
49:22 - yeah go for it okay so down here it says this version of python seems to be
49:28 - incorrectly compiled what does that mean
49:34 - oh good question um i mean we can go look at this so it says
49:40 - bugs.python.org so we’re going to control click the link probably open something in chrome here
49:46 - um
49:59 - um
50:19 - oh interesting i wonder which version of python thinks it’s using
50:24 - okay so we’re in powershell right here right me
50:32 - yeah i can’t see i’ve got the your desktop is being shared thing okay
50:39 - so if i type in
50:49 - i think i just nuked our connection that’s unfortunate okay
50:55 - the window must have gotten cut off here um yeah you’re getting really cool now
51:03 - all right well uh let’s go back to the chrome remote desktop thing
51:09 - you want to send me another code um yeah
51:16 - whoops
51:21 - well i can’t say for sure it’s kind of weird that you’re getting that it looks like there’s an open issue um i couldn’t
51:27 - tell you why python isn’t it says it’s not compiled correctly what i was going to check right here is which python version it thinks is pulling from is
51:33 - this the new python that we just installed or maybe it’s referencing a python that is not the right one so that’s what i
51:40 - was going to check oh excuse me let me see
51:47 - i can’t find my zoom may zoom okay i think i think it’s right
51:54 - there that’s right we were on different desktops so
52:02 - [Music]
52:08 - i suppose we would need to keep recording through this but it’s okay so anyone who’s watching will get to see
52:13 - how chrome remote desktop works um okay so
52:19 - did you just send it to me yeah okay so chrome remote desktop you take
52:24 - in the code that your friend sends you you put it in the connect to another computer thing
52:30 - and it sits here and does its thing
52:40 - and there we go okay so we’re looking at this issue here so i was going to go back to vs code
52:47 - before weird things happen my vs code now so i moved the window here
52:53 - so let me do python why is it it closes again
53:00 - what the heck [Applause] all right well i’ll pause this time so
53:06 - we don’t waste time okay so we’re going to try again here
53:14 - hide floating do i have
53:20 - to press enter in that terminal yes i
53:27 - keeps can the connection that is
53:33 - very strange huh
53:38 - i i just want to press the letter p i i wonder i wonder what the deal is um
53:44 - okay i mean here let’s let’s try one more time um and obviously i can’t press the letter p
53:51 - in that terminal without having something go back
54:10 - all right very strange lovely technical difficulties we’ll probably get the hang of this if we do
54:16 - this more um
54:39 - all right let’s move that out of the way somewhere
54:49 - why doesn’t it let me type letters down there
54:59 - let’s meet them all right well type in python-version let’s see if we can
55:05 - test it
55:10 - okay so it is that python version well
55:19 - internal generated file names are not absolute huh
55:24 - well you know what if we run into problems later i guess we’ll have to try reinstalling but
55:29 - um for the time being let’s not worry about that
55:38 - now the fact that i can’t use our terminal that’s that’s an issue um
55:48 - maybe it still treats that it treats it like the um
55:53 - [Music] yeah but the thing is i can press enter in it [Music]
56:01 - weird so it thinks that it’s still capturing the keys in my chrome not your window
56:09 - but if i’m here
56:14 - ah now something weird’s happening with the keys it’s not just the terminal it’s anything okay it’s not letting you type
56:21 - there too okay yeah yeah what’s going on then it’s weird very
56:26 - weird but you you were able to type before
56:38 - yeah it seems to me like it thinks the control key is being held down because
56:44 - that’s what control t opens a new tab right and that’s what’s happening when i press
56:49 - t here inside this so it thinks control is being held down
56:55 - even though i’m not holding down control i’m not here either
57:10 - i can type it on my computer so why can’t i
57:17 - let me relaunch vs code would that help no i don’t think it’s
57:42 - um [Music]
57:52 - ah i don’t know this is kind of gonna block us here see it wasn’t doing this forever it just randomly started
57:59 - doing this [Music]
58:13 - well let me go to chrome and let me see in
58:20 - your chrome well let me press the letter t
58:25 - nope so it seems like my keyboard in general is not working but my mouse is and i can
58:31 - press the enter key i can press the enter key on your uh
58:36 - on stuff over here too so
58:42 - well i mean i i tell you what uh let me let me figure finish talking through stuff here
58:48 - um i guess i am still recording here so let me finish talking through a couple more
58:54 - things but let’s figure this out before we next meet because otherwise this can be kind of hard for us to keep doing um
59:00 - so uh what we’ve gone through so far is we have vs code opened um we have the
59:07 - python plugin installed for vs code which lets us use python files um and you see also that in your python file
59:14 - here it is like highlighting things this is called syntax highlighting right that’s good
59:20 - and if we were to
59:25 - press f12 which is what i just did there we’ll get into this later when we do hotkeys more formally it takes us to the
59:32 - definition of that function and so this probably doesn’t mean too much to you here but this is the definition in
59:38 - python of the print function now i want to resize this window why aren’t you letting me resize
59:46 - okay yeah so this is the print function you know it’s got some very interesting
59:51 - looking library functions there but that’s what happens when you jump to definition much more useful for your own
59:57 - functions um now of course i can’t type anything because of our lovely bug here but um
1:00:03 - so yeah that’s python in visual studio code uh we will pick up next time we meet talking about virtual environments
1:00:08 - more um so uh specifically setting up a virtual environment for our project here in vs code and then setting up the
1:00:14 - launch configurations for vs code as well um so i think we’ll cut for here so we did
1:00:21 - make some good progress today um i know it was kind of slow as we were getting used to uh this chrome remote desktop stuff and
1:00:28 - installing software and checking versions and stuff but uh we’ll keep slogging through this um until we get to
1:00:35 - uh the point where you’re running everything in python locally here um so sound like a plan yeah okay so that’s
1:00:43 - where we’ll cut today and let’s try to figure out that weird bug that’s not letting me type um
1:00:48 - so we will pick up next time continuing on with python configuration vs code specifically virtual environments

28: Python virtual environments, VSCode launch configurations, packages w/ pip and requirements.txt

Video


Summary

In this video, we continue to work on setting up a local Python development environment in VSCode.

We talk about the concept of virtual environments (sandboxing packages per-project). We also talk about how to set up a launch configuration in VSCode to be able to always launch from your project’s main file, no matter what file you might otherwise be presently editing.

After this, we get into packages in Python, discussing the Python package index (https://pypi.org/), the pip package manager for Python, and how you can use pip to save a list of your project’s packages (in a file conventionally called requirements.txt) to make installation of your application easier in the future (and also stable = independent from breaking changes in updated package versions).

We also install Git, a version control tool, which we’ll work on setting up more next time.

Timestamps

  • 00:00 - Introduction
  • 02:20 - Our bug from yesterday: a Vim browser extension
  • 03:03 - Python virtual environments (in VSCode)
  • 25:07 - Setting up a launch configuration in VSCode
  • 33:53 - Python packages, the Python package index, and pip
  • 53:15 - Package dependencies at the project level, requirements.txt
  • 1:01:20 - Preview: Git (with Git bash), SourceTree, and GitHub (remote repository host)

Content

Our bug from yesterday: a Vim browser extension

  • If anyone else uses Chrome Remote Desktop with Vimium active, you have been warned!

Python virtual environments (in VSCode)

  • Virtual environments at a high level – sandboxing project packages so that they don;t interfere with each other
  • In VSCode specifically: https://jasonmurray.org/posts/2020/vscodepythonvenv/
  • In the integrated terminal, run:
    • python -m venv .venv
    • And then ./.venv/Scripts/activate to activate the virtual environment

Setting up a launch configuration in VSCode

Example:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "configurations": [
        {
            "name": "Preprocess",
            "type": "python",
            "request": "launch",
            "program": "main.py",
            "console": "integratedTerminal"
        }
    ]
}

Python packages, the Python package index, and pip

Example:

  • Let’s say you want to build a URL from a file path. URLs don’t have spaces (conventionally), and usually follow a specific format. To get strings in a format, we can download a package and use it: https://pypi.org/project/python-slugify/

Let’s say we had a simple program like the following


import slugify

def make_url(input_string):
  return slugify.slugify(input_string)

You can also just import the function directly (from slugify import slugify = in the format of from module_name import function_name), and then you don’t need to worry about the module name when invoking the method.

Package dependencies at the project level, requirements.txt

Preview: Git (with Git bash), SourceTree, and GitHub (remote repository host)

  • Git is a version control system. There are other options too, but Git is probably the most popular.
  • Version control systems track the changes you make to files over time, and are absolutely essential to the software development process, especially when working on a team of developers.
  • Today we will just be downloading and setting up a couple tools. We will get into specifics in our next lesson

Video transcript

0:04 - all right so uh today is march 24th and uh today we are going to be continuing
0:10 - on uh in our series here of learning programming and this is going to be the second day here
0:17 - uh of us uh moving uh faster so uh yesterday we had uh started downloading
0:24 - things on my friend’s computer to get the development environment set up and today we’re gonna keep doing uh that
0:30 - sort of setup procedure uh working with python and visual studio code uh so here’s the outline of things that we are
0:37 - going to focus on today uh we’re going to uh first off we’re going to go over we
0:42 - spent the last few minutes yesterday trying to figure out this reason why i wasn’t able to send key presses over
0:49 - uh the chrome remote desktop application that we’re using here um
0:54 - so we did end up figuring that out it was actually on my end i’ll go over that we’ll talk about python virtual
1:00 - environments which we kind of brought up some yesterday but we’ll actually experiment with them a little bit and talk more about them today we’ll talk
1:06 - about setting up a launch configuration in vs code what exactly that means and how that controls how you run your
1:12 - applications we’ll talk about python packages so library files that we can use in our code applications uh the
1:19 - python package index so finding python packages that you can use and then pit
1:24 - which is the python package manager here um and so just how we had chocolatey as a package
1:30 - manager for windows pip is a package manager for python then we’ll go over package dependencies
1:36 - at the project level so that’s managing groups of packages how you track them how you stabilize so you pick a set
1:43 - version and you don’t let the version go above that so that your code doesn’t break if things change
1:49 - in the version and then we’ll talk about the requirements.txt file which is conventionally how python applications
1:56 - store their lists of packages finally i will work on installing git at the end of
2:02 - today for you so it gets a version control software we’ll also install sourcetree and we’ll look at github
2:07 - the website again here probably won’t do a great deal with it today just because it would get very
2:14 - late probably but we’ll at least get it set up so that we can go over it the next time we meet
2:19 - so that’s our plan for today so first off uh i took me some troubleshooting uh
2:24 - the end of yesterday after we stopped recording but um there was a plugin i used for google chrome called vimium
2:30 - that lets you do some cool stuff in the browser with key bindings but i hadn’t realized that it was
2:36 - actually activating on the chrome remote desktop tab which is how we’re doing the sharing screen so that’s why some key
2:42 - presses were getting intercepted so anyone else use this chrome remote desktop if you have uh some
2:49 - extension in your browser like vimium so vm is not the only vim emulator for the browser but it’s one of them well if you
2:54 - have one of those things you might want to disable it when you’re using chrome remote desktop otherwise you end up with
3:00 - books like we had so that’s what it was yesterday for us there and so where we’re going to start here
3:06 - today is with virtual environments in python so if we go find the folder that we were working in yesterday we made
3:12 - we’ve made a folder in your downloads folder called python-example and if we go find this folder here you
3:18 - see these folders here that start with dot v-e-n-v right here this is the virtual environment folder
3:24 - and so we’re going to go ahead and just start fresh today so i’ll go ahead and delete the one that we made yesterday
3:29 - towards the end when we were experimenting there and so see there’s a whole lot of stuff in this
3:34 - folder right and that’s because when python sets up a virtual environment remember how i talked yesterday about
3:40 - how it’s basically building its own box um so you see here is another folder with
3:46 - uh a dot uh so-called doc files are configuration files and folders um so
3:52 - dot vs code is a folder containing files related to configuration for the project in visual studio code and that one’s our
3:59 - launch file which we’ll go ahead and update a little bit later today so now let’s go ahead and we’ll open up a vs
4:06 - code on your system again here so ps code
4:12 - and it should probably open in the directory that we have been in for our python example application here
4:18 - um so
4:25 - here was me trying to test my keyboard towards the end of yesterday
4:31 - all right so this was just our normal hello world application right um
4:36 - and uh so at the moment we are just in this directory uh remember we talked about
4:42 - the command line yesterday and do you remember what the three commands that we talked about were
4:48 - yes there was ls there was cd and um
4:54 - was the last time we just had clear uh just the command to clear the console stream right so we
5:01 - want to see what’s in this folder right here we do ls if we want to clear we do this and if we want to go
5:09 - oh i don’t know let’s go into the vs code folder uh we can cd there and then
5:14 - if we ls there we’ll see the launch file right and actually um so cd takes it as an argument it takes
5:22 - in a path right and by convention uh dot dot means the directory above the
5:29 - directory that you’re currently in so right now we are in the directory vs code
5:34 - and two dots means we’re gonna go one directory up python example so actually one dot one dot represents the current
5:41 - folder so if you do don’t slash like this if you do dot slash like this then i press tab it will auto complete to just
5:48 - the files in this folder so dot dot is the current folder and so we do dot slash and then i press tab it will auto
5:55 - complete to launch or it would if it was a directory but you know cd doesn’t operate on files but
6:01 - dot dot means go to the directory above this one so that’ll be python example here all right so that was just those
6:08 - were the command lines things that we did yesterday so right now what we are going to be focusing on
6:14 - is um making a virtual environment so if you remember at a high level uh what we talked about was that virtual
6:20 - environments take everything relating to an application and they kind of put it all in its own box so each application
6:27 - is running in its own box it doesn’t care about the other applications or what things the other applications use
6:33 - because we want all of our stuff to be specific to our application and the reason for this is if you globally
6:39 - installs things so you install it in like the global scope so if you try to install one package and
6:45 - use the same package in different applications but what happens if your applications all use different versions
6:50 - of the package and if you remember we talked some yesterday about this idea of deprecation
6:56 - of libraries that you use in your code not always staying the same sometimes they make breaking changes
7:01 - um and so if different applications depend on different versions of a library and you
7:07 - only have one version of the library suddenly you’re going to start getting bugs in your code and it’s going to be very hard to track down and keep track
7:13 - of and so why not all up front let’s just give each application its own set of packages
7:19 - that way when the application uses its libraries it won’t get hung up with
7:24 - other applications uh so uh usually this is just by far the most
7:30 - headache-free way to do this um you want your programs applications to not or
7:35 - sorry your programs libraries not interfere with any other programs so this is definitely considered best
7:40 - practice this is what you want to do um so if you install things to the global name
7:46 - space you don’t have to set up virtual environments arguably it’s a little bit easier but the problem is then then you start getting conflicts as you build
7:53 - more applications so we definitely want to start with virtual environments from the very first day
7:58 - unfortunately as you’ll see it’s really not that hard so that is what a virtual environment is
8:03 - conceptually it’s this way to organize all of the information relating to our application specifically so that it
8:10 - doesn’t conflict with other applications we want to keep everything isolated in its own box
8:16 - staying in its own lane basically so that even if we have multiple versions of python on our system or
8:22 - multiple applications depending on different versions of libraries none of that stuff will conflict with each other
8:28 - so conceptually does what i’m saying makes sense i think so i want to ask a question i
8:35 - hope will verify for me so if you’re working in vs code for example
8:41 - and we we’re building two [Music]
8:46 - uh applications it’s not what we’re talking about like
8:52 - um let me open that so here for example if if i’m making a
9:00 - storefront application then everything we’re working with all the information
9:06 - we’re working with is in one place if i were to be working on another application in vs code as
9:13 - well everything i all the information i’m using is also is that is that sort of thing you mean
9:19 - so it’s actually based on directories uh you remember at the very beginning of today i deleted the directory called
9:25 - venv within this folder so the virtual environment lives within
9:30 - your projects folder and so if you have two different projects they’ll be in two different folders with
9:37 - two different virtual environments i’m not sure if that’s answering exactly
9:42 - what you’re asking um yeah it kind of is two different projects
9:48 - will have two different virtual environments right now you can also have multiple python
9:55 - files in the same virtual environment um okay so
10:00 - there’s no reason why you can’t do that either it’s just the point is it’s a way for you to encapsulate
10:05 - a certain set of libraries and uh the python version you’re running with and
10:11 - all of that stuff you you basically say this is the standard of the things that i’m using
10:17 - here um this is like my list of dependencies um and so if you have multiple things to
10:24 - share the same list then they can live in the same virtual environment but if you have a different
10:29 - application with different requirements then they’ll be in different ones um
10:35 - i think what i want to be clear about is whether applications here is the same as projects or
10:41 - if they me if they mean something else i mean so generally speaking you would
10:47 - want you know an application uh can contain multiple functions that do multiple
10:54 - things right and uh especially as things get bigger you might you might break it into like modules like you might have
11:00 - one part of your application that oh i don’t know displays information to the user and another part
11:06 - that does like operations calculations on the information and you might choose to organize your code into multiple
11:12 - different modules but they’re all part of the same application right so
11:17 - i would say if you have one script that is uh i don’t know let’s say it’s doing
11:22 - something with video files you’re you’re like basically you’re sticking video files together on the command line or something that’s what one script does
11:29 - and then you have another script that like replaces text in some of the text
11:35 - files on your system those two scripts have nothing in common you really shouldn’t have those living in the same
11:40 - virtual environment you should split them up because those conceptually are two separate applications doing two different things right so one
11:47 - application can be composed of multiple components but
11:52 - i would track this in your head by you know like actually
11:58 - an application has a certain set of requirements that does a certain thing um you see what i’m saying
12:05 - when we call the storefront application that the what we were working on
12:11 - can we that’s the education is that sort of thing you mean
12:16 - yeah um but i mean i’m trying to see where the the
12:21 - disconnect is here um i mean i i understand it can be a little bit hand wavy because
12:28 - what is the difference you know obviously an application can do many different things and why do we call it
12:33 - one thing if it does multiple things right where is the line between one application and multiple applications
12:40 - i would think of it like this if you were a user would you conceivably ever use one part of it alone without
12:47 - everything else if the answer to that question is yes then they’re multiple applications if they answer that question is no then
12:53 - they’re not so in the storefront application would the user ever would the user ever
12:59 - be like uh for example making a transaction buying a product
13:04 - if they didn’t have the rest of the storefront running you know so they had to be logged in as a user and they had to know the other stores around them and
13:11 - things right you see how it’s all kind of dependent um and so the answer would be in that
13:16 - specific case they wouldn’t ever use that part of our application in isolation without everything else
13:23 - but if you have multiple things that really don’t depend on one another where
13:28 - you might conceivably use one all alone without needing the rest of it then arguably that doesn’t really belong
13:35 - in the same application okay so there it is so we have a project
13:41 - that’s actually made up of multiple applications is that it now there is a design paradigm uh
13:49 - especially in web architecture called microservices um this is getting a bit ahead of ourselves
13:55 - you may have heard of the difference between a monolith application versus microservices uh
14:01 - that is about microservices yeah so uh microservices the idea is you want to
14:06 - keep each application will do one thing and basically one thing only a separation of concerns uh there are some
14:13 - advantages when you’re deploying to the web scaling wise it load balance is better it can handle traffic easier uh
14:20 - if one part of your application goes down so i don’t know something handling like uh
14:27 - like updating user information or something well
14:32 - whatever in the wider application this network of of meshed
14:38 - microservices whatever depends on the thing that’s currently having problems won’t be accessible but everything else
14:44 - will still work whereas in a monolithic application if you get an error it will take the entire process down
14:49 - this also gets into how programs run on your computer you may have heard of
14:56 - multiple processes versus multiple threads that probably doesn’t mean too much to you right now
15:02 - but um if you have a single process that means that
15:07 - conceptually one thing is running on your computer and so if there’s an error in that
15:13 - process if if your program’s running there’s an error in the program since there’s only one program it’s going to like obviously kill everything right but
15:19 - if you have five programs running and something dies in one of the five programs then the other four programs
15:25 - can keep going right as long as they don’t depend on the one that died um so there are some advantages to microservices one downside
15:32 - of it is that well you have to maintain five separate things and they have to talk to each other at least much of the time they do they
15:38 - need to pass information or keep track of state it gets very complicated very fast um
15:44 - now we’re getting a little bit ahead of ourselves here but for the purposes of what what has its own virtual
15:51 - environment what is his own application i wouldn’t sweat the details for now um
15:57 - if there’s nothing bad is going to happen most of the time if you have multiple things in the same
16:04 - project because maybe much of the time maybe one part of your code will use a certain library but it’s
16:10 - probably not going to be used everywhere in your code right and so if things have slightly different
16:16 - purposes as long as they’re all kind of working together uh in one thing conceptually and like i
16:22 - said the lines can get really blurry because you might have an application that handles multiple different aspects of something and each function could
16:30 - arguably be its own thing but what i’m saying is is that there’s not a wrong answer to this um
16:36 - it kind of depends how you break down your code and you split it um for us right now we’re probably not
16:42 - gonna we’re not gonna be working on something so big that we’re gonna split it into a lot of different microservices that’s just
16:48 - i mean like that’s just this is not where you start anyway in development generally because it’s more
16:54 - complicated like i said you have to have them talking to each other and it adds a lot of of uh coding complexity even
17:00 - though there’s like performance advantages to it um okay i think i understand the virtual
17:07 - environment thing a bit more now so essentially it’s not that um [Music]
17:14 - your entire code will be will [Music]
17:28 - for our purposes right now anytime you’re writing one project everything will be in the same
17:34 - virtual environment um yes there’s a rule of thumb for now that’s what we’re getting more complicated
17:41 - when it gets larger and more complex and you might have multiple virtual environments well
17:46 - you might but you might not there’s plenty of large enterprise level applications that are still monoliths um
17:53 - in which case they would share the same package dependency the same library because the same thing is running so the
17:59 - answer is not it’s not it’s not as clear-cut as that um it really depends
18:06 - yeah um so for now i would just emphasize that if you have different projects so it’s
18:12 - easy when we’re talking about different projects right things that are obviously different and in those in those cases
18:19 - you have different virtual environments um where it gets messier is if you have one project but you’re splitting it in a
18:24 - certain way but just don’t worry about that for now that’s what i’m saying um
18:30 - okay so that’s virtual environments um managing all of your packages and dependencies uh in one place so that you
18:37 - don’t pollute the general system with it and cause conflicts elsewhere um
18:43 - so the command to make a virtual environment uh you can just copy this is our python program right we give it a
18:50 - flag the m flag for make virtual environment and then we name the virtual environment we give it a folder name and
18:56 - conventionally you put it in a dot a folder that begins with a dot these are
19:02 - hidden folders and this is the a folder called venv for our virtual environment so we’ll go down in our
19:08 - terminal here and we’re inside the python example folder this is where our test.pi file is and so we’ll go ahead
19:16 - and we will run this command to make a virtual environment and so
19:22 - when we run this command you see that we made the the folder there and vs code will say hey we noticed that you just
19:28 - made virtual environment you want to select it for the work workspace folder we’re going to go ahead and say yes this is the virtual environment we want to
19:34 - use for this project and then if we click yes there vs code will just go ahead and it will do the rest and so
19:40 - you’ll see right here the shell is actually working it’s kind of building stuff and you know that because you
19:45 - haven’t seen this thing right here um like the prompt that’s what it’s called we haven’t seen the prompt return
19:50 - to us yet so because of that we know that it’s just sitting here it’s it’s building stuff at the moment so it’ll take it a while
19:56 - because there’s a fair bit to scaffold into i mean we’re not we don’t really need to worry about what exactly goes on in the virtual environment but you see
20:03 - now the prompt has come back to us so that means it finished right um okay
20:08 - so uh the next thing you do after you build a virtual environment is you need to activate it because right now if we
20:14 - run a command to install a package right now it’s going to install it at the global level because the python we’re using is
20:21 - the global level versions of python and it’s going to install packages globally and so if we want to install a package
20:27 - only for this project in this virtual environment we need to do what’s called activating the virtual environment and
20:32 - so to do that um for us specifically here uh this is the
20:38 - this is the location of the script to activate it it’s in our virtual environment folder
20:44 - in a folder called scripts and the program is called activate and so if we copy this remember i said the
20:50 - current files path is or sorry the current directory’s path is just a single dot you see dot slash
20:57 - means we’re in the current directory we go into the virtual environment directory from the current directory then the scripts folder and then the
21:03 - activate script and the directory we’re in right now is python example and you can see that in the prompt here
21:09 - okay so we do that and once we execute that you’ll see now that we have this green thing in parenthesis over here
21:15 - telling us hey we have a virtual environment active yeah
21:20 - makes sense so now we’re actually in the virtual environment here anytime we install a package now we’ll install it
21:26 - inside of the virtual environment we run we run inside the virtual environment and things like that okay
21:33 - so that really wasn’t so bad right two commands right one command to build it the very first time and after you built
21:39 - it you never have to build it again after that the only thing you need to do is when you’re starting up your project you just need to remember to activate
21:45 - your virtual environment so that the things that you do to modify packages and stuff only happens inside of this
21:51 - specific space um and that’s it but for now for our purposes
21:57 - you don’t have to worry about anything other than that just make sure you remember to do it and that will keep everything nice and sandboxed on your
22:02 - system and that way your projects will never conflict with each other um
22:08 - but you know it’s another step in what we need to do to properly work on python projects locally here so that’s why we
22:14 - had to cover it
22:20 - all right so do you have any more questions here or are we good to go ahead and move on just for clarity in my
22:28 - head um the bush bits actually
22:34 - says we are we are still in the python example folder within that forward find
22:40 - scripts of our rather the personal environment right within the example we find the
22:46 - virtual environment folder then in the virtual environment folder we find the scripts
22:51 - right and then activate scripts
22:57 - so over here in the sidebar we can actually go find this so this is what happens when you expand the virtual environment folder so right now the
23:03 - folder that’s open in the sidebar is the python example folder so it’s this is
23:08 - its absolute path on your file system so we have the c drive users and then your name and then downloads because we put
23:15 - it in the downloads folder and then python example that’s the name of this directory here then inside that we have
23:20 - the dot v env folder which includes a scripts folder and the scripts folder
23:25 - includes something called activate so there’s a there’s a batch file and a powershell script
23:31 - um probably running the powershell script here so if we wanted to deactivate
23:39 - go ahead so when when we do the dot slash what we’re actually saying is that we we
23:45 - instill in the python example directory okay now it will work fine if we don’t
23:52 - so the thing is i auto-complete it and when you auto-comp so let me type it out so if we want to deactivate
23:58 - we can go to the scripts folder again and then there’s a script called deactivate which will deactivate our current virtual environment so
24:05 - this time i didn’t put um
24:12 - well i guess i guess we don’t have the deactivate here as maybe a control c out of it
24:20 - no well that gets rid of the terminal
24:26 - completely not entirely what we wanted um now we reopen it now we’re not active
24:31 - but uh all right well anyway um basically uh vs
24:37 - code smart there’s no reason why you’d want to be inside this folder without your virtual environment active so
24:43 - um i believe vs code smart enough at least i think it is in my project and i i think once you once you associate the
24:49 - virtual environment with this folder whenever you open this folder in vs code it will activate the version environment
24:55 - for you so you never have to actually remember to do anything to it again okay
25:06 - okay so that’s virtual environments now they’ll become important in a second here
25:12 - because oh my goodness why is it well i guess i can’t scroll through it
25:19 - so we were just talking about virtual environments um the next thing that we’re going to do before we get into
25:25 - packages here is we’re going to set up a way to launch our file so if you remember right now if we press
25:31 - f5 that’s the run command here or we go to this this view here
25:37 - we have something here this is called a launch configuration for launching the current file and so if
25:43 - we had more than one python file it would only ever launch the file that we were currently in which isn’t
25:49 - necessarily what we want if we had a main application file you know here let me actually do it just so that you’ll
25:55 - see so oops um let’s go here and let’s add a file
26:02 - called file file
26:08 - [Music] here’s an underscore child file dot hi okay so this one could be like a library
26:16 - or something and so we can just print here you know like
26:22 - inside file okay and uh inside test.pi let’s say this was
26:28 - our main file we could print um
26:35 - right here okay so if we are inside this file in the text editor
26:41 - um these two files will be different um so if we are inside the child file right
26:47 - now and we use the launch configuration that runs the current file you’ll see when we watch
26:53 - here that what gets printed out should be inside child here
26:58 - so it’s going to activate the virtual environment then it’s going to run child file and so you can say inside child okay and
27:04 - that’s because we pressed we we launched our launch configuration inside of that file now when we have this file active
27:11 - and we press f5 it’s going to say inside parent because we’re going to run it again
27:17 - so and get that out of the way um
27:22 - we’re going to run it again and now it says inside parent right
27:28 - okay so you see how what happens if we always want to run the same file no matter where we are
27:33 - because very commonly you’ll be breaking your code into multiple different files and then you’ll import stuff from one file to another once your project gets
27:40 - bigger most of the time you want to be running your project as a whole right not just the specific file
27:47 - you’re in so yes let’s go ahead and um so
27:52 - if we want to add the configuration this is going to open up the launch json file here and this is what it looks like
27:58 - so the file here it says is is going to take in this
28:04 - this app this thing right here rather than being an actual path right now is
28:09 - just taking in the current file um so let’s change this
28:16 - to say run the test application that’s what
28:21 - we’ll call this and then rather than passing in the current file that’s what this
28:26 - uh that’s what this thing does right here with the ah come on don’t cover
28:32 - with the file injected into the parameter there let’s just type in
28:38 - testosterone so from our application folder this is takes in the path to
28:43 - where uh the file that we want to run is and so um you know let’s just call this rather
28:49 - than that whole longboardy thing let’s just call this test like that and so now we just modified it so that our program
28:56 - will always launch test.pi which will contain the main program rather than the child one okay so if we
29:02 - save this file this file like i said yesterday this is a json file a json is
29:09 - you see these curly braces and brackets and stuff that is the syntax specified for storing information in json
29:17 - and so uh this is used for configuration of setting up now you could have your
29:23 - different things uh set up here so right now we just saved this we call this test so if we run test here
29:30 - um and this is the configuration that we use for launching then you’ll see that this should this should print inside
29:36 - parent because we’re just going to run test.pi um right there okay
29:42 - so now no matter which file we’re in even if i go over here to the child file and i run the program when i’m inside
29:49 - the child file like i am right here it’s still going to print the parent one because we set up our
29:55 - launch to always execute the parent does that make sense so
30:01 - um that that that means that if we make
30:06 - if we make a particular file the main file that we always want things
30:13 - to run there and build things like this child let’s just say child files like that what we
30:19 - would do is actually kind of connect the files between it
30:25 - between them and the parent so that when you walk around the main program it actually
30:31 - runs all the stuff in the other one that’s needed am i guessing
30:37 - okay so let’s say in the child file we define a function like this print message okay
30:43 - so it’s not going to take in any parameters we’re just going to print the string hello world okay so print
30:53 - hello world very normal you know beginner application here okay so
30:59 - uh this is the only thing for now that we’ll have in this file so right now the child file just contains a single
31:05 - function definition right yes so now if we come over to our test
31:10 - file over here what we can do is we can say from
31:16 - so we can actually import that function from
31:21 - child file yes i think this should work um
31:28 - we have print underscore message
31:43 - now uh we’ll find out real fast if this will work or not it might say can’t find it
31:49 - um
31:54 - oh no it works fine right it works yes so that’s the idea of having multiple
32:01 - files like that and deciding to make one in one that always runs if you if you
32:09 - set things up like that yep and then you’ll import things from your library your modules that you write into your
32:16 - main program file this is this is the way in which you write programs 100 of the time um if you have
32:23 - a big interconnected program you’ll break it down into smaller bits and pieces so that it helps you think about
32:29 - it so it’s easier to work on one thing at a time and then you’ll combine it all in your your main program
32:36 - that’s the one that you will always run um so in the launch setting here uh you know
32:42 - maybe you don’t call it test output maybe call it main.pi maybe you call it whatever but you’ll almost always be running just one file 100 of the time
32:49 - and you don’t need to worry about other things for now i mean eventually uh launching it you might launch it in a
32:56 - debug mode versus a release mode or launch it in a different environment for comparing if you’re deploying to a
33:02 - server we’re not going to worry about any of that for now for now you’re going to pick whatever file you’re designating your main file you’re going to set up a
33:09 - launch configuration for that and then you’ll reference any other files that you write in your main file
33:17 - since i understand okay great so now we’ve set up a launch
33:22 - configuration we can run our application here our test.pi application uh just by
33:28 - going to the run menu here i mean so it’s ctrl shift d if you want to always just pull this up immediately or you can
33:35 - just press f5 and it will run the currently selected watch configuration uh which is we only have one right now
33:41 - so um yeah we’ll get more into hotkeys and stuff later um very useful because they
33:46 - save you a lot of time once you’ve memorized them all right so um that is setting up our
33:52 - launch configuration here for our application um and uh oops i forgot i can’t use the
33:58 - scroll wheel because of whatever bug um all right so now that we have our
34:07 - uh application up and running the next thing that we might want to do is we might want to install a package um so
34:14 - packages are programming libraries they’re code that other people have already written and as much as possible
34:20 - we don’t want to reinvent the wheel so if someone else has already solved a problem that we want to solve
34:27 - why don’t we just use their code rather than writing it ourselves right it saves time and uh and you know just makes lots
34:34 - of sense right so um this what you see right here um pypi.org
34:41 - um i’m not actually sure how you pronounce it i’ve only ever seen it written pie pie maybe that’s probably how i pronounced it pie pie uh the
34:47 - python package index so pis is an acronym stands for package index this is where you go to find packages that you
34:54 - might want to use um so like trending projects well tensorflow very famous thing for
35:01 - machine learning um you know there’s another package called numpy like n-u-n-p-y uh that’s
35:07 - used a lot in data science stuff um you know different different packages used
35:13 - for different things um you know i mean as i most of these
35:18 - things probably don’t mean too much to us you know a cryptocurrency trading library all
35:23 - right interesting huh if you want to trade cryptocurrencies now there’s a python app there’s python package for that and what you’ll realize very
35:30 - quickly uh especially for popular programming languages um python is among
35:35 - the most popular so python c-sharp javascript java see
35:40 - i’d say probably those are the most common production leverages i think probably i’d have to go look at the
35:46 - statistics but javascript is probably the most common uh python it may be second
35:52 - java c-sharp are up there too all of these things will have packages
35:57 - to do most things you want to um every once in a while you will have to write stuff
36:03 - yourself but many many many of the things that you would want to do someone else has already written the code for now what
36:09 - your responsibilities developer will be is you need to go find a package that does what you want and then you have to read how to use it
36:16 - because even if someone else has already written the code you need to know what inputs to pass the functions for example
36:21 - and what the functions will return and the format that they’ll do things and you see what i’m saying right like
36:27 - just because someone else has already done the the coding part of whatever you want
36:32 - to do you still need to understand how to use it um and so uh this is where you go and actually not
36:39 - here i would not usually recommend that you go straight to pi pi and you try to find something what i would do is i would 100
36:46 - google how do i do x in python and on stack overflow or some other site you’ll
36:52 - come up with someone saying oh just use this library and then you go search for the library and pipeline right um
36:58 - and the reason why we do this is because you can find the official package uh the package names here and you’ll find the
37:03 - command to install them uh so i’ll give you the example that we’re gonna use use we’re going to use an example here for
37:10 - making a string url safe so it’s called sluggifying the string um so a url is this is this
37:17 - string that we put up in the address bar in our browser right you see right here it says programming dash teaching dash
37:23 - series right that has a dashes in the path well you don’t have spaces inside of urls i
37:30 - don’t know if you’ve ever noticed that but you don’t yeah and so there’s a certain way in which they’re formatted
37:36 - right and we’re not going to worry about some of the icky specifics of this but we’re just using this as a simple example um so
37:42 - if we want to take in an arbitrary string and we want to convert it in the format that will be like valid to use in
37:48 - a url so actually the slug is not this full path because we have things like
37:54 - the domain name up here uh the slug would just be the path once you’re once you’re in like the file structure part
38:00 - of it it would be like this uh rather than like the domain name and uh the connection type so if you http versus
38:06 - https and stuff like that or the port number we’re not gonna worry about any of that the slug is just like the name
38:13 - of whatever it is you’re doing right but if you have spaces in it it’s not gonna be a valid url right so if we want to
38:19 - take in an arbitrary name maybe of a file or a path on our system and then we want to make it in a form such that we
38:25 - can publish it to the internet it needs to be a valid url right so that’s what this package here will do so we’ll go
38:31 - open this package on pi pi um uh python dash slugify it’s a it’s a
38:36 - package here it takes in unicode strings and then it tries to to create a slug for it something that
38:42 - you can reference in a url um so you can see that there’s a version for python 2
38:48 - and a python 3. of course we’ll get the python 3 version when we install it here and when you go find it on slugify right
38:55 - you can see that you know like there’s a some information about uh who has this
39:00 - if we want to go look at this we could probably go find see if we go to the home page it
39:06 - looks like this this project is hosted on github which we’ll talk about towards the end of today this is one of those uh
39:14 - code repositories online so you can see uh the guy who maintains this
39:19 - um you know has you know a number of commits to it and the last commit was
39:24 - like it says like 30 26 days ago or something and you know you can see all the information this is
39:30 - the package uh someone has made this free to use and you can check the license on it that’s actually kind
39:36 - of important depending on how you’re using your project um different kinds of software line systems
39:41 - i don’t want to get off to uh uh too off topic here um if you see a license that’s either mit that’s this
39:48 - one or apache or oh what are other common one those are probably the two most common like
39:54 - so-called permissive licenses where basically if something’s licensed on mit when you use it in your own code you
40:00 - have to say hey i got it from this guy i didn’t write this you know you can’t like claim it as your own code but that’s about it like you can use it for
40:05 - anything uh commercial applications whatever um open source right um
40:11 - and uh uh licenses that are more restrictive uh there’s a license called the gpl license uh
40:18 - put out by the the gnu software foundation um so gnu is the acronym there uh the gpl uh
40:25 - they’re on version three now the gpl v3 is uh so-called copy left license that
40:30 - basically whenever you use that license anything that uses code that’s licensed under that also has to be open source
40:36 - and copy left has to use the same license um so it’s popular in the free software community that’s like really
40:42 - big on like privacy and uh you know open source everything uh but it means that commercial
40:49 - applications will tend not to use their code um so um i would say the vast majority of stuff
40:56 - on github is probably mit or apache um i i have to go check the statistics on it but um these are the open source
41:02 - licenses that are basically like yeah just make sure you give credit where credit’s due but other than that you can use it to your heart’s content um
41:09 - so this one’s mit right this is the package i mean you see they have some examples here and uh
41:14 - you know like different parameters and we’re not going to do anything complicated here right so there’s some regular expression matching and stuff
41:20 - but um so that’s where this package lives but to install it if we go on pi pi you’ll see that it just gives you the
41:27 - pip command right so we are using pip as our package manager here there’s other ways to do it but for
41:33 - now we’re going to use pip and so this will be the command that we run here pip install
41:38 - python-sluggify that’s all we need to do to install the package in our virtual environment so here we are if we go back
41:45 - here you’ll see that now in our terminal we have our virtual environment active right
41:50 - so we have this venv active and green over here we just copy paste that in
41:55 - here and we say pip install python’s lockify this will actually download the package
42:00 - for us and uh well okay i guess you have
42:07 - i just x out of that i don’t know if it’ll work but it looks like it’s gonna work okay so downloaded it downloaded it downloaded it successfully installed
42:14 - and uh you see it installed the dependency there’s a reason why i picked this one see text dash
42:20 - uh you you need decode right here that package well you might say but stephen we just
42:26 - installed this package why’d we install something else so this is the idea of the package dependency
42:33 - this is one of the reasons why managing packages is such a pain in the butt um because
42:39 - if one package depends on a certain version of something and another package depends on a different version of it you might end up with two versions of the
42:45 - same library neither one of which you actually thought that you needed because you didn’t say install this it just got
42:51 - installed when you installed something else right so hopefully what i’m saying maybe maybe
42:57 - this doesn’t sound so bad to you right now i guarantee this will cause pain and suffering no matter where you work um
43:04 - dealing with packages and wrangling packages and dependencies for packages and somewhere sometimes something will
43:10 - get messed up i promise you um it happens frequently enough that everyone has to learn how to deal with it it’s
43:16 - just one of the headaches of being a software developer if your application gets big enough especially so that you
43:21 - have multiple dependencies and you’re relying on a lot of other code each one of those things will have
43:26 - its own package dependencies which may have their own package dependencies and you get the idea right it gets very complicated very fast and uh easy for
43:33 - stuff to get messed up um now it won’t always get messed up right it’s
43:38 - not always doom and gloom but uh it’s just something to be aware of right so when we
43:43 - installed this you’ll see how there’s a number on the end of this this is the version number and this will be important we’ll talk about this towards
43:49 - the end of today when we talk about freezing packages um and setting them up in our requirements file so
43:56 - anytime this package the sluggify package here gets updated we don’t necessarily want to just automatically
44:02 - use the updated code in our application because what happens if it breaks something right remember we’ve been talking about that stuff gets deprecated
44:10 - or they add new features or they change how they do it so we in our application we want to use what we know works so if
44:16 - we say i’m going to use python sluggify whatever version i’m going to keep it at that version now one exception to this
44:21 - is you generally don’t want to let your versions of things get too too too out of date especially if they’re part of
44:28 - your application that deals with security because there will be security like patches there’ll be bug fixes or
44:35 - improvements related to security matters so especially if you have a package dealing with like network traffic or
44:42 - something that is like security related you will definitely want to keep those things up to date more and it’s just
44:48 - generally considered good practice to not let your packages get super super out of date but anytime you bump the
44:54 - version on something you might have to go fix a bunch of places where it breaks stuff um kind of unpleasant right this
45:01 - is part of software maintenance so i don’t want to get off on too big a tangent but i think i’ve kind of uh got
45:07 - up on my high horse a couple times and mentioned how uh software maintenance is like a way
45:13 - bigger part of the software engineering life cycle than actual development is so
45:18 - you will spend more of your time especially if you work for a big company who has big applications you’re going to
45:23 - spend more of your time dealing with something that already exists then you then you’re going to be writing something from scratch um
45:31 - and a big part of the maintenance is well when the application was written we wrote it in java 8 and like angular 5
45:38 - for example and now we need to update it to java 12 and angular 11. and when you do that update you might
45:44 - think oh well everything will just work one no it won’t um you’re gonna have to go fix all the places where it breaks when you update the versions on stuff um
45:52 - so yeah um no that’s enough on that um so this is packages this is our introduction to
45:58 - packages and um so now these are packages that we can use and so i have an example application
46:05 - that we’re going to take in now where we use the slugify package here i’m going to remember not to scroll this time
46:13 - so here’s our application so we’re going to import the sluggify package that’s the one we just installed and then we’re
46:19 - going to have a function called make url that takes in an input string and then it solidifies the input string to make
46:25 - it valid okay so in our project here uh we’ll go we can
46:33 - actually do this in the child file right there’s no reason why we can’t so um we’ll replace that very simple
46:38 - function we have there with this and so we’ll import slogify here and python will know what this is because we have
46:44 - the selectify package installed in our virtual environment right and um i’ll show you two different ways
46:51 - of calling this function right so this is going to import the sluggify package this likify package defines a function
46:56 - called sluggify so we do package dot function name and we give it our input
47:02 - so that’s how we’re going to call this right now and over here we’re going to go
47:07 - make our url so we no longer have that function name now we have something called make url so we
47:13 - need to make sure that we’re importing the right thing from our child file here so we’re instead of importing print
47:18 - message we’re going to import make url and we’re going to call make url
47:24 - with oh what shall we do something like huh this is a
47:31 - file name so we need to make it a string
47:36 - okay so this right here is not something that can be part of a url right it’s got spaces it’s got an
47:42 - exclamation point right so let’s go ahead and let’s print
47:48 - what happens when we make this a url right so that should
47:55 - what what how this will run when we run the test.pi file because remember that’s what we set up in our launch
48:00 - configuration it’s going to run this file but this file imports a function from the child file that we have which
48:07 - imports a package defines a function that calls the package to modify the input string
48:14 - is everything i just said makes sense yes it sounds really complicated right but
48:19 - you see we only have five lines of code here but this is why it’s so important for us to understand
48:25 - what’s calling what why does it call it how does it work how does python know where things are right if you actually
48:32 - understand how this runs you’re gonna be good to go uh basically your programs can get pretty large you
48:39 - can make lots of different function calls but the actual mechanism for how things are connected won’t be much
48:45 - different than this like ever like this is how python knows uh how to call libraries and how you call a local code
48:52 - files here you do import statements right so if you want to import a function you do uh from module name import function
49:00 - right that’s this syntax here and over here we have just import module and then you call it as module.function name so
49:07 - typically this format right here is what you’ll do because usually you won’t need everything that’s in a module you’ll
49:12 - just need a function or two right but i started us out over here with the whole module just to show you that it
49:17 - does work fine if you do it this way too it’s just usually it’s considered uglier because then you have to like put the module
49:23 - name in front of the function every time you call it right um okay so let’s go ahead and let’s run i
49:30 - actually haven’t run this i really hope it works because i was just
49:35 - coding this off the cuff here um so it did right and you see this is a file
49:41 - name exclamation point gets turned into this dash is dash a dash file name right
49:47 - and that is something that would look just fine in a url right yes
49:53 - okay all right so let’s go ahead and let’s try doing the more elegant approach here
50:00 - so we know that we all we want to do with our selectify package we want to call this logo function
50:06 - so uh what that means is that we want to do from module name so our
50:12 - module that we’ve installed is called slugofont and you can just take my word for it but the function that we want to use from
50:18 - the sortify module is well it’s actually called the same thing it’s called socify but if we do this we don’t have to we
50:26 - don’t have to include the modulate anymore right so we’re saying from the sockify module import the sluggify function and now it looks prettier right and this
50:33 - is especially important once your code gets bigger right right now we only have like one thing so it doesn’t really matter that much but um
50:39 - eventually eventually you might have a whole bunch of different library calls that you’re making and it’s much more convenient to
50:45 - call it this way because it’s easier to read in your code it’s not so cluttered right
50:54 - understand that the two sluggifiers mean different things
51:00 - one of one of them is is the actual [Music]
51:05 - thing we’re using and the other one is what contains the things yep yep so the
51:10 - official terms for that would be the the thing that contains the thing uh it’s called it’s called the module um
51:16 - or the library right um and within that module within that name space you might also hear it referred to as that is a
51:23 - function or a method and that is what we’re calling right because you invoke or call functions and methods with
51:28 - arguments like this right so open parenthesis close parenthesis we’re calling a function here it’s contained
51:34 - inside a module that’s actually kind of confusingly named the same thing um
51:39 - generally actually probably kind of frowned upon if you can make your module
51:45 - not the same name as functions and it’s probably better because then at least it’s a little bit clearer to people
51:50 - right um yes i mean this isn’t wrong there’s nothing wrong with it it will work just fine the compiler or the
51:55 - interpreter for python will know the difference between the two of them but um
52:00 - and it knows the difference because the syntax of this statement here is you from a module you import a function
52:08 - that’s how this reads that’s how the interpreter interprets it um so you never write from function name
52:14 - import a module that doesn’t make any sense right because functions don’t contain modules modules contain functions
52:24 - all right so we’ll just keep on going um nothing we’re doing today i just i i hope not i hope nothing we’re doing
52:30 - today is super duper hard um this is just all the basic framework stuff that you need to write
52:35 - python applications locally uh in your your vs code environment in your virtual environment you know setting everything
52:41 - up uh getting it uh integrated now now you know how to uh find packages you
52:47 - know you find a stack overflow that says hey you should use this package you go look the package up on pi pi and then
52:52 - you you find the pip command to install it um after you install it in pip
52:58 - you can then reference it um by importing it you do have to use the import statement you can’t can’t
53:03 - reference it before you import it but after you import it then you can use it in your code as if it were your own code so
53:08 - very critical part of programming is learning how to use other people’s code so that you don’t have to do it all um don’t
53:15 - reinvent the wheel ah i did it again all right so
53:22 - we only got a couple more things left uh the next thing that we’re going to talk about now is we’re going to talk about
53:28 - keeping track of all of the libraries that we’re using in a requirements.txt file so let’s say
53:35 - that you’ve made this application here and you want to send it to me and i want to be able to run your
53:40 - application well right now we only have one library file so you might say hey steven uh you just
53:46 - need to go download this logify package right so as long as you download this logify package
53:52 - you should be able to run my code and it should work just fine because what happens if you try to run the code without having this package installed is
53:58 - you’ll get an error it’ll say i’m sorry i can’t find sluggify what’s likify um
54:03 - and so that’s what will happen if you don’t install the package first right we installed the package with the pip package manager for python but when you
54:11 - share your code with someone else their system is just not going to inherently have that package right and so you could
54:17 - tell them verbally hey you need to download this before you run my application but what happens when it’s not just one package or two packages
54:24 - what happens when it’s like 50 packages and also don’t remember that for to run
54:29 - our application you might think ah but you see i’m only importing things from one place right but you remember how
54:35 - actually two things got installed right so when you share your application with your friend
54:40 - you’re well i mean actually you can just install sluggify because when they install it it’ll install the other one but technically they’re actually installing two packages um
54:48 - and so all of this is the reason why typically you want to
54:54 - track which packages you’re using somewhere these things are called configuration files right we have a
54:59 - configuration file for setting up our launch the the
55:04 - specific parameters of how we’re launching our application well here we’re going to have another configuration file for specifying which
55:11 - packages we’re using and what version of those packages we’re using right um so i’ve made a pretty big deal today
55:17 - talking about how important it is to keep track of your packages and which versions you’re using and not just
55:23 - automatically bumping versions because it might break stuff and all that um so python’s way of doing this they they
55:29 - typically i mean it’s different across different programming languages you know there are some patterns here um you know
55:36 - many programming languages might use like an xml document for this uh a project file or whatever that’s what c
55:41 - does but for us here we have a text file that contains a list of packages called
55:46 - requirements.txt so the way in which you want to make this file you should not make this file by hand let me repeat
55:54 - that you should not make this file by hand um whatever package manager you’re using
55:59 - will have a way to freeze the packages that your project is currently using and you will want to use that command to
56:05 - build your requirements file because the program’s smarter than you it knows exactly which packages and which versions you want to use now you can
56:12 - update this if you want to say hey you should have this version of this package or greater
56:18 - you know maybe you do that or this version or less than or equal to this version or exactly you go to this version like you can tweak stuff about
56:24 - that um so i have a good link here you know someone’s blog um and uh on this person’s blog they go
56:31 - over uh some of the stuff you can do uh as being kind of slow come on let me
56:36 - click
56:42 - ah well lag um so this person has a good guide to it i’m
56:48 - just taking the the main the main takeaways but i think they have some examples he see here’s the comments so
56:54 - aversion matching minimum version version excluding anything but this version compatible version you get the
57:00 - idea right there’s this is the syntax for we’re not going to worry about it for our purposes you really don’t have to worry about it you’re just going to
57:06 - always say hey i want this version and that’s what most people will use like 90 of cases that’s all you care about so
57:12 - we’re going to let the package manager build our package file basically so we’re going to copy this command here
57:17 - it’s called the freeze command so we’re using the pip package manager the pip package manager has a command called
57:23 - freeze and we’re going to save the output of this into a file called
57:29 - requirements.txt now for now you can just copy paste this command i don’t really want to get into
57:34 - this thing right here is actually directing the output of this away from the command line and it’s
57:41 - going to output it into this text file if you don’t have this it will just print it to the command line
57:46 - so this is so-called redirection operator um but don’t worry about it for now just copy this command and use this
57:51 - command so we’re gonna go to vs code uh we’re in our virtual environment right so now
57:57 - we’ve installed the package we’ve run our we’ve run our application we want to be able to share it with someone else so we’re going to go ahead and we want to
58:04 - build this file called requirements.txt that will contain a list of the packages that our program depends on okay so we
58:10 - run that command and inside of our project if we go look now it made a text file
58:15 - called requirements right if we open this text file hey look there’s our selectify package and here’s the thing
58:21 - that this like package depends on right and it says version double equals these so to run the application that we’re
58:27 - building here you need the python dash slugify package and the text.unidecode package right which is a
58:34 - dependency of this but you know in the requirements file
58:39 - this is how it will install them okay so what we just did make sense right we took the packages that we had in our
58:46 - virtual environment and we ran a command with our package manager that said hey i want to figure out what packages i’m
58:52 - using right now and i want to save those to a file and then i can share that file with other people
58:57 - okay so now let’s say that you sent this to me and i’m on my installation and someone else gave me a requirements.txt
59:04 - file and i said hey uh here’s my application here’s all the code i have but you need to install your
59:09 - packages first so to do that you’re also going to use pip right so we saved them with the pip we’re going to install the
59:15 - requirements file so pip has another command called install so we have the freeze command we have the install
59:20 - command right for now don’t worry about the dash r that’s a command line flag telling us to do it i think it’s recursively i’m not
59:27 - actually sure what the flag is whatever i could look at it um but we go here to
59:33 - our virtual environment right so let’s say that i didn’t have these right in fact i’ll show you what happens when we
59:40 - do this right now it’s going to say hey you already have these packages basically it’s not going to like error it’s just going to be like no we didn’t
59:46 - do anything you already have it right but if we didn’t have these packages
59:52 - then it would install them for us right so it says requirement already satisfied we
59:57 - already have this package and here’s where this package lives right so
1:00:03 - saying that it’s already insight packages for us but if we didn’t have these packages and you sent me this file right here
1:00:09 - i would actually go ahead and install the packages so do you want me to show it to you like
1:00:14 - we could make another python project and you know take this requirements file and
1:00:19 - then run this command and it would install the packages or you can just take my word for it um that it does that
1:00:24 - i think it gets it’s how it works okay so you know what maybe maybe
1:00:30 - uh as an exercise you can make a completely separate python project and in fact i think that’s what it would be
1:00:36 - good for you to do we’ve done a lot of things right we’ve set up the launch configuration we’ve set up a virtual
1:00:41 - environment all of these things you want to do this at the beginning of when you set up a new project so probably before
1:00:47 - we next mean i’ll have you go ahead and just make a new project doesn’t matter what the project does it can even just be a hello world application but for
1:00:53 - that to be correct for you to get full marks you’re gonna want to uh you know make a new directory set up a virtual
1:01:00 - environment set up a launch configuration to run just the main file uh install a package and then uh
1:01:07 - you know get a set of package requirements and put them in a text file like this so that anyone else who uses
1:01:12 - your application will be able to install the requirements right and all of that once you’ve done all of that you’re kind
1:01:18 - of finally done now you’re ready to go develop your python application and then you can share it with people right
1:01:25 - so uh what we’re going to close on today then is we’re going to talk about version control okay so now great our
1:01:31 - python environment is set up we have the ability to run it in a virtual environment where we have all of our
1:01:36 - packages and we’ve frozen our packages we put them in a list so that someone else can use our application now they
1:01:42 - can install all the package dependencies so we’re ready to go write code right but then the question is how do we share
1:01:48 - code with others how do we develop our project on a team of developers and
1:01:53 - that’s where this thing called version control comes in so today we’re just gonna go ahead and install things for
1:01:58 - you uh we’ll talk about next time we meet we’ll talk about how you use it um this is pretty complicated um
1:02:06 - uh you know we’ll go over some of the more basic cases but there are some some
1:02:12 - parts of git that you know even i try not to touch too much just because it gets very confusing and uh it’s kind of
1:02:18 - buggy but not buggy gets not buggy there’s you know millions of people use it but like it’s easy to make mistakes
1:02:23 - with it um but version control is a completely essential part of being a software developer on a team um so if
1:02:31 - you’re on a team of software developers you’re going to be all working on the same project you might even be working on the same files and you want to make
1:02:37 - sure you don’t step on each other’s toes and so how do you do that you track the changes to your files over time with the
1:02:43 - version control system so git git is a version control system there’s others uh subversion and
1:02:50 - mercurial are probably two of the other famous ones but a git probably is the most popular probably used by the most
1:02:55 - projects um so version control systems at a high level they track the changes that you make to files over time so they
1:03:01 - show you what you’ve added and what you’ve removed from files right uh you and everyone else on your team right and
1:03:08 - so today like i said we’re just going to be downloading and setting up a couple of tools we’ll get into specifics uh
1:03:13 - next time so the first thing that we’re going to do is we’re going to go ahead well actually first let me check if you
1:03:18 - haven’t i uh i guess we’ll find out so
1:03:27 - at a high level any questions while we’re waiting on this to pull up any questions about what version control is
1:03:32 - or why we’d use it um and if you don’t 100 get it right now it’s fine because we haven’t really done any examples with
1:03:38 - it but um yeah you don’t have to have a question right now i think i get
1:03:45 - the concept of it okay
1:03:51 - so uh we’re going to use git um it’s the one that literally like um
1:03:57 - working in a google docs with with other people that’s how i’m thinking of it
1:04:03 - except that of course that gets
1:04:08 - gives you a record of changes google docs does
1:04:14 - well it kind of does but you structure the changes that you make into things called commits
1:04:20 - and so you may have heard this before a commit and get is basically it’s a set of changes a change step that’s what a
1:04:27 - commit is in kit and um the other big difference between uh git and google docs is on google docs
1:04:33 - you everyone is sharing the same copy of stuff in git there’s one centralized copy on your
1:04:39 - remote git repository and then everyone else has a local copy where they can do stuff themselves and you you i mean i
1:04:47 - don’t want to get too off in the weeds here git also has things called branches which is basically you take a copy of a project and then you clone it and then
1:04:54 - you do stuff to the clone and before you change the original you want to say hey guys do you like the changes i made and then other people can
1:05:00 - improve your changes or reject your changes and and if they approve them then that branch that you made
1:05:05 - uh so-called get it gets merged into the main branch right so that change set that you’ve adopted or uh you might
1:05:11 - actually have multiple changes that multiple commits on a branch if that gets merged back into the main one
1:05:17 - then you change the shared version but otherwise you’re just changing your version um
1:05:24 - so if i lost you there don’t worry um get it’s not the easiest thing once you
1:05:31 - learn it you learn it once you’re good though um and you’ll use it all the time so um
1:05:37 - now we may as well just install it as a normal setup you can also install a portable version of it if you want to run things off a flash drive i don’t
1:05:43 - think we care that much here so we’ll go ahead we’ll save the 64-bit installer here you’re probably gonna
1:05:49 - have to enter your you know admin password and all that great stuff for us setting it up
1:05:56 - okay okay so this one is an installer we might be able to start with chocolaty i guess i just haven’t ever bothered
1:06:01 - because i don’t know um i’ve installed it with the installer before uh it was pretty
1:06:06 - shame on me you know i was encouraging you to use chocolatey the other day and here i am not using it um but
1:06:14 - we could have used it to do the installing is what you’re saying uh maybe i’m not actually sure um chocolatey doesn’t have all packages
1:06:21 - like ever it has many things um but i it doesn’t i mean
1:06:26 - like honestly you’re never gonna really update git um i mean you probably can but yeah i mean like it’s been around
1:06:33 - for a long time since the 1980s i think um so all right so
1:06:39 - here here’s that you remember i said the the general the gpl right oh look at this
1:06:44 - uh git is licensed under the gpl version two um
1:06:50 - open source software license so okay okay
1:06:56 - lag
1:07:03 - actually i can’t i can’t touch that window so you go ahead and you do this you can press next
1:07:09 - that’s fine press next uh let’s see
1:07:14 - okay so uh if i were you i would uncheck the windows explorer integration
1:07:21 - you don’t really need that um and
1:07:30 - yeah that’s fine okay so you can press next
1:07:35 - and that’s fine that’ll let you open it from the start menu
1:07:42 - uh i would go see what’s in that drop down um you probably don’t want bim
1:07:49 - uh i would use visual studio code
1:08:06 - that’s fine
1:08:15 - so tell me if you see if you can figure out what this is saying um
1:08:21 - this is base this is related to something we talked about yesterday so
1:08:35 - this option has only [Music]
1:08:43 - do you remember when we were talking about the path yesterday and what the path represented
1:08:49 - yes um essentially let me see if i can put it in words and
1:08:56 - make sense to me okay so the path is um
1:09:05 - i okay the way i’m thinking of it is this is how the computer can actually
1:09:13 - launch something or run something
1:09:18 - that’s how i understand the path i’m not sure if i’m getting there i mean it’s
1:09:23 - the set of things that the computer knows how to execute right you know you point it you point the computer to
1:09:30 - here’s the things i want to be able to run right and so the difference between the first radio button here and the
1:09:36 - second one is if you check the first one it’s not going to actually add git to your path it’s only going to add it to
1:09:43 - the environment variables for one specific shell and that’s git bash which i’ll show you in a sec the second one is
1:09:49 - well you might want to be able to use git no matter what command line you’re on right that’s why this is the
1:09:55 - recommended one right um is that is that this will let you use git no
1:10:02 - matter what shell you’re in so powershell command prompt and git bash will i’ll let you use git this is
1:10:07 - probably what most people want but what it will do is it will add it will add the path to get to your path
1:10:15 - variable your system path variable so if you didn’t want it on your path well suddenly now you have things there that
1:10:20 - you added right so if you want it it’s great if you don’t want it well then you wouldn’t want it there right that’s why they give you the choice um okay so okay
1:10:29 - we’re gonna want it there because the default uh the default terminal in vs code i think is powershell and so we’re
1:10:36 - 100 gonna want to be able to do git stuff right so uh if you want to leave that that one checked that’s the right
1:10:41 - one
1:10:49 - okay all right now that’s fine um
1:10:56 - that’s fine too
1:11:10 - yeah keep that
1:11:20 - all right keep that
1:11:29 - keep that
1:11:35 - uh that’s fine we’re going to be using an ssh key eventually anyway
1:11:43 - uh that’s fine
1:12:01 - hey don’t worry about it i shouldn’t check anything yeah don’t
1:12:06 - don’t check anything those are like beta features just go ahead and press install
1:12:13 - all right so i’m just gonna install some library extensions here um and uh
1:12:19 - this will probably be the the biggest thing we install now um
1:12:25 - can you go ahead and click can you click on your browser again um
1:12:30 - so that i can do things again all right so we’re going to go ahead here and we’re going to look for
1:12:37 - another application called sourcetree now sourcetree uh interfaces we get it’s
1:12:43 - like a graphical user interface for it so git is a command line program for the most part um
1:12:49 - but what happens if you want to be able to see the changes that you’ve done like this so you see this it tells you what
1:12:56 - you’ve added and what you removed and this nice pretty file it shows you where the additions are and stuff and you can see all the files in your change set
1:13:03 - blah blah blah um so uh sourcetree is one of the two big
1:13:09 - graphical user interface front ends for git another one is called github desktop
1:13:14 - so obviously github desktop is made by github um sourcetree is made by a company called atlassian that runs
1:13:21 - basically a competitor to github called bitbucket we actually use bitbucket at work previously we were using
1:13:28 - microsoft devops but you know you don’t care about any of that i use sourcetree is the one i’m familiar
1:13:33 - with they’re all basically the same so it really doesn’t matter that much um but i’m actually pretty opinionated
1:13:40 - about this i really think that for most people it makes sense to use one of these programs rather than doing everything on the command line sometimes
1:13:46 - you may want to hop on the command line if you want to do something more complicated because the command line lets you script it you can use multiple
1:13:52 - arguments etc etc but for general day-to-day use i recommend most people use one of these visual programs i just
1:13:58 - kind of makes it easier to think about and see so we’re going to go ahead and we’re going to install this as well so if you
1:14:04 - want to go back let’s see what the progress of our git installation is here
1:14:11 - okay so i would go ahead and check that launch get bash and uh
1:14:16 - and it will open up a terminal uh when we do this and so now you will have a new shell on your system so
1:14:23 - uh we installed this thing hopefully i can i can touch this window okay good um
1:14:28 - so i see this is actually a unix shell um so
1:14:34 - we’ll get into that eventually powershell is actually a different shell language than uh bashes so this is
1:14:39 - called a bash so bash is one of the most common probably the most common shell scripting language um a shell scripting language
1:14:47 - is kind of like a programming language but it’s kind of suited for doing stuff on the command
1:14:52 - line uh there’s actually a large segment of people who think that shell scripting languages are stupid and we shouldn’t have them and so there’s some people who
1:14:58 - made a shell for python basically where you just write python on the command line because you know that makes sense right why are
1:15:05 - we learning a separate thing and also the way in which bash makes you do things is like really confusing in some
1:15:11 - ways and so why don’t we just use a real programming language there’s also other shells there’s like a c shell
1:15:18 - where that lets you write c on the shell although python is much prettier than c so if you’re going to pick a programming
1:15:23 - language i’ll add 100 go for one of the python ones um although it’s a little bit slower of course um but at any rate
1:15:30 - um this is bash so um are we ls here you’re in your home directory um and so this is
1:15:37 - the same thing as what you had before it’s a little bit prettier you know see it’s got some uh
1:15:42 - it’s got some you know like uh uh colors here for different folders and
1:15:48 - stuff and so if we want a cd into documents we can still do that we can still ls
1:15:54 - we can still clear right all the same all the same stuff um okay now but what this will let us do is
1:16:03 - if i go back up remember i said dot dot takes you back to the parent directory right
1:16:08 - and i want to go in the downloads folder okay well i’m just going to say i can’t find that so downloads right then i want
1:16:15 - to go into our directory for python test right so we have python
1:16:21 - that’s what we called it right oh i think we call python example yeah
1:16:26 - you’re right okay so now we’re in this directory here’s what’s in this directory right
1:16:32 - so um i mean oh so
1:16:38 - uh this is a command cat is a command on the command line that shows you what’s inside the file um basically uh sticks
1:16:44 - it on the output so that’s the file we know we’re in the right place here right all right so um just to test our git uh there’s a
1:16:52 - command for git called init this will set up the scaffolding for a git repository for whatever folder you’re
1:16:58 - currently in right so we’re in we’re in this python example folder right to test if we have git or not we’re going to go
1:17:04 - ahead and run the git to knit command and then if we ls again you should see a dot get well
1:17:10 - um don’t worry about that for now um this shows hidden uh commands and folders uh the dash a stands for all the
1:17:17 - dash l stands for like the list view that shows us everything right but you see how now there’s a folder here called
1:17:23 - dot git so if we go open this up in your vs code it’ll be clear in vs code um
1:17:30 - is actually vs code won’t show it because it has a separate thing for source control here
1:17:43 - i think it just needs to be updated
1:17:51 - now it should probably show up okay yeah so now source control is there
1:17:58 - if we go to the file tree what i just did was i ran a command called uh reload
1:18:03 - window here uh if you press control shift p in vs code it will take up a command
1:18:09 - window here that lets you run a bunch of different commands um and uh control p in vs code will
1:18:17 - let you search between files now we’ll get to all that later okay but anyway in git bash we’ve now made this new folder
1:18:23 - here you see how it says dot get right that means that now this thing is a git
1:18:30 - repository and so um you know uh
1:18:36 - so i suppose i don’t need the l if i just do a now you see that gets there right um all right so that means that git is set
1:18:42 - up and it’s working properly and we could do more things like commit and push and merge and stuff but we’re not gonna do any of that today we just
1:18:48 - wanted to make sure that we got it installed so now we’re gonna download sourcetree uh
1:18:54 - hmm what was that that was the release notes that we had so we’re going to go ahead and download sourcetree so that we
1:18:59 - have a visual front end for this blah blah blah assuming you are fine with their
1:19:04 - software policy which is normal stuff okay so we have another setup thing here
1:19:10 - that we’re going to download
1:19:15 - and then you’re probably going to have to do this again i mean it’s kind of logical right if you’re sharing someone’s screen that
1:19:21 - they wouldn’t let me just like take over control of your computer and install whatever i want you know it’s kind of a
1:19:27 - security risk
1:19:38 - well i can’t see anything that’s happening right now maybe it’s just being slow yeah it’s slow it’s actually
1:19:46 - right okay i would say install anyway yeah
1:19:54 - so are you on windows 11 then no this is windows 10 i use those ten still okay yeah
1:20:00 - just wondering because that didn’t look real familiar to me all right well
1:20:06 - looks like it’s opening that’s what the normal opening looks like or is it just going to be an installer i
1:20:12 - guess we’ll find out in a second
1:20:33 - okay so there’s bitbucket server bitbucket
1:20:38 - will i do anything with all that
1:20:45 - i guess you’re gonna have to create an account um
1:20:51 - so i guess we’ll have to do that um you know what let’s pause the recording
1:20:56 - real quick and we’ll go ahead and do that off screen and then we’ll pick back up to pick back up once you’ve done that
1:21:04 - all right so we picked up uh have a source tree installed now logged into an
1:21:09 - account uh with the atlassian folks and so the last thing that we’re going to do here today is we’re going to go ahead
1:21:15 - and we’re going to add the new git repository that we just made if you remember we on the command line here we
1:21:20 - did a git init we made a an empty git repository in our folder for our example python application so
1:21:28 - we’re going to go and we’re going to actually get that imported into our visual get tool here so we’re going to
1:21:34 - go to downloads where we have it right now and we have our python example
1:21:40 - and this is the folder in which we have our git repository so we’re going to go ahead and we’re going to add this right
1:21:46 - and it would give you an error it would give you an error if this wasn’t a git repository it would say hey you can’t do
1:21:52 - that okay and uh over here it’s going to show us all of the files that we have staged and you
1:21:58 - can actually see these are all the files that are living inside of the virtual environment but i bet you didn’t know
1:22:03 - that these things were there huh but you see pretty long bar right um so we get down towards the
1:22:10 - very end and then we have some vs code launch and then you know here’s our here’s our watch configuration file that
1:22:16 - should look familiar right um yeah so before we do anything else uh we will
1:22:22 - make a file called a git ignore file so here’s our here’s the files that we’re expecting right there’s our child file
1:22:28 - here’s our test file here’s our requirements file um and so if we add this it would let us make a commit to
1:22:34 - the repository right so-called stage file we’ll talk about all this tomorrow or not tomorrow whatever next time we
1:22:40 - meet um but you see now we have the git repository loaded in this program that lets you see what the files are you see
1:22:46 - the contents over here you’ll be able to see additions and deletions from it all very kind of clean easy to use right
1:22:52 - um so that was actually the last thing that i was going to have us do today so let’s go and briefly recap before we
1:23:00 - finish here so this is what we did we just finished installing git with git bash that command line version of it
1:23:06 - here with the unix shell or uses bash and uh so we did that
1:23:11 - we got git installed we downloaded source tree um i guess actually the last thing that we were going to do is we were going to go ahead and look at
1:23:18 - um github.com so for now i’ll mostly just take you here um
1:23:25 - actually we go look at one of my repositories i suppose um so github is uh is basically where people push code
1:23:33 - where they host their their applications their projects you have to update your code somewhere especially if you have
1:23:39 - multiple people developing to it um uh you know you have to store it somewhere right so bitbucket which is
1:23:45 - what you just made an account for to use uh sourcetree well bitbucket is basically the same thing as github it’s
1:23:51 - another option uh there’s pros and cons between them they’re both uh used a lot github is probably the
1:23:56 - most uh the most prevalent one so if you want to see the bible teaching ministry that i have
1:24:03 - right so this website um that you know i’ve obviously been working on for a while now you know still haven’t
1:24:08 - completely launched but uh you know hosted with the top bar and the sidebar and all this so this is what the website
1:24:14 - looks like well this is actually posted on github so
1:24:19 - if i search for it on github um you’ll come to see that i’m actually
1:24:25 - hosting this on github as the application platform so
1:24:31 - you know this is me this is my account stephen tamman that’s that’s me and so you can see well look you see remember that file
1:24:38 - that we have there vs code right remember how we had a vs code file that had a launch dot json file on it well
1:24:44 - guess what i have oh look at that
1:24:50 - and so i have a python application embedded in this website and that python
1:24:55 - application is the one that you’ve heard me talk about more recently here it’s a python application for pre-processing
1:25:01 - the content to build slides from it and in fact knowing what you know today you should know more or less what that
1:25:08 - thing is right we’re saying from this module app module setup right
1:25:14 - import a function called clean slides directory right that’s what that’s doing and then look a for loop and uh you know
1:25:20 - all this you should maybe you don’t know exactly what stuff does but you should be able to look at it and kind of know the gist of it right um
1:25:28 - so it’s the power of programming but yeah this is what github looks like um so we’ll talk about commits and branches
1:25:34 - and pull requests and we’ll talk about all that stuff once we start talking about git but another cool thing is it shows it shows you what programming
1:25:41 - languages are being used so you can see 68 of my site is html right and then i have css css python javascript right um
1:25:50 - but there you go um so this is an example of a remote code repository um
1:25:56 - you know in fact another cool thing that github lets you do is it lets you make a board uh for tracking all the work
1:26:02 - you’re doing on your project the so-called uh kanban board here or kanban i’m not actually sure how you say that
1:26:07 - word um again must have seen it written so here’s a whole bunch of in progress
1:26:13 - stuff well actually i haven’t really been tracking to work on my website with this for a while because you know i’ve had so much and it’s been changing so
1:26:20 - rapidly but if you’re a good developer and you’re on top of things you can track all of your issues here and something like this
1:26:29 - so well there you go um so i was just gonna show github this is
1:26:37 - probably where we’ll push code um so as we get things set up here as we move forward in our programming teaching
1:26:42 - series i will actually make a repository here and then i’ll have you pull it down and then we’ll both be we’ll both be
1:26:49 - working on code in the same repository that will be up here at public on github right um so
1:26:55 - we can build an application together basically where both you and i will be able to contribute to it um
1:27:01 - and uh more specifically what i’ll do is i’ll post a bunch of practice problems to the git repository and then you can
1:27:06 - work on them and then i’ll post the solutions the next day so you can check yourself against them um
1:27:12 - okay okay all right well that’s where we’ll cut for today um so i’ll go back through
1:27:18 - some of the things we’ve talked about real briefly before we stop here so um that was our git preview so what we did
1:27:24 - we started today just mentioning uh anyone else in the future who uses chrome remote desktop for something like this make sure your browser extensions
1:27:30 - don’t get in the way like they did for us we talked about virtual environments uh specifically setting them up in vs code
1:27:36 - an integrated shell there setting up a launch configuration of vs code it’s a json file
1:27:42 - we talked about python packages the python package index and the pip package manager
1:27:47 - we talked about package dependencies and why we freeze them in the uh
1:27:53 - the virtual environment right we talked about the requirements.txt file that you build by freezing your requirements and
1:27:58 - you can install them or someone else can install them when they run your application and then finally we got some
1:28:05 - tools for git setup to use and we’ll talk a lot more about git and version control next time we meet and how all of
1:28:11 - that will interface with the python applications that we’ll be writing here but as off leaving today uh you now have
1:28:18 - everything you need to develop python applications locally in vs code um so if you’ve followed everything we’ve done
1:28:25 - the last couple times we’ve met you should be able to make a new folder on your system uh open it in vs code make a
1:28:31 - python file make a virtual environment uh set up a launch configuration and
1:28:37 - then uh build your package index right with the the python uh with the python package
1:28:44 - manager uh so pip freeze will let you build your requirements file you do all this and suddenly now you’re all set up
1:28:50 - and you’re ready to go right you’re ready to develop your python applications and share them with other people
1:28:55 - and uh when we next pick up we’ll be talking about how you actually get this code that you have on your local computer and
1:29:01 - you push it up to the internet uh in a version control repository so that other people can access it um we’ll be talking
1:29:07 - about how you track your changes to it as well um so we have a bit more to do here but we’re getting closer to uh
1:29:13 - being fully independent being able to code python applications locally and uh basically setting you up for how rio
1:29:20 - developers in the real world work so this is where we’ll cut for now and uh
1:29:25 - when we pick up we’ll be talking more about version control

29: A conceptual introduction to version control

Video


Summary

Version control can be tricky to wrap your head around the first little bit. There are a lot of moving parts, and some of the concepts are easily mixed up before everything clicks. It’s very normal to struggle a bit with these things initially, so no worries.

This video attempts to introduce version control… without talking about code at all! Instead, an extended analogy is made to accounting ledgers in business, and how a central ledger in the bank might interact with the records kept by indidivdual co-owners in a business setting. It’s a pretty close analogy, all things considered, and the time spent here outlining things conceptually will hopefully pay off later as we move into code-focused specifics. Having a concrete physical example of why we might want to be accurately tracking changes in various records can hopefully make these abstract concepts easier to get sorted in your head.

Timestamps

  • 00:00 - Introduction
  • 04:05 - Foreword: version control can be hard to understand, and that’s OK
  • 05:44 - Defining terms in version control by analogy
  • 08:46 - Repositories, commits, pushing, and pulling
  • 18:17 - Branches
  • 35:45 - Work items/tasks/product backlog items (PBIs)
  • 40:54 - Merging
  • 53:07 - Pull requests
  • 58:45 - Even as complex as all of this has been, we’ve still made some simplifications
  • 1:06:53 - Some other jargon and miscellaneous notes

Content

Foreword: version control can be hard to understand, and that’s OK

If you find version control hard to wrap your head around for the first little bit, I wouldn’t sweat it. It will be pretty tricky until things click and you have an “aha moment.”

Many new developers have a hard time figuring out the differences between repositories, branches, pull requests, and commits, so you may want to pay special attention to our discussion of these concepts.

Defining terms in version control by analogy

Let’s use an analogy: let’s say you run a business alongside several business partners, with each of you having a local ledger where you keep track of your business finances, with a master copy of your business’ overall accounts kept at a secure bank. The bank’s copy is the “real one” under law (so if you get audited, it is what is referenced as the authentic “current version” of the record). This situation is rather parallel to version control in code, so we’ll define all the relevant terms based off this analogy:

Repositories, commits, pushing, and pulling

Repository: a record (ledger) of business financial transactions. Each co-owner of your company has their own repository, and the main repository is the one at the bank.

Commit: some action taken that is added to a repository (an individual’s ledger or the shared one at the bank). A commit here might be something like “bought 500 units of new inventory for $10,000”. A commit represents a single, discrete change in state.

Push: one of the business owners takes their local repository (individual business ledger) to the bank (remote repository) to update the shared ledger with their most recent financial activity.

Pull: One of the business owners goes to the bank and updates their local copy to reflect the overall history of all the financial history. Their local activity is still there, but everybody else’s financial activity has now been added to it.

Everything making sense so far?

Branches

Now things will get more complex.

On top of there being all these different business ledgers (repositories) floating around, now let’s also say that each ledger is further subdivided into sections. Every ledger contains one “main section” that represents the overall financial record, but before certain groups of financial transactions (that is, groups of commits) go through (i.e., are pulled into the formal record), they are tracked separately. Basically, they are treated as pending until the transactions clear. You might think of these sections as representing pending business deals that are almost certainly going to go through, but some additional negotiation on contract specifics is required before they become final and get pulled into the main record.

Branch: A section in an individual ledger. By convention, the branch representing the overall final record is often called “master” (although some people are now also calling it “main” due to some unfortunate slavery associations with the former word – most people probably won’t bat an eyelash at either name). Also by convention, no individual co-owner will have deals that go directly into the permanent record, but will always have a different branch for each new business deal, in case one of them ends up having issues. Generally speaking, the most up-to-date information relating to a specific pending business deal will be located in the branches (sections in the ledgers) of the individual business owners (=local repositories) relating to the specific pending business deal, but from time to time, someone will push, so that the bank (remote repository) has a record of the open pending business deals too.

Work items/tasks/product backlog items (PBIs)

Work Item: each individual pending business deal is typically tracked on its own branch, so that the pending business deals don’t interfere with each other. Each one of these goals will usually be achieved through a collection of one or more commits targeted at the specific business dealing, typically with a very definite purpose in mind. For example, in business, the goals might be like “acquire X company” or “sell stockpiled supply to bring market prices down.” Each one of these things might ultimately need multiple transactions to coordinate the work being done, but together kind of represent “one thing”. Hence why the whole specific business deal is tracked on its own separate branch.

Merging

Merging: in the process of making a business deal, your company’s assets and liabilities might change due to the actions of your business’ co-owners. Let’s say you are in charge of acquisitions for your company, and therefore the acquisition budget. Your current business deal might depend on you having a certain amount of capital on hand therein, but what happens if Jeff, one of the other co-owners, uses some of the company’s money in that budget for a really important internal research project? Suddenly, you now need to reconcile changes in the global business ledger with your pending business deal (local branch corresponding to a task). Most of the time, you won’t have to scrap your pending deal entirely, but you’ll need to figure out how to square what new thing you are trying to accomplish with the changes in the company’s overall ledger. This process is known as “merging”, and it usually involves combining your new pending branch with the master branch. (Although occasionally you might need to reconcile the accounts for two pending business deals, if you decide to combine them into only one branch).

It is actually common to have merging be easy, with no input needed on your part. If Jeff were to take money from the R&D budget, for example, it would not mess with the acquisition budget that is important for your new deal (even though you’d still want to know about Jeff’s expenditure and pull information concerning it into your own ledger). But if there are conflicts, merging will involve reconciling the two records that now conflict in some area, and this can sometimes get really messy and gross. An ounce of prevention is worth a pound of cure here, so it would be advisable to tell your co-owners to temporarily keep their hands off your acquisition budget, if you know you’ll be dealing with it a lot for your current business deal.

Merge conflicts: the specific areas leading to some form of conflict when merging two branches. Merge conflicts arise when two different records (ledgers) are trying to do something different with the same resources. (E.g., the acquisition budget from above).

Pull requests

Pull request: once a business deal (work item/task/etc.) has been completed and all contract negotiations have been finalized and looked-over (the relevant person has pushed such that the business deal has been inked into the bank’s version of the ledger so that some or all people in your company have been able to give it a look and approve it), a request is made to incorporate the new deal into the main section of the bank’s official ledger (to write it into stone in the official final record). Note the emphasis. Pull requests are typically always against the master branch in the bank’s copy of the ledger.

Even as complex as all of this has been, we’ve still made some simplifications

Believe it or not, we’ve actually made quite a few simplifications here:

  • In a real production environment, there are actually usually several branches that all correspond to some “final-ish” version of the ledger. All of these might have pull requests against them, rather than just having a single master branch. It is common to have no branch called master, and instead have three (dev, test, production) or four (dev, integration, test, production) main branches. If none of this means anything to you, that’s fine, don’t worry about it for now. Just know that in the real world, usually the bank will actually have several different copies of the shared ledger, all of which might end up being slightly different. As a normal developer, you will probably still mostly be interfacing with a single ledger at the bank (and it will likely be called “dev”). So just pretend that the master from our above conversation is dev, and you’re good to go.
  • Sometimes people rewrite history, and change the record of what happened in the ledgers everywhere. Obviously this can cause lots of issues (what happens if someone goes forward with an out-of-date ledger?), and is usually avoided if at all possible. But sometimes it needs to happen anyway because life. This is called rebasing, and usually ends up being excessively complex and error-prone. In simple terms, rebase bad.

Some other jargon and miscellaneous notes

Cloning: the first time you as an individual stop by the bank to acquire a local copy of a ledger, that is called cloning the repository.

Ignoring files: let’s say that your company has an internal fund for helping out employees (or their spouses) with medical costs from cancer. Employees at your company can voluntarily elect to donate to this internal fund. It is not material to your business applications, so you don’t want it being tracked as part of your business’ overall assets. Therefore, you would specify that you want this thing specifically to be ignored in all the ledgers floating around everywhere. You would specify this in a document called .gitignore, which exists solely to tell ledgers to not worry about certain areas that aren’t relevant.

Unstaged changes: work that has been completed but not yet committed can be in one of two states. It can either be unstaged (so that if you commit, it won’t show up in the commit), or staged, meaning that it will be part of the next commit. It is common to stage all of your current changes when committing, but sometimes, after making a set of changes, you might want to have two or more separate commits to better organize the work that you did into discrete chunks.

Diffs: comparisons between two different versions of the company ledger, to highlight where the differences are. By convention, things highlighted red are deletions, and things highlighted green are additions.

Video transcript

0:02 - hey guys so today on the 28th we are going to be picking up uh in the lesson
0:08 - number 29 here in our series on picking up programming in a practical sense and
0:13 - today we’re going to be talking about version control in terms of a conceptual introduction so
0:19 - we’re not actually going to practice things with it specifically relating to git
0:24 - that is the version control software that we installed at the end of our last meeting but before we even get into
0:31 - doing things in a hands-on sense we’re going to talk about it conceptually and that’s because
0:36 - this is one of the trickier aspects of learning how to be a software developer
0:42 - especially integrate onto teams where you have to make your changes to a code base
0:47 - alongside many other people this is a very important skill that often doesn’t get emphasized enough
0:54 - in the college environment at least in my opinion i didn’t learn almost anything about it in college even though it is something that comes into play
1:01 - every single day when you are working on an actual team and so we’re gonna spend a good bit of
1:07 - time just hitting uh this idea of version control uh conceptually and uh specifically as we’ll see here um i’m
1:14 - going to be using an analogy to talk about things here so uh this is the outline of the things that we’re going
1:20 - to talk about today so we’re going to start out uh just kind of talking about the fact that version control can be
1:25 - tricky to understand and it usually does actually take people a while it’s not something that you’ll probably just
1:31 - instantly be able to snap your fingers and rattle off what everything means and how everything’s related you’ll see what
1:36 - i mean in a second here there’s just a lot to kind of wrap your head around and so you shouldn’t get discouraged if
1:43 - it takes you a little bit eventually hopefully things will click and you’ll start being able to see how everything
1:48 - relates but it may take a little while um because you know what seems easy for people who’ve been doing this for a long
1:54 - time maybe it’s not so intuitive the first few times you see it and so you just shouldn’t get discouraged on
1:59 - that account and then we’re going to talk about um an analogy uh that will help us hopefully understand
2:06 - some of what we mean by tracking changes so we’re going to use an analogy relating to uh the ledger that a
2:13 - business might have so a list a record of transactions uh used to represent
2:19 - business finances that’s going to be kind of the analogous situation that we use here to understanding uh changes to
2:26 - our code with version control so now we’re going to talk about all of these terms involved in version control
2:33 - so repositories commits pushing pulling those are kind of like the basics then
2:38 - we’re going to talk about branches and then work items tasks product backlog items radiated as pbis these are all
2:44 - synonyms kind of depends what sort of uh a task management system uh your software development team might use if
2:50 - you’re in the agile framework uh pvis is what my team calls them but uh yeah i’ve seen work items in tasks too these are
2:57 - these are the goals the chunks of functionality you’re trying to implement um then we’re gonna talk about merging
3:03 - uh you merge branches and we’ll get what that means in a second pull requests and um
3:08 - finally we’ll go over some other stuff like uh diffs and cloning and uh ignoring things that you don’t want to
3:15 - track in version control um and uh you know even even when we get there we’re going to note that we’ve made some
3:21 - simplifying assumptions for this first pass we’re not even going to hit everything completely as it is in
3:26 - reality uh our very first time looking at it just because there’s so much and after all of this we’re going to move
3:32 - from the analogy i don’t actually have so much written here we’re just going to go look at it um so i have this is the
3:38 - git repository for the ministry website that i’ve been working on so you can see i’m here on github
3:44 - which is this a remote a repository host um and uh we’re gonna look at one of the
3:50 - pull requests that i made uh in this repository and that should hopefully help us understand uh the difference
3:55 - between uh repositories and pull requests and branches and commits because all of those things i just said
4:02 - are very easy to confuse especially when you’re first getting introduced to these topics so uh that probably doesn’t mean
4:08 - too much to you now but we’ll get to it as we go there later on today so first thing as i was saying just as a forward
4:14 - for us here version control can be a hard topic to understand or wrap your head around and that’s okay um you
4:20 - should give yourself some slack here uh uh just be prepared for this to take a
4:25 - little bit of time for you to be able to wrap your head around most people don’t get it the very first time
4:30 - so ask questions if you get stuck if you don’t understand what the purpose of something is or what the differences
4:36 - between some of these terms are as we’re going over them please do ask questions because uh it is pretty tricky to get
4:42 - these things straight in your head uh once you do uh usually it’s like a one-time thing you know once you have
4:47 - your your aha moment your eureka moment uh you’ll kind of have it after that um but getting there can sometimes take a
4:53 - little while is what i’m saying so like i was saying uh just before a lot
4:59 - of new developers have problems distinguishing between these things here so repositories branches pull requests
5:05 - and commits all of these things are sort of related but these things all represent uh you
5:11 - know sets of changes or uh you know the state of your project at a given point in time and so given that uh sometimes
5:19 - they seem really similar uh in the minds of new developers and so it can be kind of hard to tell them apart and uh what
5:26 - the differences are what the what what they’re used for how we talk about them um so just as we go through all of the
5:32 - terms i haven’t haven’t done them exactly in this order but as you go through you missed mine on may want to
5:38 - pay some special attention to these things specifically because these are often uh the the terms that people
5:45 - stumble over uh because they get them confused with one another um all right so with that out of the way um we’re
5:51 - gonna try to use an analogy um so in fact you might be a little bit put off
5:56 - we aren’t going to talk about programming we’re not going to talk about code for like the next 10 slides
6:02 - or something everything that i’m going to bring up today uh in our high level conceptual uh
6:07 - overview of version control is going to be through analogy um and that’s just because uh
6:14 - we’re talking about the concepts here uh not the specific concrete implementation are used by a git our version control
6:21 - system here but we’re talking about what uh what each of these concepts represents like what is it basically
6:27 - doing how does it relate to some situation that we might have more of an intuitive feel for
6:33 - that’s not just lines of code so the analogy the lens that we’re going to view all of these things through
6:40 - is kind of a business analogy so let’s say this let’s say that you run a business alongside several business
6:47 - partners with each of you having a local ledger where you keep track of your business’s finances with a master copy
6:54 - of your business’s overall accounts kept it a secure bank um so so just to repeat
6:59 - this you know might seem repetitious but we just want to make sure we’re being clear you alongside several co-owners of your
7:05 - business each have a local ledger where you’re keeping track of your business finances and then there’s a master copy
7:12 - of your business’s overall accounts kept it a bank and so the one at the bank is separate from the one that all of the
7:17 - individuals have um and the bank’s copy is quote unquote the real one so under
7:24 - law this would be the one that if you got audited uh you know in terms of taxes or whatever the one at the bank is the one that
7:30 - would be referenced as uh the authentic current version of the record so it’s
7:35 - kind of it’s kind of the one that is considered the uh the last stop you know this is
7:40 - what the current state of the finances are set in stone this is uh the the
7:47 - original copy if you will that everyone else has to work off of um so this situation that we’re talking about
7:54 - here uh where uh individual co-owners in a business might each have their own ledger where they keep track of the
8:00 - financial transactions that they specifically make and then all of that ends up eventually flowing into
8:06 - a master copy of your business’s accounts that are kept in a secure bank uh this situation
8:12 - is actually quite parallel to how version control will work in code um so specifically uh the sets of changes that
8:18 - we’re tracking uh you know that’s the versioning that we use in version control very similar to this idea of
8:24 - having a ledger something that tracks transactions uh individual things that
8:29 - change the state of our code base are very similar very parallel here that’s why we’re going to try to use this
8:35 - business example as an analogy so we’re going to try to define all of the terms here
8:40 - based off of this analogy that we’re setting up so before we go ahead and move any further uh does the the general
8:46 - situation that we’re bringing up does this make sense in a high level yes it makes sense okay
8:52 - okay cool so now we’re gonna do uh kind of the easy stuff so most people can
8:58 - kind of get this the first try these things aren’t usually where people get hung up because as long as we keep it uh
9:04 - a set to just these things it’s not so bad so uh we said that uh each individual here has a ledger right and
9:11 - then there’s one that’s shared between everyone that ends up at the bank and that one represents kind of like the final copy right um so uh in our
9:18 - terminology each ledger each record of the business financial transactions is
9:24 - going to be called a repository um that is the word used of them in programming terms um so in our analogy we’re just
9:31 - going to call these records we’re going to call them repositories so each co-owner of your company has their own repository and the main repository is
9:38 - the one at the bank still okay so far yes it is okay
9:43 - so next term to define here is called a commit so some action taken that is added to a
9:49 - repository so that could either be an individual’s ledger or the shared one at the bank um so a commit here in business
9:56 - terms might be something like bought 500 units of new inventory for 10 000
10:02 - so a commit represents a single discrete change in state something has changed you record that
10:08 - change in a repository still tracking okay yes so this would be like an individual
10:15 - line on a transaction uh register so someone has done something we’re gonna
10:20 - we’re gonna update how does that affect our program um how does that change the state of our ledger um that is what a
10:28 - commit message represents and commits are discreet they’re separable um typically if you are following good code
10:35 - style uh your commits will be all organized around one one thing so
10:40 - you try to do something in the commits you don’t want to do a whole bunch of things you want your commits to be separable um so that if you need to roll
10:47 - something back you’re able to get rid of just that undo the changes uh that are doing one thing specifically so uh just
10:54 - keep that in the back of your mind you don’t want your commits to get like basically uh
11:00 - you don’t want them to be doing multiple things all over the place you want them focused um and and that would be
11:06 - similarly to a business uh would want each line item in their record of transactions to be for one thing that is
11:14 - easy for them to understand what it is right so you buy these items you sell these items
11:19 - uh you make this acquisition uh you know you you deposit this amount of money you get the idea um something that is
11:27 - one purpose discrete separable that’s what a commit is and commits are tracked in these repositories so you commit
11:33 - against a repository um each person uh each person has their own repository
11:40 - right each owner of the business has their record of the things that they’re doing for the business right so they
11:46 - might spend some money they might gain some money each one of them has a record of these transactions here that we’re
11:53 - calling commits um so uh like let’s say if you have john
11:58 - and robert and joe and all three of those people are owners in a business
12:03 - they each have their own uh they each have their own repositories each person would be taking these actions and
12:09 - recording these actions in their own repository and then eventually all of these things that they’ve done would end
12:15 - up if the one in the bank so that’s what we’re going to talk about next so having made commits against a repository so
12:21 - they’ve kept track of the changes that have happened in their local uh ledger that we’re calling a repository uh
12:28 - eventually we want to have all of these changes recorded in the main one right so uh this is called pushing so one of
12:36 - the business owners here takes their local repository so that’s their individual business ledger where they’ve been keeping track of their changes and
12:43 - they take it to the bank which is called the remote repository here so the one that’s shared among everyone’s called
12:48 - the remote repository to update the shared ledger with their most recent financial activity so i think we said
12:55 - john and robert and joe right each one of them would take their uh their ledger to the bank and then they’d record the
13:02 - changes that they made in the banks one right and then so after each one of these three people push
13:08 - the banks ledger will contain all of the commits from their local repositories
13:15 - does that make sense yes it is so you can push one commit
13:22 - you can sorry say that again you can push more than one commits that is true um so
13:28 - uh each commit represents one uh state of change right so let’s take john for
13:34 - example let’s say john bought like oh i don’t know what kind of business you have let’s say you’re in a grocery
13:40 - store so john bought a bunch of new fresh produce and then he sold
13:46 - you know the produce from the last day he would have some amount of money going out some amount of money coming in and
13:51 - he would record both things right but he would record them separately because if he record them at the same time
13:57 - what happens if there’s a problem with some of the money coming in right what happens if someone overcharged or something um you see what i’m saying
14:04 - right you want to be able to isolate things so those things would be tracked separately but then eventually when all of this is
14:11 - going into the main record for the business then both of those things will need to be tracked
14:16 - right and so when he’s going to the bank to fill out what changes he made to the business’s account books he’s going to
14:22 - record both things um so both of those things that we’re calling commits will end up uh when he goes to the bank in
14:28 - the final record of things so that’s called pushing um
14:35 - and each one of these commits uh is uh basically that they have unique names i
14:40 - won’t get into exactly how this works um but you know you’re gonna be able to track uh each line in this will be
14:47 - distinguishable from the others so uh you can just think of it as having numbers for now right commits one two
14:54 - and three may come from john four five and six may come from robert uh six seven or seven eight and nine might come
15:01 - from joe um and then in the final record of things you’ll be able to see all of
15:06 - those all nine of those and you’ll be able to see which one came from which person and things like that
15:14 - okay so a good question then might be so once once people have pushed their local
15:20 - commits to the remote repository the ones that shared then the remote repository has a complete record of all
15:27 - the transactions that happened of all the commits does that make sense
15:32 - yes then the question is how do the people get that the the complete uh the complete
15:39 - record of transactions well they want that in their own local ledgers as well right because otherwise they have like
15:46 - an incomplete set of information right they’re operating on a certain set of assumptions about what assets the
15:52 - company might have but they don’t know that so so john might not know that robert and joe spent money on this or
15:58 - earned money here and so if he doesn’t somehow update his local copy to match
16:04 - the shared copy eventually his state will kind of get out of sync right and he’ll be making decisions based on data
16:09 - that isn’t valid anymore right and so just as people can sync the shared copy
16:16 - with their local copies you can also sync your local copy with a shared copy right this is called pulling um so you
16:23 - push to the remote repository that contains the shared version and you pull from the remote repository containing
16:30 - the shared version to get your local version up to date right so in our analogy how this would work is
16:35 - one of the business owners goes to the bank and they go get the shared copy and then they update their local copy to
16:42 - reflect the overall history of all the financial history across all of the different people so their local activity
16:48 - is still there in their ledger they don’t overwrite theirs their activity is still there um but everyone else’s
16:54 - financial activity that they didn’t have previously has now been added to it
16:59 - yes you’re tracking yes i am i am okay so this is the
17:05 - general uh idea of version control so different people have their own copies
17:11 - of the changes being made and then eventually all of the changes being made will end up in the shared version that
17:18 - represents like the the final state of the project um and that is uh that
17:23 - shared version is is what ends up getting hosted not locally for you but somewhere shared so
17:28 - it’s on a server somewhere a github is an example of the bank in our analogy
17:34 - here uh they’re the people who contain uh the shared ledger that everyone uh references so this repository here on
17:40 - github this is an example of the bank’s ledger uh basically in our analogy and
17:46 - uh there’s another another site called bitbucket that’s the same thing as github so just as they’re different banks there’s different people who will
17:53 - happily support you uh keeping your your ledger that is shared among people
17:59 - on the internet somewhere okay so like i said this is what i would
18:06 - consider the easier part of the analogy all of these things kind of directly map onto our analogy very nicely kind of
18:11 - easy to wrap our head around i mean it’s just new names for things for concepts that you can probably already kind of
18:17 - understand right and yes so now things are going to get a little bit more complicated um so the
18:24 - next thing we’re going to talk about are called branches and like i said things are going to get more complex here so uh
18:29 - we’ve talked now about how there’s different kinds of these business ledgers that we’re calling repositories right there’s different ones of these
18:35 - floating around some of them belong to individuals we have the shared one that belongs to the bank um so now
18:41 - even though we have multiple ledgers we’re going to go a step farther now let’s say that each ledger is further subdivided into sections so each one of
18:49 - these ledgers contains one main section that represents the overall financial record um so this is the record of all
18:57 - the transactions that have occurred you know kind of uh by by date uh you know so it’s chronological and so on um and
19:04 - and this is the thing that is kept up to date with the bank’s copy because this represents the total record
19:09 - of all transactions this represents the overall state of the assets of the company
19:15 - but you might group other sets of of commits other sets of transactions into a
19:20 - different section um and so the best way to think about this let me finish here um is that before
19:26 - certain groups of financial transactions so that is groups of commits uh according to our terminology here so
19:32 - before they go through and by going through we mean before they’re pulled into the formal record
19:38 - as things that were kind of saying yes these things happened we’re committing these to our history um
19:44 - they’re actually going to be tracked separately and so basically they’re going to be in a different section because they’re treated as pending until
19:51 - the transaction’s clear so you might think of these sections that aren’t the quote unquote main
19:56 - section you might think of these sections as representing pending business deals that
20:01 - are almost certainly going to go through that is we’re planning on doing them um
20:07 - but some additional negotiation on contract specifics might be required uh before they become final and get pulled
20:13 - into the main record um so very common uh in businesses in a business context
20:18 - someone might want to buy you know one company might want to buy another company but they have to go back and
20:24 - forth a bit to decide on terms and timing and things like that or if uh a
20:29 - manufacturer is buying supplies from a supplier right they might agree on a
20:34 - certain volume of shipment and a payment and they might have dates associated with this or whatever well
20:41 - what happens of in the process of negotiation something something bad comes up right they
20:46 - realize that a deadline is not going to be met uh the suppliers overcharging them or something well they might want
20:52 - to cancel it right and so the problem with directly putting uh some of these these commits that we’ve talked about
20:58 - right these incremental changes you know like one commit might be paying a supplier uh like half of the money up
21:04 - front and then you might pay them half once the supplies have come or something like that right or some other agreed
21:09 - upon you might make some commits before everything is done right well the problem with making those commits
21:15 - directly to the shared record is what happens if your new business deal falls through for some reason or if not falls
21:21 - through you have to like renegotiate something comes up right something in this pending set of transactions that
21:28 - you want to do i’m using a business deal that’s our conceptual unit here for a set of
21:34 - transactions so not one commit uh i mean it could just be a single one but one or more commits uh represent this a unit of
21:42 - work that we’re doing here um uh kind of conceptually one thing but uh it
21:47 - represents you know these individual transactions taken to get there well all of these things are going to happen in a
21:53 - separate section then the main section where we’re tracking the formal history because we don’t want to have these
21:59 - things end up in the final history of our ledger until we’re sure that they’re actually going to happen right until
22:06 - everyone has looked at the changes and we’ve decided that yes this is this is a good thing we want to keep
22:11 - this this is this is what is going to actually uh be there moving forward
22:16 - yes does it kind of make sense at a high level um yes okay we have a little more to say
22:22 - here and so like i said we’re calling these things branches so a branch is a section in an individual ledger and like
22:28 - i said by convention we do have a main branch the one that represents the overall history um so by convention the
22:34 - branch representing the overall final record is often called master um so that’s the name of this branch is called
22:40 - master although some people are now calling it main uh due to uh some of the unfortunate slavery associations with
22:46 - the word master um so most people really won’t bat an eyelash if you call it either one of these things these are the
22:52 - two names most conventionally used for this this particular branch as a concept and so this is the final record where
22:59 - you’re tracking the overall state uh of uh like your your business ledger at any point in time and so also by convention
23:06 - this is what we were just talking about here no individual co-owner so no one in the business will have deals that go
23:12 - directly into the permanent record um for the reasons we just said what happens if something comes up what
23:18 - happens if something goes wrong you have to renegotiate terms something like that you won’t have the records of all these
23:24 - transactions end up in the company records until we’re sure that the deal is actually going to go through
23:30 - um so in that way we will always have a different branch for each new pending business deal in case one of them ends
23:36 - up having issues um and so remember how we were talking about in terms of repositories each of
23:43 - the co-owners in your business has their own repository and then there’s the shared one well for these pending
23:49 - business deals the most up-to-date information relating to one of these things uh so one of these specific
23:55 - pending deals right that set of transactions that’s happening uh in pursuit of some specific goal uh well
24:02 - the most up-to-date information for that will probably be located uh on the branches so again branches are sections
24:10 - in the ledgers um of the individual business owners and so that means that there will be a section in the ledger of
24:18 - a specific individual rather than the shared one dealing with some of the transaction history relating to uh
24:24 - whatever the pending business deal is do you need me to repeat that or do you think you tracked there
24:32 - i think i tracked it so again each individual has their own
24:38 - specific ledger uh their own record of the financial transactions that’s called a repository um
24:45 - each transaction itself uh each set of of things being done we call a commit
24:52 - but uh in the section of the repository so in a section of a ledger you might
24:58 - have multiple commits relating to a new pending business deal that’s the idea of a branch
25:03 - so in terms of relationships a repository might have multiple
25:09 - branches and each branch might have multiple does that make sense
25:15 - okay um just one thing that’s confusing me um
25:20 - said that the branch that represents the overall final record is called
25:27 - the master or domain [Music] so you should understand
25:33 - that the branch can mean the entire repository
25:39 - or is there something else i should understand there
25:45 - so the repository isn’t uh the main the master branch it’s not as if the master
25:50 - branch equals the entire repository um so each branch represents uh you know
25:55 - one state of the assets of your company in our analogy um and the master branch
26:02 - happens to be the one that has all of the transaction information across everyone it happens to be the one that has the
26:08 - most complete state but a repository actually isn’t the master branch a repository contains
26:14 - multiple branches right the repository is the whole ledger which conceptually contains the main record but it also
26:20 - contains these other sections relating to kind of pending changes right things
26:26 - that haven’t yet come in to the main record but are kind of in progress
26:32 - um so repository is a collection of these branches right one of the branches like you said is the main historical
26:38 - record has all the changes from the beginning of time related to the financial
26:44 - aspects of your view company but all of these other sections in the repository might be related to these deals that are
26:50 - kind of underway on these things that are still going on
26:56 - okay so a repository will contain more than just the information on what’s going on
27:03 - right now or what the state of things is right now so it will also contain information
27:08 - about what what might yet be or um use that
27:14 - i mean i might not think of this so much in terms of temporal sense um i think it’s best to think of it as uh you have
27:21 - a history right you know that’s kind of another thing for this log for this ledger idea and
27:26 - uh one history is the one that has kind of been set into stone right it’s like been
27:32 - recorded in the history books if you will that is the master branch right this is the one where once things end up
27:38 - there uh they don’t canonically at least they don’t change anymore right um yes
27:43 - and it’s the things that um are kind of based on uh so if you’ve ever seen
27:50 - um uh you know idea in like time travel books or whatever how there’s like branches in a tree right if someone
27:56 - makes a certain decision then some other things happen right but different branches share the same starting point
28:03 - that is entirely why we use the word branch here because you might have um let’s go back to our
28:11 - our people here john and robert and joe right so john and robert two people who work for the same company the the
28:17 - co-owners of this company right so john and robert might both be working on two things at the same time
28:22 - now let’s say that they both start their new business deals uh right on the date
28:28 - of like march 15th so that’s the day when they look at their they look at their ledgers they go to the bank they
28:34 - they they pull right so they they go to the bank and they they update their local history to make sure that they’re
28:40 - up to date with what’s going on in the bank’s ledger right so that’s called polling now they they are up to date uh
28:47 - they know that their their financial record is current with the financial record for the whole company
28:53 - um so they pull on march 15th and then they start their business deals and so john’s business deal might be different
29:00 - than robert’s business deal but they both start from the same place right so on march 15th their local ledgers look
29:07 - exactly the same right and then they both quote unquote branch off of it uh
29:13 - because they’re doing something new and so john let’s say he’s acquiring trucks right he
29:20 - wants to make more logistic shipping for the stores so john’s business deal is relating to acquiring trucks that’s what
29:25 - he’s doing so all of his transactions will be related to i don’t know maybe
29:31 - buying trucks retrofitting them hiring drivers things like that right um let’s
29:36 - say that robert his focus isn’t on trucks but it’s on oh what’s a good thing uh i mean we’ll
29:43 - just go with infrastructure we’ll keep on going here his his things about buying new store locations okay so john
29:49 - is buying trucks and figure buying uh people not buying people uh hiring
29:54 - people to drive the trucks and stuff like that um and then robert’s working on buying store locations right so he
29:59 - might have to buy property hire a construction company you know hire someone to uh pour the the asphalt for a
30:06 - parking lot things like that right so both of them start on march 15th from
30:11 - the same place they have the same set of financial information and then uh john spends some money uh he
30:18 - makes some transactions he has a certain set of things that are uh branching off from that march 15th point i
30:25 - after he does all of these things the state of the ledger would be updated right and similarly robert starting from
30:32 - march 15th does another set of things but starting from that same point right and so from a certain
30:39 - from a certain point of view if you from the perspective of march 15th if you could look into the future it’s as if
30:46 - uh it’s as if a split happened there right it’s as if those people started at the same place
30:52 - and then uh you know a branch like i said you think of time travel here a branch was
30:57 - taken and you know if you were in john’s shoes this stuff happened if you were in robert’s shoes this stuff happened
31:04 - yes tracking so far okay so that’s the idea of branches right you you have this initial starting
31:10 - state uh from your history uh the the master branch uh the main branch uh in
31:15 - your repository represents the shared set of history this is what’s set in stone the final record that’s where
31:22 - that’s where every single new business deal starts from so every single time uh you’re going to be doing something new
31:28 - uh you the steps are first you go you pull you go to the bank you make sure that you have up-to-date information on
31:34 - the assets of your company right you don’t want to go strike out making a new business deal if you don’t know what your current assets are right you want
31:40 - to make sure you’re up to date and then so you’re going to pull and then you have your record of transactions you
31:46 - know exactly what the state of your company’s financial assets is and then you’re gonna go start doing whatever you
31:53 - need to do for uh the goal that you have right and then you’re gonna branch
31:59 - you’re gonna branch off of the master branch at that time you’re gonna have that split where you say okay this is
32:05 - the financial information of what we currently have but now i’m gonna go do something different but i’m gonna start
32:11 - with the same thing that is already there right yes okay so
32:17 - now this gets more complicated because so individuals can have local branches
32:22 - right so in their local ledgers uh their record books of the finances of the
32:28 - company so the thing that they carry around with them they’ll have a history of the transactions that
32:34 - they’re making for their new business deal right and that part easier to understand however you can
32:41 - kind of see why the company as a whole might want to track the pending deals going on right so
32:48 - both john and robert are doing things related to company infrastructure right whoever manages all of the finances but
32:55 - want to know how much money is this person spending how much money is this person spending uh what pools you know
33:00 - most companies share they have like budgets so different departments have different budgets and stuff right where’s the money coming from can they
33:05 - both use these resources at the same time where we can have problems right so
33:10 - you would want to track this sort of thing and so eventually both john and robert are going to want to push they’re
33:17 - going to want to say you know what i’ve been doing some stuff now i bought my trucks i bought my property i’ve hired
33:23 - some construction workers i need to go record this information in the bank’s ledger so that the other people in the
33:29 - company can see what i’m doing right so that they can have a view into oh the changes that are
33:35 - going to be made if my deal goes through right if all of the changes that i’ve made end up coming into the the final
33:42 - record well then all of this stuff is going to be affecting other people and so
33:48 - um they have their their local copy of branches right so this is the section in
33:54 - their personal ledgers of the company finances dealing with their new business deal
33:59 - that they’re doing right so they have that but every once in a while they’re going to go back to the bank and they’re going to say here’s the progress on my
34:06 - new business deal since the last time i checked in right i’ve made some additional commits i’ve done some
34:11 - additional things right these these atomic operations uh that represent you know changes in the state of the
34:17 - application i’ve bought trucks i’ve hired people uh you know uh things like that right these
34:23 - transactions um are the commits and uh you might have multiple commits to a branch each branch
34:30 - representing this this new direction this new business deal and then eventually you might register uh the
34:36 - branches you might update uh the the the bank’s record of how your deal’s going
34:42 - and that’s called pushing as we talked about here yes yes okay i understand it
34:51 - okay right so this is definitely more complicated than when we just had this right because suddenly now we’re saying
34:58 - that uh rather than straight up committing to a repository actually commits belong to
35:04 - branches and branches belong to repositories right um so each ledger can
35:09 - have multiple sections in it one section will contain the history since the beginning of time that’s called the
35:15 - master section usually or the master branch and then the other ones are these
35:20 - branches representing pending sets of changes pending business transactions going on
35:25 - and so a repository is a collection of all the branches and then each branch has a set of
35:31 - changes associated with it so the whole change set is per branch but within that
35:37 - it will be composed of multiple different commits a multiple different smaller sets of changes representing a
35:43 - very specific a very specific change in state
35:48 - okay so definitely more complicated right and this is why i said version control can
35:54 - take a little bit to get through so now we’re going to talk about things this is from the level of organizing your work
36:00 - on a programming team so we just talked about branches now branches conceptually come about when
36:07 - you have a new goal so we’re going to talk about these things i’m going to call them work items although you might hear them called tasks or product
36:12 - backlog items depends on which software development infrastructure you’re using um so
36:18 - each work item basically represents a block of things you want to do right so in the example that we have had here
36:24 - john’s work item was he wanted to increase the number of trucks that the
36:30 - company had for shipping right that was what he was trying to do and so all of the transactions he made all the commits
36:36 - he made were related to that right one commit was buying more trucks another commit was retrofitting the trucks
36:41 - another commit was hiring drivers right all those are separate but they’re all related to this goal of
36:48 - getting more trucks for the company right and then robert’s goal was uh you know
36:53 - buying more store locations so he’d buy the property he’d hire the construction company to build the store hire the
36:58 - people to lay out the parking lot and each one of those commits is separate but all of those things are working
37:04 - towards the goal of getting more store locations open right
37:09 - so each of those commits would be going on separate branches but actually each branch is organized by one specific like
37:16 - conceptual thing it’s the branch is trying to do something right all of the work for a purpose is is towards some
37:23 - end and that’s what we’re calling a work item so each individual pending business deal is typically tracked on its own
37:29 - branch so like i said uh when john is doing his thing with the trucks he’s kind of doing that separately from what
37:35 - robert’s doing with the stores each of those things is tracked separately just as you’d expect in a normal company
37:40 - right because those are kind of separate endeavors they each have their own uh costs and schedule pressures and you
37:46 - know all of the different factors there but they’re kind of done separately in parallel um so each pending business
37:52 - deal is tracked on its own branch so that the pending business deals don’t interfere with each other right so that
37:58 - everything is kept nice and boxed and all of the work associated with this work item
38:04 - is cleanly separable onto the branch for that work item right so if you want to see how are things going on john’s
38:10 - acquisition of trucks you can go see all of the commits that have been pushed to that branch
38:16 - again pushing back here right of the record of what’s going on in the bank’s register um you can go check that
38:22 - for the work item here of acquiring trucks and you’ll be able to see all the progress that’s been made on that branch
38:27 - and similarly you’ll be able to do the same thing with robert’s branch for acquiring store locations uh even though
38:32 - it’s it’s in a different section of the legend of the ledger right those things are being tracked separately but you can
38:38 - see how both of them have diverged since they split off of the shared history of
38:43 - of when the the the new a business deal started this was the set of assets that
38:48 - the company had and things like that um so as we’ve said each one of these goals
38:54 - will be achieved through a collection of one or more commits targeted at the specific business dealing right these
38:59 - commits are going to a specific branch which is tracking all of the changes being made uh towards this work item um
39:06 - typically with a very definite purpose in mind right again in our example definite purpose is uh john’s acquiring
39:12 - trucks and robert’s acquiring new store locations um so i give some examples here in business
39:18 - the goals might be like acquire x company or sell stockpiled supply to bring market prices down or whatever
39:24 - right each one of these things might ultimately need multiple transactions to coordinate the work being done but
39:29 - together kind of represent one thing right hence uh getting more trucks for the company involves again buying the
39:35 - trucks retrofitting the trucks hiring the drivers right each one of those is a specific milestone in the process but
39:41 - together they all compose the idea of getting more trucks right um and so all of this is why each a new
39:49 - business deal is tracked on its own separate branch right so that you can track uh the progress on the work being
39:54 - done uh kind of separately still making sense
40:00 - yes so all the activities relating to one specific thing that’s being done
40:06 - will be on its own that’s correct it’s rather than each of those
40:12 - activities being a branch and it’s it all constitutes one branch
40:18 - now the lines can get a little bit fuzzy like how do you how big how many things do you clump together because arguably
40:25 - there might be some tasks involved in like hiring drivers too for example right like you might have to go contract
40:31 - with a labor company and set up insurance health insurance plans for the drivers and those things are tasks too
40:36 - right so do those things get their own branches well you you kind of draw a line somewhere and you say okay this is
40:42 - the the higher level concept that may have sub tasks and those subtasks may have sub tasks and i mean it can break
40:48 - down further than that but eventually you you you say everything that goes in this box is related to this thing right
40:54 - that is the branch level
41:01 - okay so now we’re going to talk about what happens when despite your best efforts
41:08 - the branches that you’re working on separately what happens when they come into conflict with each other and you have to reconcile the records um
41:15 - so uh let me go ahead and read this this is this is going to be one of the harder things to understand here um so uh this
41:21 - process we’re going to call it merging so in the process of making a business deal your company’s assets and
41:27 - liabilities might change due to the actions of your business’s co-owners so someone other than you right uh let’s
41:33 - say you were in charge of acquisitions for your company and therefore the acquisition budget your current business
41:39 - deal might depend on you having a certain amount of capital on hand therein but what happens if jeff is one
41:44 - of the other co-owners what happens if he uses some of the company’s money in that budget for a really important
41:49 - internal research project so that money that you’re counting on for your business deal well someone else just took some of it right suddenly you now
41:56 - need to reconcile the changes in the global business ledger with your pending business deal uh that is your local
42:02 - branch corresponding to one of these work items that we’re talking about here right
42:07 - so uh to keep using our example here uh let’s say that uh john and robert were
42:13 - sharing resources right they were pulling money from the same place and robert uses some of that money to buy a
42:19 - new store location but suddenly now john doesn’t have enough to cover the cost
42:24 - that he thought he was going to have for buying a truck right and so how this would play out in a code practice is
42:31 - robert would go he would um you know he would be
42:36 - uh making his business deals and then he’d go to the bank and say okay here’s the stuff i’ve done and then uh
42:41 - similarly john would go to the bank to be okay here’s the stuff that i’ve done or the things that i promised the obligations that i have
42:47 - and then eventually they’d see that oh wait uh this isn’t good right let’s say
42:52 - that robert’s stuff finishes first so robert closes his business dude he signs the contract with the people that he’s
42:58 - buying the property from they shake hands it’s in ink right can’t be undone now right and so he finishes before john
43:05 - and then john comes back and says oh wait look at that wire transfer right robert transferred more money than i
43:10 - thought he was out of this account so suddenly john doesn’t have quite enough to cover what he thought he was going to
43:15 - have right now he has to renegotiate the terms of his contract he has to figure out what he’s going to do given the fact
43:23 - that things have changed since he first branched off of the initial history of the ledger right so in our example we
43:30 - said john and robert were both starting from the state of the company’s assets on march 15th
43:36 - that was what we were using in our example right and since march 15th robert has pushed
43:42 - his changes and we’ll in fact he’s merged them we’ll talk about full requests in just a second here but
43:47 - robert’s stuff has gone into the final record right it’s now part of the company’s business transaction he’s he
43:53 - signed it in inc it’s not reversible anymore and so suddenly now john has to reconcile
43:59 - the the fact that the final record has changed so the state that he started from is not the current state now so
44:05 - when his changes go into the final record they have to play nice with everything that’s already there right
44:11 - and so things have changed since john first started making his new business deal
44:16 - and so he’s going to have to reconcile his contract with the changes that have
44:22 - happened since he first branched off of that initial state um
44:27 - so now he has to reconcile changes in the global business ledger with his pending business deal right and that
44:33 - pending business deal is tracked in a section of his of his personal ledger right um it’s one
44:42 - of the things in his local repository right and he occasionally will be pushing uh the stuff that he does to the
44:49 - remote repository that’s to the bank’s ledger saying okay here’s the progress i’m making in my business deal in this
44:55 - set of tasks that i’m undertaking here okay so a lot of the time you won’t have to
45:01 - scrap your pending deal entirely right but you might need to figure out how to square what new thing you were trying to
45:07 - accomplish with the changes in the company’s overall ledger right so if someone else touches something that you were depending on or relying on you
45:14 - might have to make some some tweaks some changes to adjust here um so this process of reconciling uh what has now
45:20 - become the final the final ledger uh even the so of reconciling the changes in the final ledger uh with your branch
45:28 - is called merging um so it usually involves combining your new pending branch so this
45:33 - this section in your local ledger uh with the master branch um so occasionally you might actually merge
45:40 - two branches where one of the branches isn’t master right so if you have uh two
45:46 - business deals going on at the same time and they’re kind of related to each other you might say you know what we should be tracking all this stuff in one
45:52 - place right and you might consolidate branches actually and in that case you would merge one branch into another
45:57 - branch and you’d say okay uh like let’s say let’s say that john who’s acquiring
46:03 - the trucks uh let’s say that he has a subordinate named jim okay and so jim
46:09 - was working with some other thing and initially the company was tracking their stuff separately but then they said you know what jim stuff is really kind of
46:15 - under john right jim’s negotiating the labor contracts or something but his stuff really part of john’s goal right
46:22 - relating to all the trucks so then they might merge those two branches and track all of those changes
46:29 - in the same place does that make sense yes so normally the most normal thing that you
46:35 - have to do is you have to merge the master branch that has changed because someone else has done something since
46:41 - you branched off it uh since you basically since you started uh your new project and you’ve been making changes
46:48 - uh to the the record uh as your company had it from that point in time well now suddenly the company record the global
46:54 - company record has changed now you have to reconcile the changes that you’ve been making with the changes that
46:59 - someone else made right usually that is what you have to do when you merge right you have to reconcile
47:06 - the two records to make everything work and play next with each other um so it’s actually pretty common to have
47:13 - merging be easy so this might sound scary like any time someone else changes something everything’s gonna break
47:19 - that’s actually not the case um a lot of the time you don’t have to do anything so in our example that we brought up
47:25 - here where jeff kind of pirates some of your uh your acquisition budget for his internal research project right well if
47:31 - jeff were rather than taking your money if you were to take money from the r d budget let’s say your company has an r d
47:37 - budget well it wouldn’t actually mess with the acquisition budget that’s important for your need deal um
47:43 - and therefore it wouldn’t like mess with your new deal right and so your new deal could still go through even though jeff
47:49 - did this and even though the company’s spending money over here now we don’t really care because it doesn’t really affect your stuff right um yeah and so
47:57 - you’d still want to know about jeff’s expenditure right so you’d still want to go to the bank uh you know as you do
48:03 - periodically to go to the bank to pull right and get that updated ledger for the transactions of what everyone else
48:09 - has done and so you’ll go there and you’ll be like hey any changes and they’ll say oh yeah look jeff jeff bought this stuff for that internal
48:15 - research project and you’ll be okay cool um you know i’m glad that progress is being made over there but you know that’s not really my stuff so you know
48:21 - i’m happy to see my acquisition budget still untouched right all that money i need for my business deal well i still
48:26 - have that right this is actually probably the the more common case especially if your team is
48:32 - well coordinated so if you have good meetings at your company you try not to have people step
48:39 - on each other’s toes right you try to make sure that people are working on independent things that they’re not going to cross each other’s paths and
48:45 - get in each other’s way right but sometimes it happens you know even if you don’t intend for it to sometimes it
48:50 - happens anyway right but a lot of the time you can get a merging
48:56 - doesn’t always have to be gross so so we still call it merging right we still call it merging so taking what’s in the
49:02 - master record and putting it in your own record so that your own record is up to date with the master one we still call
49:08 - that merging even if there aren’t any conflicts it’s still merging we just call it an easy merge right
49:14 - um and so if you think of this if you think of this again as that that decision tree where we have branches so
49:22 - this is why they use these words right it’s supposed to help us envision this idea of history so if a
49:27 - branch is where something deviates from like this this common path right well
49:33 - when you merge you’re going back into the common path right so
49:38 - you’re kind of you’re you’re coming off it and then you reconcile your changes with whatever’s there and then you you go back into it you merge back into it
49:45 - right that’s how you ought to think about this right um yes now so we said sometimes and in
49:51 - fact a lot of the time if you organize your work well merging won’t be that bad right it it should happen completely
49:57 - automatically you don’t have to worry about it because no one will be touching your stuff uh but if there are conflicts
50:02 - suddenly then you have to reconcile the two records that now conflict in some area and this can sometimes get really
50:08 - really messy and gross um this is a very challenging part of being a software developer um
50:14 - usually all it takes is a time or two for you to have a really gross merge for you to like get it through your head this is terrible i never want to do this
50:20 - again um and then you’ll be sure to communicate better with your teammates so it doesn’t happen again um
50:26 - you’ll get the hang of this communication very important in avoiding really bad merge conflicts right so uh
50:32 - in code terms i’m gonna i’m gonna break our analogy for a second here in code terms if you and a coworker are both
50:38 - working on the same file changing the same functions you’re going to step on each other’s toes right you might change
50:44 - the same line of code and how how is the the ledger how is the the record here how is it supposed to know which which
50:50 - change it wants right it can’t do that on its own that’s how you have to
50:55 - resolve conflicts in code now for our business transaction this might be someone’s using money over here but you
51:00 - said you were using that money who actually gets to use the money right that’s in our business context the the
51:06 - idea of these conflicts here um so again merging sometimes it’s easy
51:11 - but if it’s gross it can be really really gross and so let me again emphasize that an ounce of prevention is
51:16 - worth a pound of cure here so it’s definitely advisable to tell your co-owners to temporarily keep their
51:22 - hands off of your acquisition budget if you know that you’re going to be dealing with it so in code terms if you say hey i’m work i’m dealing with this function
51:29 - and this file don’t touch it um sometimes it’ll be harder because sometimes everything’s connected and it’s really
51:34 - hard to avoid stepping on each other’s toes but as best you can good communication can help you avoid really gross merge conflicts um
51:41 - it kind of depends how big your team is too um but all right so last thing to cover for
51:48 - merging here is this idea of merge conflicts so merge conflicts are the things that
51:53 - cause the merge to not go easy right on the specific areas leading to some form of conflict when merging
52:00 - two branches so merge conflicts arise when these two different ledgers are trying to do something different with
52:05 - the same resources so in our example on this slide this would be with the acquisition budget right if you’re the
52:11 - only one using it you won’t have any problems but if someone else suddenly starts using it too then you have to know well who actually
52:17 - gets to use it and what do they get to do with it because if you have two different reports of what is happening with it
52:23 - then how is the bank the bank record of the bank ledger which represents the final uh set in stone state well what
52:30 - goes in the record for all time um
52:36 - and that will need to be reconciled okay how we doing um
52:46 - okay i think you’ve got everything still so far yes yes okay
52:52 - um so next we’re going to talk about pull requests okay so now we’ve talked about repositories commits pushing pulling
52:59 - branches work items which are the things that kind of represent the work that happens on a branch and then merging
53:07 - which is when you get one branch stuck into another branch so that you can get that final record
53:13 - ironed out now we’re going to talk about pull requests so once a business deal and that’s what
53:19 - we’re calling a work item or a task has been completed and all contract negotiations have been finalized and
53:24 - looked over which means that whoever’s been a running point on this business deal has pushed they’ve put their
53:30 - changes in the bank’s ledger not in the master branch not in the main section of the bank’s ledger but in
53:36 - their little section detailing all the work that they’ve been doing on this business deal so they’ve put it in a place where everyone else can see it
53:43 - right in the bank’s ledger so in that part of the bank’s repository they push their branch to the main repository so
53:50 - that other people can look at their branch right so once the person has done that and
53:55 - the business deal has been inked into the bank’s version of the ledger so that some or all people in your company have been able to give it a look and approve
54:01 - it so after that happens a request is made to incorporate the new deal into the
54:07 - main section of the bank’s official ledger so this is the step in which it becomes written in stone right it gets
54:14 - added to the main history that shall not be touched um so um
54:20 - branches you know branches branch off the main branch and to get merged back
54:25 - into the main branch the actual thing that gets them stuck back into the main history is called pull request
54:31 - so a pull request is really kind of like a special kind of merging right so you merge
54:36 - you typically merge master into your local branch and then you open a pull request to get your local branch stuck
54:42 - back in master um so this is after your new business deal
54:49 - has closed uh you’ve made all the made all the transactions you need to do to get something done everyone has approved
54:55 - it so this is an important step it’s called peer review um so you peer review pull requests you say hey i think i’m
55:01 - done with my business deal um here’s all the things i did does all this look right does it check out with the goals
55:07 - that we had in mind for this and then you’ll get other people from your company to come and look at it and they’ll be like yeah that looks like
55:13 - what we wanted go ahead and put that in our final history right um
55:18 - that’s what pull requests are um so typically and again note the emphasis here pull requests are typically always
55:25 - against the master branch in the bank’s copy of the ledger so uh each individual person will have a local copy of
55:33 - the full history right so they’ll have a local copy of the master branch but you don’t put a pull request against that
55:38 - what you put a pull request against is the bank’s version of the set in stone history
55:45 - right because that’s the thing that represents actually the current state of your project if you remember when we
55:50 - were setting up our analogy we said that the the real copy so to speak is the bank’s copy um
55:58 - for the main branch right so if you get audited by the irs that’s the one that’s important right and so what the pull
56:04 - request does is it it says all this work that we’ve been doing in an area now that’s going to go into the irs copy of
56:10 - this right that’s going to go into the the main important one that is shared between all people
56:19 - so a pull request is different from a pool that is correct
56:24 - um so a poll is something that a an individual does uh where they go to the
56:30 - bank and they get a copy of the bank’s main ledger right that’s what polling is um actually you
56:36 - don’t just you don’t just get a copy of the main ledger you can actually get copies of other people’s uh uh business
56:44 - deals branches right so you can pull down any branch as long as the branch
56:50 - has been entered in the bank’s ledger you can get a copy of that section of the ledger
56:55 - does that make sense so so in our example of john and robert
57:00 - earlier you know john’s doing the truck stuff robert’s doing the store location stuff as long as both john and robert
57:05 - regularly go to the bank and update the bank’s ledger on their progress the other person will be able to keep an eye
57:11 - on what the other one’s doing right because they’ll be able to go to the bank and they’ll be able to pull the other person’s branch and say okay good
57:17 - he’s done this and this and this and they’ll be able to like watch each other’s progress right so you could you pull branches from the bank a pull
57:24 - request i i know this people don’t like the word i hate how they named this this is how it’s
57:30 - been named we can’t change it but a pull request is kind of like the opposite of polling because polling is the bank’s
57:38 - ledger basically you’re getting a copy of the bank’s ledger and it’s putting it in your own ledger a pull request
57:43 - is you know you’re opening a request other people have to approve it right they have to look it over and say yes we want
57:49 - this but it’s going the other direction it’s saying hey i made some changes uh in my localizer i’ve now pushed those
57:55 - changes to the bank’s ledger but now i want this section of the ledger i want it to become one with the main section i
58:02 - want to merge it into the main section so you’re taking uh where is pulling normally
58:08 - is you getting something from the remote repository right a pull request is you
58:14 - take something from your local repository you push it up to the remote repository so it’s in the shared ledger and then you’re going to combine that
58:20 - with the master branch it’s kind of like it’s not exactly the opposite but it’s
58:25 - definitely different right okay
58:36 - okay so i mean i know all of this is very hypothetic it’s all very abstract right now right um but
58:43 - hopefully the analogy is helping kind of us uh orient ourselves in terms of what
58:48 - these things mean at a high level um all right so even as much as we’ve gone through here
58:54 - right believe it or not we’ve actually made quite a few simplifications uh for how this stuff actually really works i
58:59 - give two examples here these aren’t it’s not an exhaustive list there’s other other points to be made too but in a
59:05 - real production environment so this is like when you’re deploying to an actual server you have an application that a whole bunch of people are hitting um
59:10 - there’s actually usually several branches that correspond to some finalist version of the ledger right so
59:17 - in our previous discussion we’ve been saying that the the one history version is called master right that’s according
59:23 - to the discussion we previously had it’s actually a little bit of a simplification a lot of the times um you’ll have multiple versions of this of
59:30 - this so-called final state right so all of these different ones might have pull requests against them rather than just
59:35 - having a single master branch um so it’s actually common to have no branch called master and instead you’d have
59:41 - three you might have a branch called dev a branch called test and a branch called production which everyone just calls
59:46 - prod so the split here this is the one that that you and your team push to when you’re like developing a new feature
59:53 - test is when the feature goes to whatever testers your customer has to make sure that you’re doing the right
59:58 - thing and then production is when it goes into it goes into effect for like final end users right
1:00:04 - um now some people might have four uh dev same deal right this is where you
1:00:10 - and your team are working on stuff it’s kind of in progress still integration uh this is an extra step where suddenly
1:00:16 - you’re pushing to your you’re pushing to your deployed environment this is literally this is still not it is not
1:00:22 - crossing the eyes of external testers it’s still you and your team but what you’re doing is if you’re pushing your
1:00:28 - code onto a server rather than running it on your own computer you need to make sure that that environment works well um
1:00:33 - so both of these are pretty common development patterns um so each one of these three things uh kind of represents
1:00:40 - a final state right so uh generally speaking uh dev is
1:00:45 - it’s like has more recent activity to it than test and test has more recent activity than
1:00:50 - prod and so in terms of like what’s most up to date dev will be most up to date but it’s also less stable right because
1:00:57 - you might have stuff that ended up in dev but maybe there’s a bug or something um
1:01:02 - so these are actually pretty common uh like quote unquote real approaches right
1:01:08 - for small projects a lot of small projects actually really do just have master right and they do
1:01:13 - make pull requests directly to master if you don’t deploy somewhere else maybe you don’t need as much of this other stuff um so actually my my projects are
1:01:21 - like i it’s actually getting kind of late today i don’t know if we’ll actually look at the code side of this today but my project here you see i only
1:01:28 - have one branch and my branch is called master so uh smaller projects that aren’t deployed as much it works
1:01:34 - fine with just one branch but um so that’s you know one level of complexity that we’re going to kind of wave our
1:01:40 - hand at right now and just not worry about so much so even when you’re on a team like this uh usually you’ll have uh you’ll have some
1:01:47 - of the production guys you know particularly more senior developers who have been in an environment like this
1:01:52 - longer who know more they’ll be the ones who probably handle the deployments to test and prod and so especially as a
1:01:59 - normal developer at junior dev you’ll probably still mostly be interfacing with just one ledger at the bank in our
1:02:05 - analogy um just rather than calling it master you’re just going to call it dev instead
1:02:10 - that is probably uh the the version control uh source that most
1:02:17 - people are going to be familiar with as software engineers most of the time the work that you do will be pushed to a
1:02:22 - branch called dev um that’s normal um so for now just think of things like this right dev
1:02:30 - will be the name of the shared ledger that the bank has um i just want to introduce this to you to
1:02:36 - make it clear that uh we’re making some simplifying assumptions here right and so
1:02:42 - don’t get super wedded to exactly how i’m describing it because if you ever go into a real job it might
1:02:48 - be set up a little bit differently but the concepts are what’s important right um so the other thing is thus far we’ve
1:02:54 - been saying that that history that we’ve been talking about we’ve been saying it’s set in stone after something goes into the final ledger uh it shall not be
1:03:00 - undone right well actually you can muck around with the history um so
1:03:06 - sometimes people rewrite history and change the record of what happened in the ledgers everywhere so obviously this
1:03:12 - can cause lots of issues right because what happens if john doesn’t go to the bank for a week well suddenly if the
1:03:17 - bank has like rewritten their ledger john’s operating on something that’s like really wrong right um so what
1:03:23 - happens if someone goes forward with an out-of-date ledger you have all sorts of issues so what we’re talking about here
1:03:29 - is called rebasing um so you basically rewrite history in the ledgers um so
1:03:34 - things that you said happened you know they say they didn’t happen they happen differently right um so usually this is avoided if at all
1:03:41 - possible because it causes a lot of issues um sometimes it needs to happen anyway because life um sometimes bad
1:03:48 - decisions are made something gets in your code base that shouldn’t be there like a common a common uh thing for this
1:03:56 - is if someone actually ends up committing a password um like a password in one of your code
1:04:02 - files right so you have a connection string to a database for example and you need to be authenticating on that
1:04:08 - database and someone pushes the actual password into version control um
1:04:14 - well guess what that’s a huge security flaw right um you can’t have a password
1:04:19 - in your code that’s not okay however in version control by default even if you put another commit to remove
1:04:26 - that password guess what it’s still visible in version control right what you want to do is make it so that
1:04:32 - as if that password was never there right and to do that the only thing that you could
1:04:38 - do is to rewrite history the problem is as soon as you rewrite history anyone who had a branch open at
1:04:45 - the time where you rewrite history like they’re completely screwed because suddenly what they branched off of no
1:04:51 - longer exists even close it’s not even remotely the same right and so this causes lots of issues again you as
1:04:58 - a junior developer probably won’t worry about i mean i did so by the way upshot of this conversation don’t commit passwords to version control terrible id
1:05:05 - um you will get in lots of trouble um but that aside you probably won’t be the one doing this
1:05:11 - right um if you need to ask uh uh hey senior developer how do i
1:05:17 - rebase you should say here you do this also do we really need to do this you
1:05:22 - should ask that question too um rebasing very frowned upon sometimes it is necessary though like i said excellent
1:05:28 - example someone gets a password in version control you need to wipe it out as if it had never been there the only
1:05:34 - way to do that is to rewrite all the history um but as a general practice this doesn’t happen um it’s happened
1:05:40 - once on my project here and uh trying to remember why we did it something got super super messed up someone pushed
1:05:47 - they merged a branch into our master branch uh this was before we’d split into like a dev and prod branch and they
1:05:53 - pushed something into our main branch that just like broke everything and we couldn’t figure out where exactly it
1:06:00 - went wrong and we wanted to just get rid of that thing that had gone in and said you know what somehow this got through
1:06:07 - peer review but it broke everything and we don’t know where it broke and we can’t just like not have our app
1:06:12 - functioning for like two weeks while we try to figure it out right and the problem was things had gone in
1:06:18 - since then right so this thing went in and then something else went in on top of it so we needed to remove that as if
1:06:23 - it had never been there so i think it’s only happened once on my application and i’ve been on it for about two years now
1:06:29 - so in production environments quite rare um and you want to avoid this if at all possible but
1:06:35 - okay no enough on that these are the exceptions right so i just take my word for it there’s some nuance here that
1:06:41 - we’re not going into just because it’s not super helpful the very first time you go over these things but
1:06:46 - you know don’t be shocked if in the real world at some point something comes up a little bit different than the main
1:06:52 - process that we’re going over but we’re going to focus on that main process because it’s the general development
1:06:57 - workflow that you’ll see as a developer um so i know we’ve just been dumping lots
1:07:03 - of data on you right now we have just a little bit more to get through and then i think we’re actually gonna call it a day there um i would encourage you to go
1:07:10 - back and try to make sure that all of the stuff that we’re talking about makes sense in your head because we’re going
1:07:15 - to go look at what all this means in terms of code uh next time right we’ve been talking conceptually here but all
1:07:21 - of the things i think i picked my analogy pretty well i think everything should transfer over pretty seamlessly
1:07:26 - so if you understand that everything works here then i think you should understand how it works uh when you’re
1:07:32 - version controlling a set of a set of text files code wise um so just some other some other terms that you’re going
1:07:38 - to need to know um so cloning cloning is the very first time that you as an individual stop by the bank to get
1:07:44 - a local copy of the ledger that’s called cloning the repository so maybe maybe your company hires a new uh like a new
1:07:52 - person who’s gonna be in charge of something well they don’t have all of the company’s assets up until now right
1:07:57 - so they need to go get a copy of it so they go to the bank and they say hey mr bank teller i’m new to the company but i
1:08:02 - need a copy of this information say okay here you go right that’s called cloning the repository you get a copy of what
1:08:08 - the bank’s copy is okay yes so cloning is something that
1:08:13 - individuals do so you from the remote repository you clone the remote pository
1:08:18 - into a local one um something that the individuals do so simple enough right that’s actually not
1:08:24 - one of the hard terms here uh something else uh that might happen in this is you might want to ignore certain things from
1:08:30 - version control so here’s the analogy i use in our business our business analogy so let’s say that your company has an
1:08:37 - internal fund for helping out employees or their spouses with medical costs from cancer right so my uh i work for the
1:08:44 - government i work for the air force we actually don’t have something directly like this but what we do have is we have
1:08:49 - uh what’s called a voluntary leave transfer program so if people uh have a spouse with a severe medical emergency
1:08:56 - like cancer or they’re out of work due to debilitating health condition if you want to you can donate your annual leave
1:09:04 - to them right if someone has to be out for circumstances it’s just it’s out of their control it’s hard and they don’t
1:09:10 - have enough vacation for it you can say here have some of my vacations i actually have something kind of similar to this in my job right it’s elective
1:09:17 - so employees it’s your company but uh for our example let’s say that it’s actually monetary right so uh your
1:09:23 - company has an internal fund for helping out um costs related to cancer for employees and their spouses so um
1:09:28 - employees that your company can voluntarily voluntarily elect to donate to this internal fund
1:09:34 - um however as a business you don’t really want to track this as like business assets right um because this
1:09:41 - isn’t material to your business applications this isn’t relevant to like your bottom line or the amount of capital you have for acquiring equipment
1:09:48 - or means of production or logistics or whatever like you can’t use this right this is just internal to your company
1:09:54 - right so this is something that you really wouldn’t want to be tracked as part of your business’s overall assets
1:10:01 - do you see why right because this isn’t really relevant to the overall scope of you of your business
1:10:08 - and so for that reason uh you would specify that you want this thing specifically to be ignored in all the
1:10:14 - ledges floating around everywhere so this is every ledger in existence right so this is john’s legend robert’s ledger
1:10:20 - joe’s ledger and the ledger the bank and if you have multiple ledgers like we said here with like devtest and prod
1:10:26 - right all the ledgers everything you’re gonna be ignoring this stuff right um
1:10:31 - so code wise um this is what it’s called in code it’s a file called a dot git
1:10:37 - ignore right so it’s a hidden file called git ignore this is basically just a list of stuff that you want to ignore
1:10:43 - so you want to say i don’t want this thing to version control and so whenever you come across this and it gets confusing in your head think i
1:10:50 - want to i want to ignore this from version control just like how a company would want to ignore their internal
1:10:55 - cancer fund because it doesn’t relate to their operating expenses right they don’t want to track it in their main
1:11:00 - assets ledger same thing in our code base there’s some stuff well we don’t care about right uh so something that’s
1:11:06 - common for this uh different people might have a preferences according to their uh to their text editors and
1:11:12 - oftentimes those things remember we’ve actually seen this um we’ve seen this in our uh examples
1:11:19 - already so this is vs code folder right so right now we just have a launch configuration which you probably
1:11:24 - actually want to share across people but you might have like a settings file here that contains like my key bindings or
1:11:29 - something for vs code i don’t really want to commit that to the shared repository because it’s not going to be
1:11:34 - relevant for other people might just get in the way right um yes that’s the sort of thing that you’d ignore um
1:11:42 - okay so that’s ignoring files you specify the files to ignore in this thing called a git ignore file um very
1:11:47 - analogous to how companies might not track everything on their balance sheets but only the stuff that’s actually relevant for their company
1:11:55 - good so far okay just a couple more things so we have uh this idea of staging changes uh
1:12:02 - on stage changes and stage changes so um if you have work on a branch that you’re doing that has been completed but you
1:12:08 - haven’t committed it yet right so it can be in one of two states you can either have it on stage and that means that if
1:12:15 - you commit the next time you commit and so you say i made this set of changes um
1:12:21 - so it means that if it’s on stage it won’t show up in your commit so your next commit uh you pick a set of stuff
1:12:27 - that you want to say hey i did this stuff and that is your that’s your block this is the stuff i’ve done this time
1:12:33 - right but if you stage it it means that it will be part of the next commit and so it’s actually quite common um if you
1:12:40 - set if you task out your work well it’s pretty common for you to stage all of your current changes when you commit
1:12:45 - something so basically everything you’ve done since the last time you committed you’ll stick in the next commit right
1:12:51 - but sometimes you might get a little bit ahead of yourself and you’ll implement one thing and then you’ll implement something else
1:12:57 - that’s really not that related to it right but you’d do it before you committed the last stuff
1:13:02 - see what i’m saying and so sometimes after making a set of changes you might want to have two or more separate
1:13:08 - commits to better organize the work that you did into discrete chunks and so let me give an example here right
1:13:15 - let’s say that you had someone uh who worked for both john and robert in our example right let’s say that this
1:13:21 - person’s specialty was like hiring employees they were an hr person right and so the hr person might have done
1:13:28 - stuff on john’s project relating to hiring truck drivers and he might have done stuff on robert’s project relating
1:13:33 - to hiring like construction for men or supervisors or whatever right and so he
1:13:39 - has hours built to both of these things right so he might have done work since the last time he went to the bank
1:13:46 - and reported the stuff that he did and how it affects the company’s ledger right he might have done work on acquiring trucks and acquiring new
1:13:52 - buildings right but since the last time he went he hasn’t
1:13:57 - kept in his record he didn’t put those transactions as you know did truck stuff or did banks or did uh a building stuff
1:14:05 - right so he has all of these things that he has ready to record now kind of all
1:14:10 - jumbled up right in this circumstance it’d be better for him to not put all of that stuff in one commit it would be
1:14:16 - better for him to break it up and say okay here’s when i did truck stuff and here’s when i did building stuff see what i’m saying
1:14:24 - yes okay this is very very very very indicative of programming experience a
1:14:30 - lot of the times new developers just because they’re not used to it will have commits that just contain a whole
1:14:36 - jumbled mess of stuff they don’t organize it very well because they’re just saying you know i did all the
1:14:41 - things it works i don’t want to care about organization or structure whatever i’m like here’s all the changes i did
1:14:46 - and you’ll have these big change sets i mean even those of us who’ve been at this awhile sometimes we get lazy right
1:14:51 - or you fix something and you’re just just i mean i don’t want to go dig through line by line and figure out what
1:14:56 - should go where um but the benefit of having more atomic commits that are very focused on one specific thing is if
1:15:03 - something breaks it’s much easier to roll back a small set of changes than it is to roll back
1:15:09 - you know a huge set of changes right because it makes it easier to pinpoint what you need to undo to fix things um
1:15:17 - so okay this is the idea of staging so on stage changes um and here let me show
1:15:22 - you an example i i know we won’t get into a lot of code stuff today but this is the example so you see here it says
1:15:29 - unstaged files right now so yes um down at the bottom of the screen
1:15:34 - um this is where i can type my commit message so i could say did this work right and so right now if
1:15:41 - i commit here i don’t have any changes in my in my change that i don’t have anything that i say i’ve done in this
1:15:46 - commission but you see here i’m deleting uh right here these are two temporary pages that i had scaffolded when i was
1:15:52 - testing stuff right so both of these things i’m deleting stuff so you can see it’s all red in the change set here right um yes but
1:15:59 - i could paste a commit here and if i wanted to call this something specific i might call this um like delete
1:16:07 - uh no longer needed uploading
1:16:12 - right so if i make that my commit message it’s actually very clear what i’m doing right uh what’s this commit
1:16:18 - doing it is getting rid of no longer needed scaffolding files right but let’s say
1:16:24 - let’s say that i update uh this path bit in the general python folder right this
1:16:30 - was me last night i was trying to get my slides partial to work on stuff in the root directory right so now if i add
1:16:37 - this file to my change set and i say delete no longer needed scaffolding files well is this right is this right
1:16:43 - here deleting no longer needed scaffolding files like no has nothing related to that at all right and so if i let you come back
1:16:50 - and i’m trying to find oh you know there’s a bug related to the general program loop right uh where’d
1:16:57 - that get introduced i’m not gonna be able to find it if i put it in this commit that has nothing that’s not related to it right um
1:17:04 - so in this regard what i want to do is first i’d want to commit these things over here i’d want to commit the
1:17:09 - deleting the no longer need find i’m not actually going to do it because i need to go like organize all this stuff but
1:17:14 - after that after i i i got those deletions up then i would come to this
1:17:20 - and i would say you know like like increase files
1:17:25 - first or slides or something like that right i’m doing a different thing here i would
1:17:31 - want those things to be split out and separate because that’s better organization
1:17:38 - does that make sense yes so you get to pick here uh this is the interface for sourcetree one of the
1:17:44 - reasons why i like sourcetree it’s really easy to see what changes are involved in your change set because you
1:17:49 - can go ahead and just look like you can preview the changes here like you see right it makes it easy to see
1:17:55 - like what you are and are not getting ready to put in an actual commit
1:18:02 - okay last main thing then uh for today we’re going to talk about diffs so diffs quite simply you see this thing over
1:18:08 - here this is a diff um it shows you the changes it shows you red stuff
1:18:14 - uh red stuff is deletions green stuff is additions that’s it that’s what a diff is um so i
1:18:21 - mean i have some more words to say comparisons between two different versions of the company ledger to highlight where the differences are by
1:18:27 - convention things highlighted red or deletions things highlighted green are additions um okay so this is actually me talking
1:18:33 - about some of the actions of the patriarchs it looks like right um what’s the actual context whatever but
1:18:38 - you know like you see redar editions you know i’m not done with this yet i’m still editing this particular piece of content but um you know red are
1:18:45 - deletions green our auditions um and oh no actually no this isn’t that this is the slides this should look
1:18:51 - familiar this is the slides that we did when we were looking at role models right um so moses job um
1:18:59 - yeah joseph so i haven’t committed that to version control yet but um that is what the diff is it shows you the
1:19:04 - differences in the files that you’re working with and so we might commit this right we might
1:19:11 - uh which one is this this one what whichever one it is right um we might commit that and put those
1:19:17 - changes in the bank’s ledger so the shared version of things um
1:19:22 - but diffs are very important for you to get used to looking at because this is how uh when you’re reviewing someone
1:19:28 - else’s code you want to be seeing what stuff they changed and so you’ll be evaluating the
1:19:34 - things they did i mean you want to functionally test it too make sure that the stuff does what they say it does but you’ll also be looking at the code and
1:19:41 - most of the time you’ll just be getting a chainsaw you’ll be getting one of these diffs the difference between
1:19:46 - the master branch and then the branch that you’re putting up for pull request to put into the master branch you want
1:19:52 - to see the differences between them to make sure that everything checks out that everything looks okay
1:19:58 - all right so we’ve skipped some other stuff and i mentioned that peer reviews peer reviews happen when pull requests
1:20:05 - get put up right so other people look over your code they approve it before it gets pulled into master or you know dev
1:20:11 - or test or prod or whatever um so peer reviews are a part of the pull request process um you know i i’m sure i
1:20:19 - missed some other stuff right i came up with all of this this afternoon so uh you know entirely possible that i missed other thing but i think i got most of
1:20:25 - the big stuff here and so um you know initially i was telling us to actually look at some code today too i don’t
1:20:30 - think we’re gonna have time um so i will pick up with this next time probably um specific examples in a git repository um
1:20:37 - so you know like this is a pull request uh from this branch about the site content section into the master branch
1:20:43 - and you can see that this this pull request on this branch here this branch has lots of commits to it right um
1:20:50 - so we’ll look at this uh next time uh once we have some time to actually look at the uh code version of this but
1:20:57 - hopefully the analogy has proved helpful here uh for getting our feet wet uh conceptually into the idea of version
1:21:03 - control um so i’m just closing us out here i’m actually do you have any questions
1:21:08 - before i jump into uh you know summarizing everything we’ve talked about
1:21:14 - so far i follow uh i’m not confused by anything so far
1:21:20 - now the trick will actually come when i say okay great now you make a branch and you make a pull request right um yes
1:21:28 - yeah you know then it always it becomes challenging when you’re the one who has to do it uh without someone holding your
1:21:33 - hand right but okay well i’m glad that that was hopefully clear um so that’s what we did today right we talked about
1:21:39 - how this stuff can be tricky to understand especially for the first little bit right once it clicks and once you have all these things
1:21:45 - straight in your head you won’t have such a hard time of it but it can take a little bit for things to click there um so we talked about our analogy here of
1:21:52 - viewing this idea in terms of like transaction ledgers for businesses so the business accounting a good way kind
1:21:58 - of parallel analogy to use here to uh tracking code changes and version control so we talked about repositories
1:22:05 - commits pushing and pulling right so repositories being the local copies of the ledgers that individuals have versus
1:22:11 - the one at the bank commits or these uh kind of atomic operations that we’re doing these transactions that get
1:22:17 - recorded in the ledgers uh pushing is when uh someone takes their ledger and
1:22:22 - updates the bank’s ledger based on what they’ve been doing polling is they go to the bank they get information about what
1:22:27 - other people are doing and put it in their own ledger right we talked about branches and work items or tasks right
1:22:34 - so each work item or task has its own branch that you do work on uh kind of
1:22:39 - analogous to pending business deals right so all the stuff related to acquiring trucks goes on one branch all
1:22:46 - the stuff uh relevant to buying new buildings going on another branch the
1:22:51 - the two branches can be worked in parallel without uh getting in each other’s way right and we talked about merging uh so that
1:22:58 - is reconciling differences in the history since you last uh branched off of something right if
1:23:04 - someone else has stuff that goes into the main record and then you’re gonna have to reconcile that with the changes
1:23:10 - you’ve made as well and sometimes this doesn’t require too much work on your part right if if their changes were in
1:23:15 - something that you weren’t working on but sometimes if you do have conflicts it can get kind of messy to resolve
1:23:21 - those then we talked about how after this uh once you think all of your stuff in a pending business transaction
1:23:28 - is done you might put that up for pull request to to kind of put it in the history that gets set in stone right so
1:23:35 - the official record of your application’s uh history um so to do that you open a pull request you’ll have
1:23:41 - some some co-workers teammates a peer review the pull request look things over say you know what this looks right this
1:23:47 - does what we want it to do we’ve allocated all of our resources accordingly i’m going to go ahead and approve this give it a green check and
1:23:54 - then once you get however many approvers you need that will go and it will be set in stone as final history
1:23:59 - now we talked a little bit here i’m not spending too much time but just about how we’re making some simplifying
1:24:05 - assumptions just for the sake of making this easier to understand the first time um but don’t be surprised if you have
1:24:10 - multiple branches like devtest and prod when you go into a real application development environment um and sometimes
1:24:18 - even though we’ve been saying that this history is set in stone and doesn’t get changed well if someone commits a password to version control it will get
1:24:24 - changed there are some circumstances where history does need to be rewritten but you try to avoid it if at all possible
1:24:32 - and then finally we talked about some of these other terms cloning right so
1:24:37 - getting that ledger the first time from the bank ignoring files in our business analogy just like how a company would
1:24:42 - ignore the assets relating to an internal fund for helping employees with medical expenses
1:24:48 - unstaged changes so the idea that you want to have very organized commit messages so that
1:24:54 - when you are kind of recording the transactions that you did inside your ledgers so so that people in the future
1:25:01 - will have a record of what was done uh you want to break things up uh into these atomic operations these things
1:25:07 - that are descriptive of one thing and one thing only um so that it’s much clearer and easier to roll back if you
1:25:13 - need to and finally we talked about diffs uh which are uh you know the the red and the green everywhere uh that
1:25:19 - oops let’s not do that uh the red and the green everywhere that represents what you added and what you removed um
1:25:25 - so i think that’s where we’ll stop uh quite a whirlwind introduction lots of information today so i would 100
1:25:31 - recommend uh once i post this video that you go back and you look at it if you need to i’ll just make sure that you have all the differences between these
1:25:38 - things clear in your head because we will pick up looking at this in terms of code uh the next time we meet um so with
1:25:45 - that that’s where we’ll cut for today and uh we’ll talk to everyone again when we pick up next time

30: Practical coding examples with version control (Git), setting up an SSH key pair

Video


Summary

Timestamps

Content

Debugging

  • Getting unstuck, if we need it.

Example of a repository

Example of a branch

Example of a pull request

Example commits

Example diffs

SSH keys

When you connect to a remote repository, you need to be authenticated – would a bank let just anyone see the company ledger, and especially modify it? No, right?

You could authenticate with a password each time you wanted to push or pull, but that’s kind of inconvenient. Fancy business owners might have ID cards they can scan at an RF-signal card reader to get them access to their important company vault quickly. We can do something very similar as developers working on a repository.

Our “ID cards” are called SSH keys, and they are basically a matched-pair of authentication hashes. You can think of them in the exact same terms as our RF-signal card and card reader example. The card reader has a set of people whose chips it “knows”, and whenever they scan, it lets them in. So too here.

The very first time, however, we will have to “go to security” and get them to register our card with the card reader. That’s what we are going to do now.

Git Bash, OpenSSH, SourceTree, and GitHub

Here’s an outline of the steps:

  1. Open Git Bash and cd into your home directory.
  2. Use OpenSSH to generate a public/private key pair
  3. Add your private key to SourceTree
  4. Add your public key to GitHub
  5. Test things out to make sure they are functioning properly

We’ll get to step (4) here, and then talk about setting up a remote repository to test with (5).

Connecting a remote version control repository with a local one

There are two approaches to connecting a remote version control repository with a local one. You can either start locally and connect to a remote repo after-the-fact, or start with a remote repo, clone it down, and only then begin working.

In my opinion, the latter approach is easier, as all you have to do is clone (you don’t have to worry about setting up remote refs). It truly doesn’t matter that much, but we’ll be going through the latter approach together.

Start remote, clone local (my preferred option)

Easy to do with just SourceTree, no command-line required.

Start local, connect to remote

  • git init
  • git add .
  • git commit -m "Initial commit."
  • Create a repo on GitHub
  • git remote add origin git@github.com:UserName/repo-name.git
  • git push -u origin master

Video/audio transcript