Practical Guidance for Coding in Science and Engineering Fields
Written on
Learning to code can be quite challenging due to the multitude of programming languages available and the varying approaches to coding within a single application. The structure of code often defies common logic, making it difficult for newcomers to grasp. However, if you find a method that suits your learning style, mastering coding becomes significantly easier. In fields like physics and chemical engineering, coding proficiency is increasingly essential. Starting this journey can feel overwhelming, but learning from the experiences of others can provide invaluable support.
Why Pursue Coding and What Is the Learning Experience Like?
I began coding nearly two decades ago as part of my undergraduate studies. During a physics course, I self-taught a language called Fortran using a well-structured handbook filled with examples, which I found enjoyable. At that time, I never anticipated how beneficial this skill would become in my career.
Fast forward to today, and physics students are more frequently introduced to Python, a markedly different programming language. Fortran includes standard mathematical functions, such as logarithms and trigonometric functions, but that's about all it offers. Python, in contrast, boasts dedicated packages for specific applications. For instance, the Astropy package allows users to convert between various astronomical coordinate systems, enabling them to concentrate on other aspects of astrophysics. These packages can automate routine tasks, which is particularly helpful in your field. Additionally, numerous online resources exist for learning Python without needing to enroll in a physics program. However, applying programming skills to real physics experiments can enhance your learning experience by presenting practical challenges.
Matlab shares similarities with Python as a programming platform, allowing for tasks like controlling robotic arms while providing specialized tools to streamline data analysis. For example, if you have experimental data showing mass changes over time, CFTool can fit equations to this data. Yet, understanding the context and physical limitations of your experiment is crucial to determine whether the fitted equation is meaningful. While coding simplifies fitting equations to data, true insight comes from a solid understanding of the subject matter.
In scenarios with vast amounts of data, coding becomes indispensable for data analysis and presentation. In particle physics, for instance, you might collect close to a billion data points but only need a specific subset. Utilizing conditional statements in your code can filter this data far more efficiently than manually sifting through billions of entries.
Fortran, Matlab, and Python all employ conditional statements, allowing them to assist in data filtering and decision-making. When I transitioned from physics to a PhD in computational chemistry, I created computer models of molecules. I could write code that compared the distance between two atoms to the ideal bond length, enabling me to make necessary adjustments. Coding also simplifies repetitive tasks through loops. For example, instructing simulation software to identify which of thousands of atoms are bonded and their respective angles could take days to complete manually, but coding accomplishes this quickly and accurately. With enough practice, you might even start thinking in logical terms like “if <i>x</i> occurs, then I will do <i>y</i>,” revealing how coding can clarify our thought processes.
A significant part of coding education involves learning to debug your code. This process can lead to those 'eureka!' moments where you discover more efficient methods. Debugging often proves to be a more effective learning strategy than simply asking for help. Furthermore, reviewing someone else's code can be confusing, as it reflects their unique thought processes. For code to be comprehensible to others, it should include comments explaining its functionality. While comments aid in learning, grasping the overall purpose of the code still requires time and effort.
Many individuals have taught themselves to code, discovering their own preferred methods, whether through handbooks, online courses, or short daily YouTube tutorials. A common theme among self-taught programmers is a clear motivation stemming from a specific problem or goal.
Motivation Through Practical Applications
Robotic arms are capable of performing a variety of tasks, but programming them to move chess pieces demands significant effort. With multiple joints, you must establish rules for movement and develop methods for identifying and picking up pieces rapidly to minimize your opponent's planning time. Collaborating within a diverse team enhances problem-solving, as physicists may propose one solution while electrical engineers might offer another. This teamwork fosters an environment where ideas can be exchanged and optimized, ultimately improving the code.
In chemical engineering, experiments often occur on test rigs to evaluate various operating conditions. When testing every condition is impractical, predictions must be made based on existing data, making equation fitting essential. One experiment may involve numerous variables, all interacting dynamically, resulting in a complex array of partial differential equations to solve simultaneously. Mathematical modeling can provide insights into how these variables influence one another. Understanding the physical constraints of your reaction is critical to building an effective model, such as establishing limits on fluid temperatures or pressure within a reaction vessel.
While a foundation in physics is beneficial, coding can extend your understanding further. A straightforward example is the physics of a pendulum, commonly taught in schools. In educational settings, we usually solve equations for small angles, where the time taken for swings depends solely on the pendulum's length. However, for larger angles, the swing period gradually increases, complicating the equation's resolution—something that is much easier to tackle through coding than with pen and paper.
Additionally, coding allows insights into scenarios that are impractical to replicate in a laboratory. In nuclear physics, statistical methods can estimate the shielding or moderation needed for a nuclear reactor. Textbooks provide numerous tables of materials' neutron absorption probabilities, enabling the setup of virtual experiments, known as Monte Carlo simulations. These simulations replicate actions thousands of times, utilizing probabilities to approximate real-life outcomes. Monte Carlo simulations also find application in computational chemistry, predicting interactions between molecules. My own simulations identified the most likely carbon dioxide binding sites within a polymer membrane, aiding in the design of efficient carbon capture devices—insights not readily observable in reality.
Advantages of Coding Skills
Beyond enhancing scientific understanding, coding offers practical advantages. Combining physical experiments with insights from coding can enhance your employability or facilitate career advancements. Additionally, coding fosters confidence in your scientific comprehension; successfully coding to resolve a problem showcases a solid grasp of the underlying science. Furthermore, coding simplifies daunting tasks, such as filtering extensive datasets or cataloging bond angles in molecular simulations.
For many, the motivation to learn coding stemmed from the desire to address a specific challenge. In these instances, individual progress is not easily compared, as coding encompasses a vast range of capabilities, and each learner often masters only a fraction of them. Confidence in your abilities grows as long as you understand how coding applies to your work. Interestingly, even a small amount of coding experience can bolster your self-assurance. Reviewing someone else's code can be perplexing—even seasoned programmers may struggle to comprehend it fully. Different problem-solving approaches and individual coding styles can lead to confusion, even among those using the same programming language. However, after spending time writing and debugging your own code, you will develop familiarity that instills genuine confidence. The code you create to solve your unique problems becomes a personal testament to your skills.
About This Story
This narrative is inspired by discussions from the podcast episode titled "How easy is it to learn to code?" Technically Speaking (a science and engineering dialogue) aims to recreate the intriguing conversations scientists and engineers often have in the lab, blending scientific facts with imaginative speculation and occasional pop culture references. New episodes are released bi-weekly on platforms such as Apple, Spotify, Amazon Music, Google, Podbean, or wherever you prefer to listen to podcasts.
Stay connected with the podcast on Twitter to continue the conversation.
If you wish to support this blog and podcast, consider becoming a Medium member. Membership is priced at $5 (USD) per month, and signing up through my link allows me to earn a small commission to fund the podcast. Medium membership grants unlimited access to all articles on the platform, and your support is greatly appreciated!