Why Writing 100 Lines of Code Can Be Better Than 2 Lines Of CodešŸ’”

Haseeb AhmedHaseeb Ahmed
4 min read

Hello Techiessss!!

When we first start learning to code, we often hear this advice "Keep your code short the shorter, the better!" But is short code always the smartest choice? šŸ¤” Imagine your friend tells you "Take the shortcut, it's faster." But that shortcut lands you in a traffic jam — annoying, right? šŸ˜… The same thing happens in coding. Short code might look cool, but when it comes to understanding, fixing, or updating it later — it can turn into a real headache.

In this blog, we’ll explore why writing more lines can actually make you a better coder. You’ll see how clean, readable, and structured code can save time in the long run. So let’s break the ā€œshorter is betterā€ myth... and start understanding.

Lets go… Let’s break it down in a simple way.

šŸ’” What Does "2 Lines of Code" Mean?

Some people love writing very short code. It looks something like this :

#include <stdio.h>
using namespace std;

int main() {
    copy(istream_iterator<int>(cin), istream_iterator<int>(), ostream_iterator<int>(cout, " "));
}

This program reads numbers from the user and prints them. Just one line inside main(). Wow! Cool, right ?

But wait a second…
Can you actually understand what’s going on here?

No?

Don’t worry — most people can’t, including beginners. Even I would need a moment to read it carefully. šŸ˜…

āœ… Let’s Make It Longer… and Easier to Understand

Here’s a version of the same thing, but this time, we’ll write it in a clear step-by-step way :

#include <iostream>
using namespace std;

int main() {
    int numbers[100];  
    int num;
    int count = 0;     

    cout << "Enter numbers (type -1 to stop): ";

    while (count < 100) {
        cin >> num;

        if (num == -1) {
            break;
        } else {
            numbers[count] = num;
            count = count + 1; 
        }
    }

    cout << "You entered: ";

    int i = 0;
    while (i < count) {
        cout << numbers[i] << " ";
        i = i + 1;
    }

    return 0;
}

🧠 What's the Difference?

  • Easy to understand

  • Shows each step

  • Can be modified easily

  • Better for debugging if something goes wrong

āš ļø The Hidden Costs of Short Code

Short code can be:

  1. Hard to read

  2. Hard to debug

  3. Hard to modify

  4. Hard to test

Sometimes, trying to be clever actually makes your program worse.

🧮 Example :

Finding the Maximum Value in a List

2-Line Version :

#include <iostream.h>
using namespace std;

int main() {
    cout << *max_element(istream_iterator<int>(cin), istream_iterator<int>());
}

Longer Version :

#include <iostream>
using namespace std;

int main() {
    int numbers[100]; 
    int num;
    int count = 0;

    cout << "Enter numbers";

    while (count < 100) {
        cin >> num;

        if (num == -1) {
            break;  
        } else {
            numbers[count] = num;
            count = count + 1;
        }
    }

    if (count > 0) {
        int maxVal = numbers[0];
        int maxIndex = 0;
        int i = 1;

        while (i < count) {
            if (numbers[i] > maxVal) {
                maxVal = numbers[i];
                maxIndex = i;
            }
            i = i + 1;
        }

        cout << "Maximum value is " << maxVal << " at index " << maxIndex << endl;


        cout << "Numbers greater than 10: ";
        int j = 0;
        while (j < count) {
            if (numbers[j] > 10) {
                cout << numbers[j] << " ";
            }
            j = j + 1;
        }
    } else {
        cout << "No numbers were entered." << endl;
    }

    return 0;
}

This code is a bit longer, but :

  • It’s clear

  • You can edit it easily

🧩 Real-World Analogy

Think Like a Teacher, Not a Magician

Imagine you’re teaching your junior how to code. If you give him a two-line program with no explanation, he will be confused. But if you walk him through the logic — step by step — he will learn.

The same applies to your future self and your teammates. Clear code helps everyone.

If you enjoyed this blog, share and comment! šŸ˜‰āœØ Happy coding!

0
Subscribe to my newsletter

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

Written by

Haseeb Ahmed
Haseeb Ahmed