The Art of Clean Code – Complexity : Chris

The Art of Clean Code – Complexity
by: Chris
blow post content copied from  Be on the Right Side of Change
click here to view original post

5/5 - (1 vote)

When it comes to productivity, complexity is the bane of your existence. This isn’t just for businesses but individuals as well. Today, let’s dissect where complexity pops up and how it can mess with your ability to get things done.

Think about these hurdles a new coder faces:

  • Picking out a programming language.
  • Selecting a coding project from a sea of open-source initiatives.
  • Choosing between libraries like Scikit-learn, NumPy, or TensorFlow.
  • Deciding which emerging tech to dive into: be it Alexa apps, mobile apps, GPTs, web apps, you name it.
  • Finding the right code editor from options such as PyCharm, IDLE, and Atom.

This overwhelming array of choices often leaves beginners asking, “How do I start?”

💡 Here’s a tip: Don’t start by picking up a coding book and trying to absorb every last syntactical detail. Contrary to popular belief, buying that book and adding it to an endless to-do list often leads nowhere. Instead, pick a practical code project and see it through. Keep your focus tight and hands-on.

Imagine this: A student of mine yearned to build a finance dashboard to gauge historic asset returns.

Although the project seemed daunting at first, she discovered Python Dash, a framework for crafting data-based web apps. By rolling up her sleeves and tackling the HTML and CSS that she needed, she ended up with a live app that has helped thousands—not to mention joining the developers behind Python Dash and now penning a book on her experience:

If you’re interested in learning more about how to create beautiful dashboard applications in Python, check out our new book Python Dash.

You’ve seen dashboards before; think election result visualizations you can update in real-time, or population maps you can filter by demographic.

With the Python Dash library, you’ll create analytic dashboards that present data in effective, usable, elegant ways in just a few lines of code.

Get the book on NoStarch or Amazon!

The beauty is in the beginner’s journey.

While working towards the finish line, you inadvertently answer vital questions about the tools and techniques you need. This exploratory process is where you develop the skills that later become your programming muscle memory.

🧑‍💻 Always remember: complexity is a constant companion throughout a project’s life cycle, but its weight can be lifted through simplicity.

What Exactly Is Complexity?

Complexity isn’t a one-size-fits-all term. At times it’s about a coded function’s computational demands; other times, it’s about a system’s knotty interactions. For us, it’s something broader and a tad more sinister:

Complexity is a whole system with parts that defy easy explanation.

From social networks to hefty software like Windows, complexity is lurking, ready to bog down coders with challenges ranging from project management woes to understanding algorithmic theories.

The Life Cycle of Complexity

The project life cycle is riddled with complex stages: from planning out your product’s vision to finally deploying it to users. At planning, defining requirements, designing the blueprint, building the code, testing to iron out kinks, and deploying—each step has its complexities.

Missteps in planning can lead to resource wastage.

Poor communication in the defining phase can spiral into major roadblocks down the line. Design challenges, building bugs, testing traps, and deployment dilemmas—complexity weaves into every facet like a crafty villain in a thriller novel.

Inside the Machine: Algorithmic Intricacy

Turn to software itself, and you’ll find that it has its complexity quotient.

Consider algorithms—they can be as varied as the problems they solve. Take the classic task of sorting for example: some algorithms scale well as data grows, while others choke up and slow down.

If your software needs speed, you’ll need the most efficient algorithm out there.

⚛ Algorithmic complexity focuses on the resource demands of different algorithms, allowing for comparisons between them, especially in tasks like sorting lists in applications.

For instance, in a game app with a high-score system, sorting algorithms become crucial as the number of players increases.

While the choice of algorithm is less critical for a small user base, it becomes increasingly important as the user number grows, affecting the app’s performance. This is because some algorithms are more efficient and scale better with larger lists.

If an inefficient algorithm is used, the app slows down significantly as more users join, leading to longer wait times and user complaints.

An example comparing two algorithms illustrates this: Algorithm 1 is slower than Algorithm 2, and its inefficiency is more pronounced as the list size increases, highlighting the importance of choosing the right algorithm for scalability. 👇

Now check out what happens when applying this concept of reducing complexity in real Python code using three popular sorting algorithms:

“Bubble sort has the highest algorithmic complexity (Figure 1-3). Quicksort and Timsort have the same asymptotical algorithmic complexity. But the Timsort algorithm is still much faster—that’s why it’s used as Python’s default sorting routine. The runtime of the bubble sort algorithm explodes with a growing list size.

In Figure 1-4, we repeat this experiment but only for Quicksort and Timsort. Again, there’s a drastic difference in algorithmic complexity: Timsort scales better and is faster for the growing list size. Now you see why Python’s built-in sorting algorithm hasn’t changed for such a long time!”
The Art of Clean Code

💡 TL;DR: Reduce complexity at all costs for maximum benefit in every area of your life!

Don’t forget about cyclomatic complexity—the number of paths through your code—it’s another metric that matters. The higher it is, the more convoluted your code might be. It’s a fine balance to strike: robust software with simplified readability.

We want to reduce cyclomatic complexity, too. You get the idea! 🙅

👉 Keep It Simple, Stupid! Minimalism in Programming: How Complexity Harms Your Productivity

Learning Curve Complexity

Learning isn’t just about soaking up facts—it’s about understanding their interplay. Just as Google’s Knowledge Graph connects billions of facts, every sphere of knowledge is a tight web of interconnections. The moment you try to learn more, the more complexity you face, and it hits you: the never-ending learning curve that makes you want to jump ship.

Complexity of Processes

In business, processes dictate efficiency. Complex processes, with their many branches and participants, can bog down innovation and raise risks. Streamlined processes can work wonders, just like Uber did by reducing the complexity of catching a ride.

The Personal Side of Complexity

Your productivity can also take a hit from your personal life and daily routines. With today’s constant distractions, deep work—like programming and researching—becomes a rare commodity. It is challenging to stay focused, but to combat complexity, simplicity and minimalism must become your new best friends.

There’s a growing need for deep, focused work in fields like programming, amidst an increasing scarcity of undisturbed time due to modern communication and entertainment technologies. The ability to perform deep work, which is becoming rarer, can significantly increase your economic value in today’s market.

👉 How to Go From $0 to $100k Net Worth in 1 Year or Less (in Tech)

However, engaging in deep work requires strict prioritization due to constant external distractions, such as office interruptions, smartphones, and frequent emails.

These distractions often lead to a preference for instant gratification over the delayed satisfaction that comes from completing long-term projects like computer programming. This tendency undermines deep work, as the allure of immediate rewards from activities like checking messages or watching Netflix often outweighs the benefits of prolonged, focused effort.

To counteract these challenges, adopt a radical minimalist approach.

This involves making substantial changes like uninstalling social media apps instead of trying to limit their use, focusing on fewer tasks and projects, and deeply learning one programming language rather than superficially learning many.

Such strategies can help maintain focus and productivity, avoiding the gradual erosion of your ability to engage in deep, meaningful work.

Eight Ways to Control Complexity – A Brief Overview

I’ll dive into all eight ways to reduce complexity and increase your productivity in subsequent articles on the Finxter blog and the Finxter email newsletter (100% free). Here they are as a quick overview:

  1. Declutter: Simplify your daily tasks and concentrate on the most impactful ones. (Refer to Chapter 2 in The Art of Clean Code for the 80/20 principle in programming)
  2. Embrace MVP: Focus on creating a Minimum Viable Product by stripping away unnecessary features. (Details in Chapter 3)
  3. Simple Code: Aim for straightforward and brief code. (Chapter 4 offers practical tips)
  4. Avoid Premature Optimization: Don’t waste time optimizing code unnecessarily—it adds complexity. (Learn more in Chapter 5)
  5. Block Your Time: Dedicate large time blocks for uninterrupted programming to achieve a state of flow. (Explore this in Chapter 6)
  6. Unix Philosophy: Assign a singular focus for code functions—“Do One Thing Well.” (Chapter 7 dives into this philosophy with Python examples)
  7. Simplicity in Design: Create user interfaces that are clean, intuitive, and easy to use. (For design simplicity, see Chapter 8)
  8. Focus Techniques: Apply techniques to maintain focus whether planning your career, project, or daily activities. (Expand on this concept in Chapter 9)

In Simplicity We Trust

By now, you’re hopefully convinced that controlling complexity isn’t just about being productive; it’s about gaining a significant edge.

Next up, we’ll dive into the 80/20 principle, where you’ll learn the art of focusing only on what truly matters — it’s the best tool to control complexity. Welcome to the simplicity revolution.

👉 Stay tuned for the simplicity saga!

I’ll replace this sentence with a reference to the next lesson of my The Art of Clean Code series tomorrow.

January 09, 2024 at 08:46PM
Click here for more details...

The original post is available in Be on the Right Side of Change by Chris
this post has been published as it is through automation. Automation script brings all the top bloggers post under a single umbrella.
The purpose of this blog, Follow the top Salesforce bloggers and collect all blogs in a single place through automation.