How 100 Lines of Code is Better than 5 Lines of Code

Niket PatadiyaNiket Patadiya
3 min read

We often hear the phrase “less code is better code.” While that sounds elegant, it's not always true—especially when you're building something that needs to scale. In fact, there are many cases where writing 100 lines of code can be far better than just 2. Sounds strange? Let me explain using a very simple, everyday analogy: filling a water tank.

This analogy will help us understand an important computer science concept called time complexity.


💡 What Is Time Complexity?

Time complexity tells us how the performance of an algorithm changes as the size of the input grows. It’s not about how long a program takes on your laptop right now, but how it will perform when the data grows—like going from 10 users to 10,000 or 10 million.

In simple terms: it helps us predict how fast (or slow) our code will run as the workload increases.


💧 The Water Tank Example

Let’s say your job is to fill a large water tank with 1000 liters of water. You have two choices for how to do it:

Option 1: Use a Mug (Simple, Short Code)

You grab a small mug that holds exactly 1 liter and start pouring.

You walk to the tap, fill the mug, pour it into the tank, and repeat this 1000 times.

You could write this as just 2 lines of code:

for i in range(1000):
    tank.fill(1)

Sounds efficient, right? But in reality, this takes a lot of time. Imagine how many steps you need, how much energy it consumes, and how slow it becomes when repeated millions of times.


Option 2: Use a Motorized Pump (Longer, Smarter Code)

Now imagine you set up a motorized pump that can transfer 100 liters at a time. It takes some effort to configure the pipe, connect the power supply, and manage the flow.

Your code might span 100 lines because you’re dealing with more setup and control logic:

# Pseudocode for better setup
initialize_pump()
while tank.not_full():
    pump.transfer(100)
    monitor_flow()

Even though it’s more work up front, the job gets done in just 10 iterations, not 1000. It’s faster, more efficient, and scalable.


🧠 What Does This Mean for Code?

Let’s compare:

MethodLines of CodeSteps NeededTime Taken
Mug (simple)21000Very Slow
Pump (efficient)10010Much Faster

In programming terms:

  • The mug approach is like having an algorithm with O(n) time complexity — performance gets worse as input grows.

  • The pump approach represents O(1) or O(log n) — it scales well, even with large inputs.

So, while the mug method is easier to write, it’s not suitable for real-world scenarios where speed matters.


🚀 Real-World Application

In software development, you’ll often have to choose between writing quick-and-dirty code that "just works" and spending more time creating a robust solution. A few extra lines of thoughtful code can mean the difference between a fast app and a slow one, especially when dealing with large data or high user traffic.

Short code isn’t always better — sometimes it’s just lazy. 😄


✅ Final Takeaway

Writing more lines of code doesn’t mean you’re doing something wrong. In fact, it often means you're thinking about performance, scalability, and future growth. As we saw with the water tank, a more complex solution is often the smarter one.

So, the next time you're proud of a 2-line hack, ask yourself:
“Is this going to hold up when the tank gets bigger?”

0
Subscribe to my newsletter

Read articles from Niket Patadiya directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Niket Patadiya
Niket Patadiya