Code Carnival: Total Cost of Owning a Mess.

Tayyba Adien - Android Avenger
4 min readDec 28, 2023

--

Embark on the Code Carnival journey, where the dance between chaos and deadlines unfolds.

All developers with more than a few years of experience know that previous messes slow them down. And yet all developers feel the pressure to make messes to meet deadlines. In short, they don’t take the time to go fast!

True professionals know that the second part of the conundrum is wrong. You will not make the deadline by making the mess. Indeed, the mess will slow you down instantly and will force you to miss the deadline. The only way to make the deadline — the only way to go fast — is to keep the code as clean as possible at all times.

But true professionals know the secret — messes won’t meet deadlines.

If you’ve been coding for a few years, chances are you’ve grappled with the headache-inducing challenge of messy code. It’s like stepping into a Tangled web where every attempt to move forward slows you down, and what once felt like a fast-paced project now inches along at a snail’s pace.

In the coding world, this messiness isn’t just a minor inconvenience; it’s a game-changer. Imagine every change you make to the code breaking two or three other parts. It’s a constant battle where even the smallest tweak demands unraveling a web of tangles, twists, and knots. And guess what? Over time, this mess becomes so massive and tangled that cleaning it up feels impossible.

As the mess grows, the productivity of the team starts plummeting. It’s a steep decline, and the more it drops, the more desperate management becomes. Their solution? Bring in more people to the project. Sounds logical, right? But here’s the catch: these recruits don’t get the design of the system. They don’t know the difference between a change that fits the design and one that messes it up. So, instead of saving the day, they unknowingly add to the chaos, dragging productivity even further down.

but wait do you know Why it happens? 🤔

Unraveling the Web of Messy Code: Understanding the Culprits.

In the world of coding, the struggle against messy code is real. Let’s deep down at why it happens and explore the common pitfalls that lead us into tangled logic and confusing structures.

Repetitive Variables:

Creating separate variables for similar tasks can clutter your code. Having variables like x1, x2, x3, and x4 when one variable could suffice.

Redundant Functions || Encapsulating Multiple logics in a Single Function :

Assigning multiple responsibilities to a function can lead to confusion. Picture this: initializing an object, assigning its values, and then performing operations on it — all within the same function.This conflation of concerns not only blurs the function’s purpose but also introduces a level of complexity that can hinder code readability and maintenance. It’s essential to adhere to the principle of single responsibility, ensuring each function has a clear and distinct purpose in the codebase. Functions like getData() and process() lack clear purposes.

Task Steps Without Classes:

Avoiding the creation of classes for sequential tasks may result in repetitive code. Create a utility class that uses extension functions within it for versatility across different contexts, like various Activities. Repeatedly using code in an activity instead of encapsulating it into a class.

UI-Backend Mixing:

Merging UI code with backend logic can blur the lines between concerns. I have seen in product-based apps that UI logic is too tangled in backend logic in a single activity. Performing backend logic directly within an Android Activity or Fragment.

No Singleton Objects:

Neglecting the use of singleton objects for dependency injection can lead to messy code. It's something like passing reference rather than passing and creating a value in a memory location. Failing to create a singleton for a globally used component.

Excessive use of Preferences variables:

Creating too many SharedPreferences variables can clutter the codebase. Unnecessary proliferation of SharedPreferences for different settings.

Forgotten Test Code Snippets :

Forgetting to remove test logs after completing a module can leave the clutter behind. Writing code snippets for testing purposes and omitting their removal post-module completion.

Incorrect Logging Tags:

Tagging logs improperly can lead to confusion during debugging.

Log.d("jdhfhhudfh", "Your debug message here")

Using inconsistent or inaccurate tags in log statements.

Unnecessary Dependencies:

Including dependencies that aren’t essential for the project can bloat the code. More dependencies mean more dex classes that will increase app size and ultimately your app gets heavier. Incorporating libraries that aren’t crucial to the application’s functionality.

Disorganized File Structure:

A lack of an organized folder and file structure can make code hard to navigate. Scattered and unstructured code files within a project.

Module Embedding from GitHub:

Embedding entire files for a single feature may lead to code duplication.
Copy-pasting entire code files from external sources for a specific functionality.

Remember that writing code is a skill that improves with practice. Don’t be afraid to experiment with different styles and approaches to find what works best.

An Interesting blend of my experience with the knowledge gained .

From Clean Code a book for Robert C. Martin

--

--

Tayyba Adien - Android Avenger
Tayyba Adien - Android Avenger

Written by Tayyba Adien - Android Avenger

👋 Hi! I'm Tayyba, an Android dev skilled in Flutter, Kotlin, Jetpack Compose, XML & Java. I've rocked 20+ projects, learning from users & real-world hurdles.

No responses yet