To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 2 minutes to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Download the notebook:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Open the notebook file

    Type the saved filename in the open box.

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Preview

Author 1

Astro 528: High-Performance Scientific Computing for Astrophysics (Fall 2023)

md"> Astro 528: High-Performance Scientific Computing for Astrophysics (Fall 2023)"
13.9 ms
     
ChooseDisplayMode()
8.1 ms

Week 6 Discussion

md"""
# Week 6 Discussion
"""
10.7 ms

Admin Announcements

Labs

  • Review feedback on Lab 4, Ex 2 via GitHub

  • No lab this week, so can work on your projects

  • Still meet Wednesday for a group work session

md"""
# Admin Announcements
## Labs
- Review feedback on Lab 4, Ex 2 via GitHub
- No lab this week, so can work on your projects
- Still meet Wednesday for a group work session
"""
26.7 ms

Class project

  • Review project instructions on website

  • Serial code should be ready for peer code review by Oct 2

  • Sign up for project presentation schedule

    • Click Fork button to create your own repository

    • Edit README.md in your repository (can use web interface for small chagnes)

    • Commmit change to yoru repo and push (if editting local repo)

    • Create Pull Request to merge your change into the class repository

md"""
## Class project
- Review [project instructions](https://psuastro528.github.io/Fall2023/project/) on website
- Serial code should be ready for peer code review by Oct 2
- Sign up for [project presentation schedule](https://github.com/PsuAstro528/PresentationsSchedule2023)
- Click **Fork** button to create your own repository
- Edit README.md in your repository (can use web interface for small chagnes)
- Commmit change to yoru repo and push (if editting local repo)
- Create **Pull Request** to merge your change into the class repository

"""
1.3 ms

Serial version of Code Rubic

  • Code performs proposed tasks (1 point)

  • Comprehensive set of unit tests, at least one integration or regression test (1 point)

  • Code passes tests (1 point)

  • Student code uses a version control system effectively (1 point)

  • Repository includes many regular, small commits (1 point)

  • Documentation for functions’ purpose and design (1 point)

  • Comprehensive set of assertions (1 point)

  • Variable/function names consistent, distinctive & meaningful (1 point)

  • Useful & consistent code formatting & style (1 point)

  • Code is modular, rather than having chunks of same code copied and pasted (1 point)

md"""
## Serial version of Code Rubic
- Code performs proposed tasks (1 point)
- Comprehensive set of unit tests, at least one integration or regression test (1 point)
- Code passes tests (1 point)
- Student code uses a version control system effectively (1 point)
- Repository includes many regular, small commits (1 point)
- Documentation for functions’ purpose and design (1 point)
- Comprehensive set of assertions (1 point)
- Variable/function names consistent, distinctive & meaningful (1 point)
- Useful & consistent code formatting & style (1 point)
- Code is modular, rather than having chunks of same code copied and pasted (1 point)
"""
932 μs

Peer Review Logistics

  • Access

    • I'll send you GitHub ID of peer reviewer via Canvas

    • Make sure reviewer(s) can access your repo

    • Make sure you can access the repo you are to review

  • If using Jupyter notebooks, make sure to add Markdown version of code for getting feedback

    • Install Weave (once): `julia –project=. -e 'import Pkg; Pkg.add("Weave")' #

    • Convert Jupyter notebook to markdwon (each time you want to update the markdown): `julia –project=. -e 'using Weave; convert_doc("NOTEBOOK_NAME.ipynb","NOTEBOOK_NAME.jmd")'

  • Provide most feedback via GitHub Issues

md"""
## Peer Review Logistics
- Access
- I'll send you GitHub ID of peer reviewer via Canvas
- Make sure reviewer(s) can access your repo
- Make sure you can access the repo you are to review

- If using Jupyter notebooks, make sure to add Markdown version of code for getting feedback
- Install Weave (once): `julia --project=. -e 'import Pkg; Pkg.add("Weave")' #
- Convert Jupyter notebook to markdwon (each time you want to update the markdown): `julia --project=. -e 'using Weave; convert\_doc("NOTEBOOK\_NAME.ipynb","NOTEBOOK\_NAME.jmd")'
- Provide most feedback via [GitHub Issues](https://guides.github.com/features/issues/)
"""
39.5 ms

Q&A

md"""
# Q&A
"""
212 μs

What exactly is "scratch" memory, and what differentiates it from other kinds of memory?

blockquote(md"""
What exactly is "scratch" memory, and what differentiates it from other kinds of memory?
""")
277 ms

"Scratch" can mean different things depending on context:

  • A separate physical disk or file system that is intended to be used for temporary files.

    • E.g., Roar's /storage/scratch/USERID/ provides large storage but autodeletes your files

  • A portion of memory allocated and reserved for holding scratch data

    • E.g., preallocating a workspace to be used for auto-differentiation, integration, factoring a matrix, etc.

md"""
"Scratch" can mean different things depending on context:
- A separate physical disk or file system that is intended to be used for temporary files.
- E.g., Roar's `/storage/scratch/USERID/` provides large storage but autodeletes your files
- A portion of memory allocated and reserved for holding scratch data
- E.g., preallocating a workspace to be used for auto-differentiation, integration, factoring a matrix, etc.
"""
752 μs

Garbage collection

md"""
## Garbage collection
"""
218 μs

Is there a way in Julia where we can easily identify memory that can be released or the program can automatically help us release memory?

blockquote(md"""
Is there a way in Julia where we can easily identify memory that can be released or the program can automatically help us release memory?
""")
246 μs
  • That's the garbage collector's job.

  • But you can make it's just easier or harder.

md"""
- That's the garbage collector's job.
- But you can make it's just easier or harder.
"""
387 μs

How does one check if the code would cause a memory leak?

blockquote(md"""
How does one check if the code would cause a memory leak?
""")
251 μs
  • If using pure Julia, then garbage collector prevents leaks (at least in theory)

  • In practice, you can use poor practices that cause it to use lots of memory, e.g.,

    • Large/many variables in global/module scope

    • Not organizing code into self-contained functions

    • Allocating more memory than you really need

    • Many small allocations

  • If you call C, Fortran, Python, R, etc., then memory leaks are possible.

  • Test your code

  • @time or @allocated to count number/ammount of allocations. Does it match what you expect?

  • In ProfileCanvas.jl, can use @profview_allocs to visually find functions/lines that allocate lots of memory (not necessarily a leak).

md"""
- If using pure Julia, then garbage collector prevents leaks (at least in theory)
- In practice, you can use poor practices that cause it to use lots of memory, e.g.,
- Large/many variables in global/module scope
- Not organizing code into self-contained functions
- Allocating more memory than you really need
- Many small allocations
- If you call C, Fortran, Python, R, etc., then memory leaks are possible.
- Test your code
- `@time` or `@allocated` to count number/ammount of allocations. Does it match what you expect?
- In ProfileCanvas.jl, can use `@profview_allocs` to visually find functions/lines that allocate lots of memory (not necessarily a leak).
"""
1.0 ms

How severe will thrashing be in a high-level language such as Julia? Should we worry about it immediately or only during optimization?

blockquote(md"""
How severe will thrashing be in a high-level language such as Julia? Should we worry about it immediately or only during optimization?
""")
320 μs
  • Thrasing is a result of programming practices.

  • When you're a beginning programmer, focus on other things first. Benchmark/profile to find inefficient code and then optimize.

  • As you gain more experience, you'll start to recognize places where thrashing could occur as you start to write them. In that case, a little planning early on can save work down the road.

md"""
- Thrasing is a result of programming practices.
- When you're a beginning programmer, focus on other things first. Benchmark/profile to find inefficient code and then optimize.
- As you gain more experience, you'll start to recognize places where thrashing could occur as you start to write them. In that case, a little planning early on can save work down the road.
"""
502 μs

What are the main causes of thrashing and how does Julia mitigate it? Specifically, how does Julia’s garbage collection reduce thrashing, if there even is a strong connection?

blockquote(md"""
What are the main causes of thrashing and how does Julia mitigate it? Specifically, how does Julia’s garbage collection reduce thrashing, if there even is a strong connection?
""")
285 μs
  • Lots of small allocations on the heap

  • Java (probably the first "major" language to have garbage collection built-in) gave garbage collection a bad reputation because it only allows mutable user-defined types (and passes all objects by pointers), making it quite hard to avoid heap allocation of even very small objects.

  • Julia (and C#) encourage the use of immutable types

  • Julia pass variables by reference (so they can pass variables on the stack)

  • C# passes variables by value by default (so they stay on stack, but often unnecessary stack allocations) and can pass by reference.

md"""
- Lots of small allocations on the heap
- Java (probably the first "major" language to have garbage collection built-in) gave garbage collection a bad reputation because it only allows mutable user-defined types (and passes all objects by pointers), making it quite hard to avoid heap allocation of even very small objects.
- Julia (and C#) encourage the use of immutable types
- Julia pass variables by reference (so they can pass variables on the stack)
- C# passes variables by value by default (so they stay on stack, but often unnecessary stack allocations) and can pass by reference.
"""
630 μs

I am still a bit confused about the high-water mark technique for creating flexibly-sized arrays/vectors. How do we determine the logical size that we need to make effective use of memory allocation? Is this just the true size of the vector instead of the actual size?

blockquote(md"""
I am still a bit confused about the high-water mark technique for creating flexibly-sized arrays/vectors. How do we determine the logical size that we need to make effective use of memory allocation? Is this just the true size of the vector instead of the actual size?
""")
255 μs

The idea is to allocate for the maximum possible size. But that only works if you can figure that out in advance.

md"""
The idea is to allocate for the maximum possible size. But that only works if you can figure that out in advance.
"""
278 μs

Is there a different technique for creating flexible array sizes in Julia that doesn't require doubling of your physical size every time you add a row/column?

blockquote(md"""Is there a different technique for creating flexible array sizes in Julia that doesn't require doubling of your physical size every time you add a row/column?
""")
809 μs

By doubling the size allocated, you need to change the size much less often than if you increased by 1.

md"""
By doubling the size allocated, you need to change the size much less often than if you increased by 1.
"""
282 μs

The reading talks about being cache friendly– if we were performing a search wouldn't how cache friendly the search is be dependent on the search algorithm? How do we know what type of search algorithm is being used if we didn't write the code ourselves? How would we know how to optimize the structure of our code based on the search algorithm we are using and how the program/computer access memory?

blockquote(md"""
The reading talks about being cache friendly-- if we were performing a search wouldn't how cache friendly the search is be dependent on the search algorithm? How do we know what type of search algorithm is being used if we didn't write the code ourselves? How would we know how to optimize the structure of our code based on the search algorithm we are using and how the program/computer access memory?
""")
268 μs
  • Read the documentation

  • Choose the algorithm for your problem (e.g., Description of sorting algorithms)

  • Consider order of algorithm and whether in-place

  • Most often, I choose the algorithm that's best fit for my data.

  • But sometimes I might change the data structure to be a better fit for my algorithm

md"""
- Read the documentation
- Choose the algorithm for your problem (e.g., [Description of sorting algorithms](https://docs.julialang.org/en/v1/base/sort/#Base.Sort.InsertionSort))
- Consider order of algorithm and whether *in-place*
- Most often, I choose the algorithm that's best fit for my data.
- But sometimes I might change the data structure to be a better fit for my algorithm
"""
22.9 ms
all(x_sorted_default .== x_sorted_insertion) && (all(x_sorted_default .== x_sorted_merge) && all(x_sorted_default .== x_sorted_quick))
true
begin
x = rand(100)
x_sorted_default = sort(x)
x_sorted_insertion = sort(x, alg=InsertionSort)
x_sorted_merge = sort(x, alg=MergeSort)
x_sorted_quick = sort(x, alg=QuickSort)
end
207 ms
begin
local n = 100
vec_of_pairs = collect(zip(rand(1:10,n), randn(n)))
end
62.5 μs

But be careful... sometimes different algorithms give different results. E.g., whether sorting is stable.

md"""
But be careful... sometimes different algorithms give different results. E.g., whether sorting is **stable**.
"""
316 μs
begin
function less_than_custom(a::Tuple,b::Tuple)
return a[1]<b[1]
end
sorted_merge = sort(vec_of_pairs,lt=less_than_custom, alg=MergeSort)
sorted_quick = sort(vec_of_pairs,lt=less_than_custom, alg=QuickSort)
end
240 ms
14.1 μs
!(all(sorted_merge .== sorted_quick)) !(all(
.== sorted_quick))
!(all(
.==
))
!(all(
))
!
false
true
1.2 s

Resume here on Wedneseday

md"""
# Resume here on Wedneseday
"""
283 μs

Other Questions

md"""
## Other Questions
"""
325 μs

How does memory function from cell-to-cell within a notebook? Is it more efficient to split up code over many cells, or have them operate in the same one? How does this impact runtime and general performance?

blockquote(md"""
How does memory function from cell-to-cell within a notebook? Is it more efficient to split up code over many cells, or have them operate in the same one? How does this impact runtime and general performance?
""")
330 μs
  • It's more efficient to split up code into separate functions (regardless of whether they are in the same cell or not).

  • There might be a very slight latency cost of having lots of cells. But that's unlikley significant unless you are making a really big notebook.

md"""
- It's more efficient to split up code into separate functions (regardless of whether they are in the same cell or not).
- There might be a very slight latency cost of having lots of cells. But that's unlikley significant unless you are making a really big notebook.
"""
416 μs

Can you demonstrate how to import a julia program into python?

blockquote(md"""
Can you demonstrate how to import a julia program into python?
""")
288 μs

First, setup PyCall.jl (to call Python from Julia) by running

> julia -e 'import Pkg; Pkg.add("PyCall");'

You only need to do that once (for each system you're running it on).

md"""
First, setup PyCall.jl (to call Python from Julia) by running
```shell
> julia -e 'import Pkg; Pkg.add("PyCall");'
```
You only need to do that once (for each system you're running it on).
"""
396 μs

Then from python/Jupyter notebook with Python kernel

md"""
Then from python/Jupyter notebook with Python kernel
"""
354 μs
from julia.api import Julia
julia = Julia(compiled_modules=False)
from julia import Base
Base.sind(90)
md"""
```python
from julia.api import Julia
julia = Julia(compiled_modules=False)
from julia import Base
Base.sind(90)
```
"""
219 μs
from julia import Main as jl
jl.exp(0)
jl.xs = [1, 2, 3]
jl.eval("sin.(xs)")
md"""
```python
from julia import Main as jl
jl.exp(0)
jl.xs = [1, 2, 3]
jl.eval("sin.(xs)")
```
"""
184 μs
import numpy as np
x = np.array([1.0, 2.0, 3.0])

jl.sum(x)
md"""
```python
import numpy as np
x = np.array([1.0, 2.0, 3.0])

jl.sum(x)
```
"""
159 μs
jl.include("my_julia_code.jl")
jl.function_in_my_julia_code(x)
md"""
```python
jl.include("my_julia_code.jl")
jl.function_in_my_julia_code(x)
```
"""
196 μs

Inside Jupyter notebook:

In [1]: %load_ext julia.magic
Initializing Julia runtime. This may take some time...

In [2]: %julia [1 2; 3 4] .+ 1
Out[2]:
array([[2, 3],
       [4, 5]], dtype=int64)
In [3]: arr = [1, 2, 3]

In [4]: %julia $arr .+ 1
Out[4]:
array([2, 3, 4], dtype=int64)

In [5]: %julia sum(py"[x**2 for x in arr]")
Out[5]: 14
md"""
Inside Jupyter notebook:
```python
In [1]: %load_ext julia.magic
Initializing Julia runtime. This may take some time...

In [2]: %julia [1 2; 3 4] .+ 1
Out[2]:
array([[2, 3],
[4, 5]], dtype=int64)
In [3]: arr = [1, 2, 3]

In [4]: %julia $arr .+ 1
Out[4]:
array([2, 3, 4], dtype=int64)

In [5]: %julia sum(py"[x**2 for x in arr]")
Out[5]: 14
```
"""
230 μs

Data structures

md"## Data structures"
245 μs

What [is] a linked list?... how we might find it useful in our projects?

blockquote(md"""What [is] a linked list?... how we might find it useful in our projects?""")
242 μs

Linked List

Use array when:

  • Know size at time of creation (or won't need to change size often)

  • Value fast access to elements (not just the beginning/end)

  • Value not allocating more memory than memory

  • Very common for scientific performance sensitive code

Use linked list when:

  • Likely to insert elements and/or change size often

  • Don't mind taking longer to access elements (other than beginning/end)

  • Value not allocating (much) more memory than necessary

  • Useful for frequent sorting

Other common data structures to consider...

md"""
![Linked List](https://upload.wikimedia.org/wikipedia/commons/thumb/6/6d/Singly-linked-list.svg/640px-Singly-linked-list.svg.png)

Use **array** when:
- Know size at time of creation (or won't need to change size often)
- Value fast access to elements (not just the beginning/end)
- Value not allocating more memory than memory
- Very common for scientific performance sensitive code

Use **linked list** when:
- Likely to insert elements and/or change size often
- Don't mind taking longer to access elements (other than beginning/end)
- Value not allocating (much) more memory than necessary
- Useful for frequent sorting

Other common data structures to consider...
"""
38.2 ms

Hash table (aka dictionary/Dict) when:

  • Elements unlikely to be accessed in any particular order

  • Value pretty fast access to individual elements

  • Don't mind allocating significantly more memory than necessary

  • Useful for scripting, non-performance sensitive code

Hash table - source Wikimedia, Jorge Stolfi, CC-BY-SA-3.0

md"""
### **Hash table** (aka dictionary/`Dict`) when:
- Elements unlikely to be accessed in any particular order
- Value pretty fast access to individual elements
- Don't mind allocating significantly more memory than necessary
- Useful for scripting, non-performance sensitive code

![Hash table](https://upload.wikimedia.org/wikipedia/commons/thumb/7/7d/Hash_table_3_1_1_0_1_0_0_SP.svg/1024px-Hash_table_3_1_1_0_1_0_0_SP.svg.png) - source [Wikimedia](https://commons.wikimedia.org/wiki/File:Hash_table_3_1_1_0_1_0_0_SP.svg), Jorge Stolfi, [CC-BY-SA-3.0](https://creativecommons.org/licenses/by-sa/3.0/deed.en)
"""
11.3 ms

Some form of tree when:

  • Elements have a meaningful order

  • Value fast adding/removing and searching of elements

  • Value not allocating (much) more memory than necessary

  • Don't mind taking longer to access individual elements

  • Willing to spend some time maintaing well-ordered tree

  • Common in database type applications

Generic tree (not particularly useful)

Unbalanced tree - source Wikimedia

Balanced binary tree

Balanced tree - source Wikimedia

md"""
### Some form of **tree** when:
- Elements have a meaningful order
- Value fast adding/removing and searching of elements
- Value not allocating (much) more memory than necessary
- Don't mind taking longer to access individual elements
- Willing to spend some time maintaing well-ordered tree
- Common in database type applications

#### Generic tree (not particularly useful)
![Unbalanced tree](https://upload.wikimedia.org/wikipedia/commons/a/a9/Unbalanced_binary_tree.svg) - source [Wikimedia](https://en.wikipedia.org/wiki/File:Unbalanced_binary_tree.svg)

#### Balanced binary tree
![Balanced tree](https://upload.wikimedia.org/wikipedia/commons/0/06/AVLtreef.svg) - source [Wikimedia](https://en.wikipedia.org/wiki/File:AVLtreef.svg)
"""
16.1 ms

Preping for Code Review

Make it easy for your reviewer

  • Provide overview of what it's doing in README.md

  • Include an example of how to run/use code

  • What files should they focus on?

  • What files should they ignore?

  • Where should they start?

  • What type of feedback would you be most appreciative of?

Make it easy for you

If you have a large code base, then

  • Move most code out of notebooks and into .jl files, as functions mature.

    • @ingredients "src/my_great_code.jl from Pluto notebooks

    • include("src/my_great_code.jl") from Jupyter notebooks

    • Near end of semester, I'll describe how to make your code into a registered package. Then you could simple do use MyGreatPackage.

  • Organize functions into files .jl files in src directory

  • Use test, examples, data, docs, etc. directories as appropritate

md"""
# Preping for Code Review
## Make it easy for your reviewer
- Provide overview of what it's doing in README.md
- Include an example of how to run/use code
- What files should they focus on?
- What files should they ignore?
- Where should they start?
- What type of feedback would you be most appreciative of?

## Make it easy for you
If you have a large code base, then
- Move most code out of notebooks and into `.jl` files, as functions mature.
- `@ingredients "src/my_great_code.jl` from Pluto notebooks
- `include("src/my_great_code.jl")` from Jupyter notebooks
- Near end of semester, I'll describe how to make your code into a registered package. Then you could simple do `use MyGreatPackage`.
- Organize functions into files `.jl` files in `src` directory
- Use `test`, `examples`, `data`, `docs`, etc. directories as appropritate
1.4 ms

Peer Code Review Rubric

  • Constructive suggestions for improving programming practices (1 point)

  • Specific, constructive suggestions for improving code readability/documentation (1 point)

  • Specific, constructive suggestions for improving tests and/or assertions (1 point)

  • Specific, constructive suggestions for improving code modularity/organization/maintainability (1 point)

  • Specific, constructive suggestions for improving code efficiency (1 point)

  • Finding any bugs (if code author confirms) (bonus points?)

md"""
## Peer Code Review Rubric
- Constructive suggestions for improving programming practices (1 point)
- Specific, constructive suggestions for improving code readability/documentation (1 point)
- Specific, constructive suggestions for improving tests and/or assertions (1 point)
- Specific, constructive suggestions for improving code modularity/organization/maintainability (1 point)
- Specific, constructive suggestions for improving code efficiency (1 point)
- Finding any bugs (if code author confirms) (bonus points?)
"""
785 μs

Don't make assumptions cartoon

(Credit: Manu via BetterProgramming.pub)

md"""
![Don't make assumptions cartoon](https://miro.medium.com/max/560/1*g95FYDe5j9X_9SqEj1tycQ.jpeg)

(Credit: [Manu](https://ma.nu/) via [BetterProgramming.pub](https://betterprogramming.pub/13-code-review-standards-inspired-by-google-6b8f99f7fd67))
"""
452 μs

Learning from others with more experience conducting Code Reviews

Best Practices for Code Review @ Smart Bear

  1. Review fewer than 400 lines of code at a time

  2. Take your time. Inspection rates should under 500 LOC per hour

  3. Do not review for more than 60 minutes at a time

  4. Set goals and capture metrics

  5. Authors should annotate source code before the review

  6. Use checklists

  7. Establish a process for fixing defects

  8. Foster a positive code review culture

  9. Embrace the subconscious implications of peer review

  10. Practice lightweight code reviews

md"""
# Learning from others with more experience conducting Code Reviews
## [Best Practices for Code Review @ Smart Bear](https://smartbear.com/learn/code-review/best-practices-for-peer-code-review/)
1. Review fewer than 400 lines of code at a time
2. Take your time. Inspection rates should under 500 LOC per hour
3. **Do not review for more than 60 minutes at a time**
4. Set goals and capture metrics
5. **Authors should annotate source code before the review**
6. **Use checklists**
7. Establish a process for fixing defects
8. **Foster a positive code review culture**
9. Embrace the subconscious implications of peer review
10. **Practice lightweight code reviews**
"""
1.4 ms

How to excel at code reviews @ BetterProgramming

  1. The code improves the overall health of the system

  2. Quick code reviews, responses, and feedback

  3. Educate and inspire during the code review

  4. Follow the standards when reviewing code

  5. Resolving code review conflicts

  6. Demo UI changes as a part of code review

  7. Ensure that the code review accompanies all tests

  8. When focused, do not interrupt yourself to do code review

  9. Review everything, and don’t make any assumptions

  10. Review the code with the bigger picture in mind

md"""
## [How to excel at code reviews @ BetterProgramming](https://betterprogramming.pub/13-code-review-standards-inspired-by-google-6b8f99f7fd67)
1. The code improves the overall health of the system
2. Quick code reviews, responses, and feedback
3. **Educate and inspire during the code review**
4. Follow the standards when reviewing code
5. Resolving code review conflicts
6. Demo UI changes as a part of code review
7. Ensure that the code review accompanies all tests
8. **When focused, do not interrupt yourself to do code review**
9. Review everything, and **don’t make any assumptions**
10. **Review the code with the bigger picture in mind**
"""
1.3 ms

Code Review Best Practices @ Palantir

Purpose

  • Does this code accomplish the author’s purpose?

  • Ask questions.

Implementation

  • Think about how you would have solved the problem.

  • Do you see potential for useful abstractions?

  • Think like an adversary, but be nice about it.

  • Think about libraries or existing product code.

  • Does the change follow standard patterns?

  • Does the change add dependencies?

  • Think about your reading experience.

  • Does the code adhere to coding guidelines and code style?

  • Does this code have TODOs?

Maintainability

  • Read the tests.

  • Does this CR introduce the risk of breaking test code, staging stacks, or integrations tests?

  • Leave feedback on code-level documentation, comments, and commit messages.

  • Was the external documentation updated?

md"""
## [Code Review Best Practices @ Palantir](https://blog.palantir.com/code-review-best-practices-19e02780015f)
### Purpose
- Does this code accomplish the author’s purpose?
- **Ask questions.**

### Implementation
- **Think about how you would have solved the problem.**
- Do you see potential for useful abstractions?
- **Think like an adversary, but be nice about it.**
- Think about libraries or existing product code.
- Does the change follow standard patterns?
- **Does the change add dependencies**?
- Think about your reading experience.
- Does the code adhere to coding guidelines and code style?
- Does this code have TODOs?

### Maintainability
- **Read the tests**.
- Does this CR introduce the risk of breaking test code, staging stacks, or integrations tests?
1.9 ms

Prioritizing Code Review Feedback

Handle conflicts different based on the severity. Credit: Alex Hill

md"""
## Prioritizing Code Review Feedback
![Handle conflicts different based on the severity. Credit: Alex Hill](https://miro.medium.com/max/560/1*zOvsiXkzqVJ7O8KalHhDZQ.jpeg)
- Credit: [Alex Hill](https://betterprogramming.pub/13-code-review-standards-inspired-by-google-6b8f99f7fd67)
"""
497 μs

Peer Code Review Rubric = Reviewer's checklist

  • Constructive suggestions for improving programming practices

  • Specific, constructive suggestions for improving code readability/documentation

  • Specific, constructive suggestions for improving tests and/or assertions

  • Specific, constructive suggestions for improving code modularity/organization/maintainability

  • Specific, constructive suggestions for improving code efficiency

  • Finding any bugs (bonus points?)

md"""
## Peer Code Review Rubric = Reviewer's checklist
- Constructive suggestions for improving programming practices
- Specific, constructive suggestions for improving code readability/documentation
- Specific, constructive suggestions for improving tests and/or assertions
- Specific, constructive suggestions for improving code modularity/organization/maintainability
- Specific, constructive suggestions for improving code efficiency
- Finding any bugs (bonus points?)
"""
781 μs

Old Questions

md"""
## Old Questions
"""
218 μs

Q: Is it always best to insure a code passes all tests before anything else?

A1: Can anyone want share counter examples?

A2: Story of Kepler database

md"""
**Q:** Is it always best to insure a code passes all tests before anything else?

**A1:** Can anyone want share counter examples?

**A2:** Story of Kepler database
"""
519 μs

Q: Even with a readme file and annotations, what are ways we can determine what the code does and whether the approach is correct or wrong?

Ask for clarification

md"""
**Q:** Even with a readme file and annotations, what are ways we can determine what the code does and whether the approach is correct or wrong?

Ask for clarification"""
334 μs

Setup

md"""
# Setup
"""
224 μs

ToC on side

md"ToC on side $(@bind toc_aside CheckBox(;default=true))"
183 ms
TableOfContents(aside=toc_aside)
17.6 μs
begin
using PlutoUI, PlutoTest, PlutoTeachingTools
end
772 ms