I started this blog as a note on my computer during office hours I host for the Computational Resource Access Network (CRANE, a scientific computing boot camp taught by scientists for scientists). Through CRANE we teach coding in Python from the ground up and get through algorithms and tools currently used in cutting-edge research.
I am still learning, and this entry is as much for myself as anyone else (it forced me to write down some of the things that have worked for me when explaining coding concepts); however, I do hope that these explanations and analogies stand as good starts to the variety of concepts covered in CRANE.
I heard my advisor in an interview once quote one of her collaborators in grad school saying, "I went to the school of open source." I love this mentality about learning to code because getting hands-on experience is one of the best ways to learn. It ties in with another idea I’ve heard in various open-source forums, instead of accepting "believe me", we should be training people to say "show me." These two principles are core tenets of my approach to sharing what I’ve learned, and my attempts to learn going forward.
Ok, let’s get into some of these analogies:
1. Version control with git
Analogy: Git is like a tool to build sandboxes for your coding projects, with a powerful “undo button,” that can combine them if you like what’s inside.
There is a panoply of version control tools you can use. In CRANE, we focus on git, which creates checkpoints in your code so you can hit the “undo button” if and when something goes wrong. A little bit more powerful than the undo button because we can make a separate sandbox to play around in (if it works, we can combine them, and if it doesn't, we can delete it and forget it happened).
2. Writing with LaTeX
Analogy: LaTeX is like a Word doc, except you are making the blueprints.
LaTeX is a powerful typesetting tool that lets you write equations, build bibliographies, add plots and figures, and more with a high level of control. We use the analogy of a blueprint because people rarely look at the .tex file of a finished product, even though that's what the architects spend their time looking at to "create" the building. Someone else does the compiling of the building from the blueprint, in the case of LaTeX some program builds your pdf.
3. Docstrings for functions
Analogy: Docstrings are like the metadata that come with images, like where or when the photo was taken.
There are various sections you can add, but a basic docstring has a summary of the function and spells out the type and definition for each parameter and output. They are helpful notes to future users (especially yourself) on how you intend it to be used.
4. Packages and libraries
Analogy: Packages are like plugins that can teach Python about more specific subjects (like linear algebra or physics).
In this analogy, Python is a framework that has some basic capabilities, but to do science we can take advantage of the work done before us by plugging in scientific Python packages.
5. Arrays and 2d arrays
Analogy: An array is like a vector, and 2d arrays are like matrices or like a list of lists.
I've found the idea of a list of lists helpful, especially for people who have not yet taken linear algebra.
6. Indexing and slicing
Analogy: Indexing is like telling Python to look at a single value in a list or array, whereas slicing is like taking a cross-section of the values.
Using a comma means you're identifying a new piece of information, and a colon means you are bounding the same piece of information.
7. Plot subfigures
Analogy: Subfigures can be used like you’re adding new layers or regions to a painting.
They can also be plotted in different frames, but the idea of painting is how I have helped people understand different plotting objects and how they are combined.
8. Nested loops
Analogy: A nested loop is like an escape room with multiple rooms, or a dungeon in DnD.
This can be a tricky concept for some people to wrap their brains around, but I've found that people latch on to the idea of moving to a new room and completing all the tasks there before moving on.
9. Classes
Analogy: Classes are like machines/factories made up of a bunch of processes (functions) that can take in information and output the result of these processes.
I have only taught introductory coding, but I think this gives people a foothold into why a class might be useful.
10. Mesh Grids
Analogy: Mesh grids are like blank canvas you can layer information on top of.
In CRANE we work through many coding concepts, but mesh grids are one of those things that we always get questions about. Talking about mesh grids as a canvas usually helps give students intuition about how to interact with them. I can't take credit for this analogy, it's how I was taught about mesh grids in my undergraduate introductory computer science course.
11. ODE vs PDE
Computation and math are inexorably linked, so we often think of different ways to condense the math from a topic. In our physics lessons, we go through how to solve equations numerically and I will often explain ODEs and PDEs with an analogy to driving a car.
Say you’re driving a car along a straight road at a constant velocity. You can tell us where the car is at just by knowing where it started and how long it’s been driving, right? That’s an Ordinary differential equation, we have enough information to link the position and time completely by a constant velocity.
Now, let’s say you're driving the car for so long that you pass through a section that had been rained on. To describe the force of friction for the system, you need the coefficient of friction that the car experiences. The problem is now partially dependent on time and partially dependent on position. This is a partial differential equation.
12. 2nd order Runge-Kutta
Analogy: RK2 is essentially where you weight the front and back end of a time step equally.*
*I recognize this is a big simplification of the process, but as part of the explanation of the method I’ve found this was a helpful bit to add.
I hope these analogies help you understand some of the concepts we cover in CRANE. I am always looking for new ways to explain things, so if you have any suggestions, please let me know!