#011 - Python Essentials | 00 - Programming Fundamentals
Tailored insights for Civil and Structural Engineers on key concepts in modern computer programming.
Welcome to the first post of our Python Essentials Series for Civil and Structural Engineers. In this post, we review some fundamental concepts of computer programming, with Python as our focal point. Our mission is simple: to lay a strong foundation in the core concepts of computer programming.
This post is not about Python syntax or coding; instead, it's about understanding the ethos of programming and why Python has emerged as one of the world’s most popular programming languages. If you’re an engineer and want to understand this branch of computer science, this series is your first step.
Let us begin.
The Essence of Computer Programming
1. Definition and Scope of Computer Programming:
Computer programming is the art of instructing a computer to perform tasks. This is achieved through writing code, a set of commands that the computer understands and executes. Over the years, programming has evolved from a niche skill into a fundamental tool that powers our digital world. From smartphone apps to complex scientific simulations, programming is the invisible force driving innovation and efficiency around our planet and beyond. This is obvious, but we need to start somewhere.
2. Evolution of Programming:
The history of programming is a tale of constant evolution, beginning in the 1940s with rudimentary binary code, a language of ones and zeros that directly communicated with the hardware. This evolved into assembly language in the early 1950s, offering a slightly more human-readable form. The real breakthrough, however, came in the mid-1950s with the advent of high-level languages like FORTRAN and COBOL, which allowed programmers to write code using words and phrases closer to human language.
Sidenote: At my first job, I met a colleague who used FORTRAN for analyzing large towers. Even though it was way over my head, it looked tremendously painful to read and write. The unbridled excitement on that man’s face, while he passionately described the features and logic of FORTRAN, will live on with me in perpetuity. Dave if you’re reading this, I remember.
Since then, the development of numerous programming languages, each with its own strengths and purposes, has continued into the 21st century, catering to diverse needs from web development to artificial intelligence. This evolution has significantly lowered the barrier to entry for aspiring programmers, making programming more accessible and versatile than ever.
3. The Role of Programming Languages:
Programming languages are the bridge between human ideas and machine execution. They enable us to solve complex problems, automate mundane tasks, and create interactive digital experiences. Each language, with its unique syntax and capabilities, offers different ways to approach and solve problems.
The most popular programming languages shown in the image below are used for a variety of purposes.
JavaScript: Primarily used to make websites interactive and to build web applications.
HTML and CSS: Web development essentials for creating and designing websites.
SQL (Structured Query Language): Used for managing and organizing data in databases.
Python: A versatile language for various purposes including web development, data science, and automation.
TypeScript: Enhances JavaScript to build more complex and error-resistant web applications.
Java: Commonly used for building enterprise-level applications, mobile apps (especially Android), and server-side technologies.
Python can be learned with no prior knowledge of any other programming languages. It’s an accessible tool for engineers who just need to get the job done.
Programming in Engineering
Programming in Engineering is not that common in my experience. I’ve met a handful of people over the years who used various programming languages to complete tasks. The reason for this is the limited exposure to practical coding skills in university engineering courses. Some students tell me that’s beginning to change. I get it; civil and structural engineering are absolutely gigantic fields of study with so much core material based on the physical sciences, economics, construction, project management, ethics etc. I’m not sure how they can fit it in. But the reality is that it’s extremely useful. If you’re a student and your university teaches programming to civil/structural students, let me know about it in the comments.
My exposure in university (circa 2007) was 2 weeks of C or C++ where we did some unbelievably mundane and obtuse computer lab assignments. I think we calculated compression/tension loads in a truss. At the time, I thought it was a huge waste of time, and the practicality of programming went completely over my head. It was probably a combination of poor delivery/material and me being a 22-year-old baboon. That’s the old me; the current me gets it. I’m a huge fan.
Key Concepts in Programming
This section provides a concise overview of the fundamental aspects of computer programming rather than delving deeply into any single topic. For engineers interested in exploring any of these concepts in greater detail, there are a myriad of excellent resources available online that extend far beyond the scope of today’s post.
To become proficient in programming, there are several fundamental concepts one must grasp:
Understanding Algorithms: An algorithm is a step-by-step procedure to perform a task. It's a recipe that tells the computer exactly what steps to take to solve a problem. Mastering the art of algorithm design is crucial for efficient and effective programming.
Control Structures: These are the building blocks of programming that control the flow of a program. They include conditional statements (like if-else) that allow the program to make decisions and loops (i.e. like, for and while) that enable repetitive execution of code blocks. Control structures make your programs dynamic and responsive.
Data Structures: These are ways of organizing and storing data so that it can be accessed and modified efficiently. Arrays, lists, stacks, and queues are examples of data structures that help manage and manipulate data in a program. A solid understanding of data structures will allow you to handle complex data manipulation tasks.
Logical Thinking and Problem-Solving: Just like professional engineering, programming is fundamentally about solving problems using logical thinking. It requires breaking down complex problems into smaller, manageable parts and systematically tackling them. This skill is indispensable and gets refined with practice and experience.
All of these concepts are woven into practical engineering examples throughout the Flocode curriculum. For those interested in digging deeper, take a look.
Programming Paradigms
A programming paradigm is a style or way of thinking about and structuring code. These ideas can seem complex and are much easier to understand with real-world examples, which we will explore in the future. There are several paradigms, each offering a different approach to solving problems:
Procedural Programming: Think of procedural programming as a series of steps or instructions that you follow to get a result. It's straightforward and sequential, making it a great starting point for beginners. You should be pretty familiar with this concept if you've ever designed any code-compliant structural element by following a series of prescribed checks and steps.
Object-Oriented Programming (OOP): OOP is about creating 'objects.' Imagine an object as a small box that contains information (data) and tools (procedures) to use that information. It's like having a toolbox for each aspect of a project, where each toolbox has everything needed to handle that aspect. This approach is helpful for managing complex systems because it organizes code into these manageable 'boxes’, providing a modular solution that can be easily added or removed and re-used for other Projects. You could create an object or ‘class’ related to steel beams that would handle all sorts of specific calculations related to steel beams and import it as needed into various projects. All of the functions and attributes related to the steel beams are encapsulated in the class. If this still doesn’t make sense, move on or read this The Power of Python Classes in Structural/Civil Engineering Design.
Functional Programming: In functional programming, you focus on composing functions – these are like small, specialized machines in a factory line, each doing a specific task. This style emphasizes using these functions without changing their internal state, making the code predictable and easier to debug. It's particularly useful in scenarios where many processes happen at the same time or in parallel.
Each of these paradigms should be combined in a way that makes sense for your objectives. The true elegance of programming lies in how you blend and utilize these diverse concepts, creating solutions that are as efficient as they are innovative.
Our approach in the Flocode curriculum is not just to teach these concepts in isolation but to integrate them into real-world examples. This practical application will help you understand these paradigms in the context of Python and also see how they can be effectively used in civil and structural engineering projects.
Understanding is not just about learning different syntax and concepts; it's also about learning to think in fundamentally different ways. This cognitive flexibility is a significant asset whether you are programming or not.
Understanding Python
Python’s story begins in the late 1980s with its creator, Guido van Rossum. What sets Python apart from other programming languages? First and foremost, it's an interpreted language, meaning that Python code is executed line by line, making debugging easier and allowing for a more interactive coding experience. This contrasts with compiled languages, where the entire code is converted into machine code (i.e. binary code specific to a CPU) before execution, which can be less flexible during the development process.
Python’s simplicity doesn't come at the cost of its power. It's a versatile tool that can be used in web development, data science, artificial intelligence, scientific computing, and more. This versatility is due in part to Python's extensive standard library and the vast ecosystem of third-party packages and frameworks.
"Python is an experiment in how much freedom programmers need. Too much freedom and nobody can read another's code; too little and expressiveness is endangered." – Guido van Rossum
Programming purists often point out that Python's high-level nature and reliance on an interpreter can lead to inefficiencies compared to lower-level languages that are closer to the machine, like C or C++. These languages can be more effectively optimized for efficiency, crucial in contexts where performance is paramount.
To address these concerns, innovative projects like Mojo by Modular (which is 100% compatible with Python syntax) are emerging. They aim to bridge this gap, bringing Python closer to machine-level operation and optimizing hardware automatically based on the programming context. This development is particularly significant in fields like machine learning and artificial intelligence, where computational efficiency scales up dramatically with complexity.
For civil and structural engineers integrating programming into their design practices, the intricacies of different programming languages, whether high-level or low-level, are typically not a primary concern. The specific efficiencies these languages offer are often beyond the usual scope of engineering tasks, except in advanced cases like computational fluid dynamics or intensive finite element analysis. Python suffices for about 99% of engineering needs. When encountering bottlenecks or delving into large-scale complex models for machine learning or artificial intelligence, that's when specialized languages like Mojo become relevant and valuable.
Some key features of the Python language are shown below.
Why Python was Initially Developed
Python was born out of a desire to create a language that was both easy to write and understand. Van Rossum wanted a language that combined the user-friendly nature of shell scripting with the powerful features of system programming. Shell scripting refers to writing small programs (scripts) for automating tasks (e.g. automating file organization, extracting data from an Excel file). On the other hand, system programming involves developing software that interacts closely with the underlying operating system, typically requiring more complex and powerful code. By integrating these two aspects, Python emerged as a highly versatile language, equally efficient for both basic scripting tasks and complex application development.
Python is Open-Source
Open-source technology is defined by its freely accessible code, allowing anyone to use, modify, and share it.
This is my favourite aspect of Python. It has fostered a massive, worldwide community where a wealth of knowledge is readily available. This stands in stark contrast to the expensive commercial software that dominates the engineering and construction industry. Python's open-source framework democratizes access to technology, breaking down barriers and broadening possibilities for engineers everywhere and it’s what makes projects like Flocode possible.
Conclusion
As we wrap up this introductory post in our Python Essentials Series, it's important to reflect on the importance of grounding ourselves in the basics of programming. The journey into the world of Python, and computer programming as a whole is no joke. It’s a jungle out there.
Though vast and complex, it is just another branch of the expansive tree of knowledge that encompasses fields like mathematics, science, and engineering. Approaching it with the same methodical step-by-step mindset will make the process more manageable and less daunting.
"In theory, there is no difference between theory and practice. But, in practice, there is." – Jan L. A. van de Snepscheut
The journey of learning Python is not a sprint; it's a marathon. It requires patience, persistence, and a willingness to build your understanding piece by piece. Sometimes, it also requires the ability to scream into a pillow.
As you begin to weave the foundational principles of programming into practical Python projects in our upcoming posts, you'll gradually start to appreciate the language's clarity and simplicity. This appreciation grows over time, developing into a profound understanding of Python's flexibility and elegance. It’s similar to learning any language or skill; initially challenging, but increasingly rewarding as fluency develops.
We will continue to explore Python in our upcoming posts, where we'll turn these foundational concepts into hands-on learning experiences.
Subscribe to ensure you don't miss any steps in this journey. Share your thoughts, questions, and progress with us. Your participation is not just about your own learning; it's about contributing to a community that grows together.
"Education is not the learning of facts, but the training of the mind to think.” - Albert Einstein
Thanks for reading and see you in the next post!
James 🌊