Teaching Advice

Advice for teaching courses on Python for chemists:

From in-class and informal experiences.

Why did you use X instead of Y?

Why use Anaconda instad of pip, distribution xyz, etc.?

We have tried both in classes and group seetings and found that Anaconda leads to the fewest problems for students totally new to coding. Some specific observations:

  • Using the Spyder variable explorer that comes with Anaconda allows inspection of objects defined in user-installed librarires.
  • Most Python ecosystem maintenance can be done using a GUI.
  • Anaconda is more frequently found in computer labs and is easier for IT departments to support.

Why use Spyder instead of VSCode, PyCharm, etc.?

Students often have some name recognition with VSCode and see it as a modern/de facto IDE. We suggest Spyder for the following reasons:

  • Spyder works out of the box, requring no installation of plugins or extension to gain important features.
  • Spyder features a powerful and intuitive variable explorer that is much more helpful than any solution in VSCode.
  • Spyder features a Plots pane that contains a history of plots, which allows students to easily see how different code changes plot outputs. As students become more adept, we certainly encourage them to find solutions that work for them. The authors are enthusiastically following the development of [Positron]{https://positron.posit.co/}, which is still in beta as of March 17, 2025, but has been used by both authors for several months with great success.

Why not use Jupyter Notebooks?

We find that students just starting out in programming struggle with the cell-based organization of Jupyter notebooks:

  • Cells and the user intervention involved in running them obscures the control of program execution provided by built-in flow control structures, leading to students misunderstanding principles of code organization.
  • The need for user intervention increases the chance for mistakes and reduces the utility of coding for speeding up work by automation.
  • It is possible to have variables that have multiple different values when cells are run out of order, leading to unexpected behaviors, incorrect results, and confusion for students. We certainly encourage students to explore Jupyter notebooks as they become more comfortable with coding. We also recommend anyone interested in Jupyter notebooks to check out [the Marimo project]{https://marimo.io/}, which alleviates most of these issues.

Addressing common student struggles

Take your time to really explain file structure.

The primary computer that many of your students use is their phone. They see “traditional” computers as devices for playing games or writing term papers. As a result, many have little experience with and understanding of the file system. We often see students working entirely out of their Downloads folder or Desktop, not understanding that there is a hierarchical relationship between folders, not understanding that the shortcuts to folders on the sidebars of file explorers are just links, or even that they are locations in a file system, and more. It is almost impossible to spend too much time helping them to become familiar with the file system.

Conceptual questions are important.

Students will often solve problems by trial and error, and will often not reflect on why their code worked. They also will produce code that works correctly for the wrong reason, or will produce code that only works for one narrow case. Emphasizing conceptual questions has been very helpful for this.

Ask students to solve problems using multiple approaches

In addition to addressing the issues in the previous point, this helps them to realize that there are multiple ways to solve any programming problems and gives you an opportunity to ask them conceptual questions about the strengths and weaknesses of different approaches. This forces them to analyze their solutions rather than simply to be satisfied that their code works.

Ask students to work out code results by hand.

Having students start with working code is a great way for them to absorb code organization and algorithm design, but they will often be satisfied with seeing that the code works and not understand why. Forcing them to work out the values of all variables in the code, line by line, forces them to slow down and analyze the execution of the code. It is surprising that students can often tell you correctly how a code works, but when forced to work out through the same code, will get its execution wrong.

Pen and paper exams are quite useful.

We find that having students produce working code on a tight timeline is not effective. Students stumble over typos, neglect important points in planning and code organization, internalize an approach to programming that prioritizes producing the correct answer as quickly as possible. We recommend midterm/final exams and homework problems that involve no coding. Instead, we suggest:

  • Conceptual multiple choice problems
  • Problems to work out by hand the intermediate and final results of working code
  • Problems that ask students to read documentation for a function/class and answer questions about its usage
  • Problems that ask students to write single lines of code that do clearly defined tasks
  • Asking students to find syntax and logical errors in code provided to them
  • Asking students for alternate approaches to a solution given to them as working code
  • Asking students to sketch out solutions using flow charts, pseudocode procedures, etc.

Acknowledge that LLMs exist.

Your students know that ChatGPT etc. can write code for them, and you can not fight this. Our philosophy is that we are teaching problem solving in chemistry using coding, not producing coders. Thus, LLMs can be useful partners for them. We recoommend:

  • Having students use an LLM to solve a problem and then follow up by asking the LLM questions about how the code works, why it is the way it is, and what alternative approaches could be used.
  • Requiring students to use specific libraries. LLMs will often pick libraries that you are not instructing on, and students will just accept this without trying to understand the new library or understand how the code works. Having them ask the LLM to use libraries with which they are already familiar enriches their learning experience and de-emphasizes the trial-and-error approach to problem solving.

Be purposeful regarding what you will grade on homework.

In grading, we emphasize (in order of importance):

  • Correctness
  • Comments
  • Code readability
  • Code organization
  • Code maintainability For problems that produce plots as output, we typically give the students the plot to output and require them to figure out how to match the formatting rather than simply spitting out plots with default formatting and minimal annotation and labeling.