diff --git a/Day_4/Day_4.jl b/Day_4/Day_4.jl index f75a5e0..ce77222 100644 --- a/Day_4/Day_4.jl +++ b/Day_4/Day_4.jl @@ -21,9 +21,14 @@ begin TableOfContents() end +# ╔═╡ 899a86c4-89e5-4779-8191-2b38ead6d567 +md""" +# Workflow +""" + # ╔═╡ 81b6211e-b065-11ec-0a86-375721c85b07 md""" -# Jupyter notebooks +## Jupyter notebooks Although Pluto notebooks are very interactive and revolutionary, there are some cases where they provide you with too much interactivity. This is especially a problem when you are mutating a variable in a different cell. You can always use `begin` blocks, but sometimes, this is not practical. Jupyter notebooks don't rerun every cell depending on a variable that was just updated. Cells are only run manually. @@ -59,7 +64,7 @@ Launch JupyterLab or Jupyter. You should see the Julia kernel listed now! 🎉 # ╔═╡ 7f45c502-0909-42df-b93d-384f743df6a9 md""" -# VS Code/Codium +## VS Code/Codium If you are working on a big project, then splitting code up into different files does help maintaining it. Therefore, notebooks should not be used for big projects. Because you should avoid using global variables in Julia and instead only call functions, you will not achieve the maximum performance using a notebook because of its workflow that does not support working only with functions. See the section about performance in this notebook. @@ -89,7 +94,7 @@ I you are using the last method, consider using [Revise](https://timholy.github. # ╔═╡ f23ad33d-af1d-40c2-9efc-17ef8c4d1fb8 md""" -# Environments +## Environments If you are working on a project and not using Pluto notebooks, you should be using environments. Environments separate project dependencies (packages). Therefore, you are less likely to have any conflicts between two packages. They also allow you to use a different version of a package for every project. @@ -127,7 +132,7 @@ In the package manager prompt, run the following to remove a package from your e # ╔═╡ 6340aec8-6f77-4a30-8815-ce76ddecd6e8 md""" -# REPL +## REPL The Julia REPL is what you get when you launch Julia in the terminal. The REPL is very useful if you want to quickly experiment with something or test if a function works how you do imagine. @@ -301,7 +306,7 @@ function thread_unsafe_sum(N) sum_of_sums = 0 Threads.@threads for i in 1:N - sum_of_sums = sum(1:i) + sum_of_sums += sum(1:i) end return sum_of_sums @@ -334,11 +339,11 @@ end # ╔═╡ 8ad3daa6-d221-4ff7-9bc2-8e8a66bdd8c7 # Stable! -@btime thread_safe_sum(N2) +sum_of_sums = @btime thread_safe_sum(N2) # ╔═╡ 95dffc7f-3393-487e-8521-c96291cdc7bf # Verify that we did not exceed the limit! -typemax(Int64) +typemax(Int64) > sum_of_sums # ╔═╡ ebd3a9d9-7a12-4001-9b53-913f664fb1c8 # Lets try shuffling again @@ -408,7 +413,7 @@ md""" N3 = 1000000 # ╔═╡ 2a24aebc-0654-4d00-bdab-627a8e1a75f2 -# Use a global array of type Any +# Bad usage of a global array of type Any (container with abstract type) begin sin_vals = [] @@ -491,13 +496,13 @@ end # ╔═╡ 43d2cbda-a21b-46ae-8433-7a9ef30c536b md""" ## `StaticArrays` -If you are dealing with small arrays with less than 100 elements, then take a look at the package [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl). Especially if you are dealing with 2d or 3d coordinates, using `StaticArrays` will make a big performance difference. +If you are dealing with small arrays with less than 100 elements, then take a look at the package [`StaticArrays.jl`](https://github.com/JuliaArrays/StaticArrays.jl). Especially if you are dealing with 2D or 3D coordinates, using `StaticArrays` will make a big performance difference. """ # ╔═╡ f0b634a5-19a9-4c61-932f-7ae357e13be2 md""" ## Profiling -Of course, you can profile your code in Julia. Check the package [ProfileView](https://github.com/timholy/ProfileView.jl) for example. +Of course, you can profile your code in Julia. Check out the package [ProfileView](https://github.com/timholy/ProfileView.jl) for example. """ # ╔═╡ 00000000-0000-0000-0000-000000000001 @@ -729,6 +734,7 @@ uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" """ # ╔═╡ Cell order: +# ╟─899a86c4-89e5-4779-8191-2b38ead6d567 # ╟─81b6211e-b065-11ec-0a86-375721c85b07 # ╟─7f45c502-0909-42df-b93d-384f743df6a9 # ╟─f23ad33d-af1d-40c2-9efc-17ef8c4d1fb8