Skip to content

Commit

Permalink
Merge pull request #10 from DHI/update-slides-module1
Browse files Browse the repository at this point in the history
Update slides module 1
  • Loading branch information
jsmariegaard authored Nov 3, 2023
2 parents eefd415 + 6368c80 commit b3d3c25
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 31 deletions.
93 changes: 63 additions & 30 deletions 01_version_control.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ logo: academy_logo.png



## Why use version control?

![](images/tech-comics-version-control.jpeg)


## Why use version control?

![](images/filenames_versions.png)



## Why use version control?

::: {.columns}
Expand All @@ -19,17 +30,19 @@ logo: academy_logo.png
:::

::: {.column width="70%" .incremental}
* Manage changes to code over time
* Keep track of changes and revert to previous versions if needed.
* Collaborate and merge changes from different people
* Ensure code stability
* Best practice for software development
* Keep track of changes
* Backup and restore
* Transparency
* Easier collaboration
* Improved code quality
* Allow experimentation
:::

:::




## Centralized version control

* Single source with the entire history
Expand All @@ -54,25 +67,25 @@ Git is a powerful tool for managing code changes and collaborating with others o

. . .

You can use Git from the *command line*, or with a graphical user interface (GUI).
Use Git from the *command-line*, or a *graphical user interface*.

. . .

`> git add foo.py`

. . .
::: {.columns}

`> git commit -m "Nailed it"`
::: {.column width="55%" .smaller}
`> git add foo.py`

. . .
`> git commit -m "Fixed"`

`> git push`
:::

::: {.column width="45%"}
![](images/GitHubDesktop.png)
:::

##

![](https://imgs.xkcd.com/comics/git.png)

:::



Expand All @@ -97,10 +110,10 @@ You can use Git from the *command line*, or with a graphical user interface (GUI
:::


## Branching and Merging
## {background-color="white"}

![](images/git_staging.png)

* A branch is a separate version of your code that you can work on independently from the main branch.
* `git merge`: merges changes back into the main branch (we will do this from GitHub)

## Git hosting platforms

Expand All @@ -119,7 +132,22 @@ You can use Git from the *command line*, or with a graphical user interface (GUI
:::


## Github flow {background-color="white" .smaller .incremental}
## Demo 1

1. Create a new repository on GitHub
2. Clone the repository to your local machine
3. Add a file
4. Commit the file
5. Push the file to GitHub


## Branching and Merging

* A branch is a separate version of your code that you can work on independently from the main branch.
* `git merge`: merges changes back into the main branch (we will do this from GitHub)


## Pull request workflow {background-color="white" .smaller .incremental}

![](images/git_workflow.png)

Expand All @@ -141,36 +169,41 @@ You can use Git from the *command line*, or with a graphical user interface (GUI
:::


## Demo 2


## Desktop Application: [GitHub Desktop](https://desktop.github.com/)

![](images/GitHubDesktop.png)


## Demo

1. Create a new branch
2. Make changes
3. Commit the file
4. Create a pull request
5. Get feedback and merge changes


## Github best practices
## Best practices

::: {.incremental}
* Commit often
* Use descriptive commit messages
* Keep pull requests small and focused
* Use "issues" to track work
* Review code regularly
* Use .gitignore to exclude files
* Don't commit data (only very small test data)
* Don't commit passwords
:::


## Gettings started

1. Create a [GitHub account](https://github.com)
2. Install [GitHub Desktop](https://desktop.github.com/) (includes Git)
3. Create a new repository on GitHub


## Resources

* [GitHub: quickstart](https://docs.github.com/en/get-started/quickstart/hello-world)
* [RealPython: git and github intro](https://realpython.com/python-git-github-intro/)
* [Datacamp: introduction to Git](https://app.datacamp.com/learn/courses/introduction-to-git)




Expand Down Expand Up @@ -226,7 +259,7 @@ Fork
::: {.incremental}

* Version control is a tool for managing changes to code
* Git is a distributed version control system (*software*)
* Git is a version control system (*software*)
* GitHub is a *platform* for hosting and collaborating on Git repositories
* GitHub Desktop is a GUI for Git (and GitHub)
* Pull requests are a way to propose changes to a repository
Expand Down
17 changes: 16 additions & 1 deletion 02_function_classes.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -752,4 +752,19 @@ class RandomClassifier: # CamelCase ✅
def fit_predict(self, X, y): # lowercase ✅
self.fit(X, y)
return self.predict(X)
```
```

## Summary

::: {.incremental}

* **Functions** are black boxes that takes input and produces output.
* Function **arguments** can be positional or keyword arguments.
* **Pure** functions are easier to reason about.
* Avoid mutable default arguments and modifying input arguments.
* **Classes** are useful for grouping related functions and data.
* **Dataclasses** are a convenient way to create classes with a few attributes.
* **Modules** are files containing Python code (functions, classes, constants) that belong together.
* **Packages** are directories containing modules.

:::
17 changes: 17 additions & 0 deletions 03_testing.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,20 @@ Line # Hits Time Per Hit % Time Line Contents
19 1 500.0 500.0 0.0 return points
```


## Summary

::: {.incremental}

* Testing is a way to verify that your code is working as expected.
* **Unit** tests are small, isolated tests that verify a single logical concept in your code.
* **Regression** tests are used to verify that your code is still working after changes.
* **Integration** tests are used to verify that your code works with other code.
* Exceptions are a way to handle errors in your code.
* Warnings are a way to alert users of your code to potential issues or usage errors.
* **Linting** is a way to check your code for common errors and style issues.
* **Ruff** is a fast linter that checks for common errors and style issues.
* **Black** is an automatic code formatter that enforces a consistent style.
* Profiling is a way to measure the performance of your code.

:::
12 changes: 12 additions & 0 deletions 04_dependencies_ci.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,15 @@ jobs:




## Summary

::: {.incremental}

* Application vs library
* Prefer `pyproject.toml` over `setup.py`
* Use a virtual environment for each project
* Use GitHub Actions to run tests on every commit
* Use GitHub Releases to publish software releases

:::
19 changes: 19 additions & 0 deletions 05_documentation.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,22 @@ User-agent: *
Disallow: /
```


## Additional resources

* https://realpython.com/python-project-documentation-with-mkdocs/


## Summary

::: {.incremental}

* Documentation is important
* Use a README file
* Use docstrings
* Use type hints
* Use `mkdocs` to generate API documentation

:::


12 changes: 12 additions & 0 deletions 06_oop.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -787,3 +787,15 @@ If you want to learn more about refactoring, I recommend the book "Refactoring:

::::


## Summary

::: {.incremental}

* OOP is a way to organize your code
* Encapsulation, composition, inheritance, abstraction
* Duck Typing
* Postel's law
* Refactoring

:::
Binary file added images/filenames_versions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/git_staging.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tech-comics-version-control.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b3d3c25

Please sign in to comment.