DEV Community

Cover image for The Relevance of Computational Thinking in Programming
Koobimdi Ndekwu
Koobimdi Ndekwu

Posted on

The Relevance of Computational Thinking in Programming

"Why don't programmers like nature? It has too many bugs!"

Let me start by saying that Programming, in its very essence, is actually the art of solving problems. But as anyone who has dabbled into coding knows, the problems we face in software development aren’t just about writing code. Most times, they’re actually about thinking. It can be fairly said that, in programming, if you can get the logic and flow right, then you have solved half the problem. This is where computational thinking (CT) steps in! This is a way of thinking that’s as fundamental to programming as a hammer is to a carpenter. But what exactly is computational thinking, and why is it so crucial in programming? Let me try to break it down with some metaphors, case studies, and practical examples.

What is Computational Thinking?
Think of computational thinking as the blueprint to a house you’re about to build. Before you start hammering nails or laying bricks (writing code), you need a clear plan – an architectural design that outlines what you’re going to build, how it will function, and how everything will fit together. Computational thinking is the mental process that helps you design that blueprint.
It involves breaking down complex problems into smaller, manageable pieces, identifying patterns, abstracting details to focus on the essentials, and developing step-by-step solutions. In other words, it's the process of "thinking like a computer" to solve problems in a logical and efficient way.

Painting a Clearer Picture using Metaphors and Case Studies
1. Decomposition (Breaking Down the Problem): Imagine you’re organizing a huge dinner party. You wouldn’t tackle everything at once. Instead, you’d rather break down the tasks – inviting guests, planning the menu, cooking the food, setting the table, etc. In programming, decomposition is the process of breaking down a large, complex problem into smaller, more manageable tasks.

Case Study: Suppose you’re developing an e-commerce website. Instead of trying to build the entire site at once, you break it down into smaller parts: user authentication, product listing, shopping cart, payment processing, etc. Each part is a smaller problem that’s easier to solve.

2. Pattern Recognition (Finding Similarities): Let’s say you’re baking cookies, cakes, and pies. While each recipe is different, they all share common steps – mixing ingredients, baking in the oven, etc. In programming, pattern recognition is about identifying similarities or patterns in problems that can help you apply the same solution to different situations.

Case Study: When writing code, you might notice that many functions in your program share a common pattern. For example, when processing user inputs, you might always validate the input, check for errors, and then execute some logic. Recognizing this pattern allows you to create a reusable function that handles input processing for multiple parts of your program.

3. Abstraction (Focusing on What’s Important): Think of abstraction as packing for a trip. You can’t take everything, so you focus on what’s necessary – clothes, toiletries, maybe a book or two. In programming, abstraction is about focusing on the essential details and ignoring the irrelevant ones, making the problem easier to manage.

Case Study: When developing a game, you don’t need to simulate every blade of grass in a field; instead, you focus on the broader elements like character movement, scoring, and levels. Abstraction allows you to simplify the problem by ignoring unnecessary details, making the development process more efficient.

4. Algorithm Design (Creating a Step-by-Step Solution): Imagine you’re giving someone directions to your house. You wouldn’t just say, “Find my house!” Instead, you’d most likely provide a step-by-step guide which will be something like “turn left at the filling station, go straight for 100 meters, and so on. In programming, algorithm design is about creating a clear, step-by-step solution to a problem. Just like Mike Ross said in Suits, “The law is a specific endeavour.” In a strict sense, the same can be said of computer programming.

Case Study: Let’s say you’re developing a search feature for a website. You might design an algorithm that searches through a database of items and returns results based on user input. The algorithm might involve steps like checking each item, comparing it to the search term, and then displaying the matching results.

Practical Use-Case Example Scenarios
Scenario – Automated Email Sorting: Lets assume you’re writing a program to automatically sort incoming emails into different folders based on keywords. You’d start with decomposition, where you’d break down the task into scanning the subject line, identifying keywords, and moving the email to the appropriate folder. You’d use pattern recognition to identify similar keywords across different emails, abstraction to focus on the key details (subject line and keywords), and algorithm design to create a step-by-step process for sorting.

Scenario 2 – Building a Weather App: If you’re developing a weather app, you might decompose the project into fetching data from an API, processing the data, and displaying it to the user. Pattern recognition helps you identify common tasks like data fetching that can be reused. Abstraction allows you to focus on the essential data (temperature, humidity, etc.), and algorithm design helps you create a process for updating the app with new weather information.

Key Points to Take Note Of
• CT is Fundamental: Computational thinking isn’t just for programmers, it’s a problem-solving skill applicable across various fields.
• Decompose Complex Problems: Break down large problems into smaller, more manageable tasks.
• Recognize Patterns: Identify similarities across different problems to apply common solutions.
• Focus on Essentials: Use abstraction to manage complexity by focusing on what’s important.
• Design Clear Algorithms: Develop step-by-step solutions to problems.

Conclusion
Computational thinking is the backbone of effective programming. It’s the difference between hacking together code that might work and designing a solution that’s robust, efficient, and scalable. By mastering computational thinking, you equip yourself with the skills to tackle any programming challenge with confidence and clarity.

"Remember, in programming, it's not just about thinking outside the box . . . sometimes, it's actually about thinking inside a well-structured function!"

Top comments (0)