Tutorial 10. Multilingual in programming?

Learning objectives

  • Get some tips about learning programming as a beginner in computational chemistry.
  • Topics:
    1. The first language to learn?
    2. From one to more?
    3. More isn’t always better

Introduction

Computational chemists often get the feeling that they need to work with multiple programming languages. For example:

  • To use machine learning packages, you feel you need Python.
  • To develop new functionality in a quantum chemistry code, you find that you need to read and modify the historical code written in the 70s, which are unfortunately, Fortan77.
  • To implement fancy parallel algorithm on GPUs, you want to embrace CUDA, and inevitably, you also need C++.
  • To implement an advanced graphical interface for your package, you may feel that JavaScript or Qt ( or Tcl/Tk, maybe too old) is needed.
  • To make your computational database available to the public, you find it necessary to learn some language related to building a website.

I will share some of my opinions about learning multiple programming languages.

Disclaimer some of the following contents are personal opinions and may not fit your learning needs.

Which programming language should I learn first?

This may be a common question asked by beginners. I’d like to answer it from 3 aspects.

  1. Many times, it’s not like we intentionally choose which language to start with, but we encounter our first programming language and need to use it. Some of us may have a required programming course to take, and the language used in that course automatically becomes our first language. My first language is C, which may seem very odd because nowadays, most colleges are teaching introductory level programming courses with Python or Java. However, C is a required course in my undergraduate curriculum. The first language may also be the language needed for your first research project.

  2. If you are free to choose any language to start with and not restricted to curriculum requirements, I would recommend Python or Julia for their versatility and easiness.

  3. However, the main point is that it doesn’t matter too much which language you pick first. The concepts are similar among different languages, and algorithmic thinking does not depend on programing language. You should choose one language most needed for your research and try to be proficient with it.

I have learned one programming language. How do I go for more?

If you ever ask yourself this question, please think about answering another question first:

  • Why do I need that new language? Is it necessary?

In many cases, we can find workarounds without learning a new language. Nowadays, many interfaces are bridging different languages. For example, I can make web pages like this tutorial website you are currently reading with Markdown, which I already use in Jupyter notebooks. Although this website is built with Ruby and rendered in HTML, I don’t need to code a single line of Ruby or HTML, because the Jekyll environment automatically converts my Markdown text into the webpage.

Similarly, many quantum chemistry programs originally written in C/C++/Fortran are now interfaced with Python, and a Python coder can work with the Python interface without digging into C/C++/Fortran.

These workarounds reduce the overhead for learning a new language and help you focus on your research rather than the technical hassles.

I really have the need to learn a second language. Any tips and tricks?

I can share a few tips.

  1. Python to C/C++. Nowadays, most students start with Python and later need C/C++ for some research projects. I recommended some intro-level Coursera courses for C/C++, and they found it helpful. One is the Programming Fundamentals by Duke University. The other is the Object-Oriented Data Structures in C++ by UIUC. Both are short courses that can be completed within 21 hours. Another online course I always recommend is the CS 106B Programming Abstractions offered by Stanford University, which is more advanced than the two courses mentioned above according to the feedbacks of my students.

  2. C to C++. I can share my personal experience. My first programming language is C, and later learned C++ from CS 106B Programming Abstractions. For me, the most valuable part about learning C++ is to learn the Object Oriented Programming idea, which is thoroughly discussed in CS106B.

  3. C to Python. I guess this rarely happens nowadays since most colleges offer high-level languages in the intro-level programming course. If you have a similar experience as me (learning C before learning Python), then here is my experience. The biggest difference I find is that I can code in C without the Internet, but I cannot code in Python without the Internet. I need to search the Python online documentation about the usage of different packages all the time. That is also how I learned Python: as a C/C++ programmer, I have never taken any formal training on Python, but I learn it while I code by checking the online documentation and examples.

  4. C/C++ to CUDA. I will talk about that in another tutorial.

Take home messages

More Isn’t Always Better. You don’t need to learn more programming languages when there is an alternative solution with the language you know.

Written on August 15, 2021