Lower line count is not always better


Home | Blogs

Many people will look at a projects line count. Many people see the line count as being small, so this is better.

Line count can heavily depend on the coding style of a project. These two lines are not the same in line count:

int example() {
    return 42;
}
int example()
{
    return 42;
}

These two lines of code mean the same thing but take up different amounts of space. This might look like a small example, as it only affects one line of code for a whole project, but it can add up quickly. This would also affect any time there is an if, for, or while, adding one more line of code than normal.

This was an example only with one programming language; how about if you try and compare multiple programming languages?

name = input("What is your name? ")
print("Your name is " + name)
#include <stdio.h>

int main() {
    char name[20];
    printf("What is your name? ");
    fgets(name,20,stdin);
    printf("Your name is %s", name);
    return 0;
}

This is a simple example of reading something from stdin and then printing it out. In Python, this ends up being 2 lines of code, and in C, it becomes nine lines of code.

Or is it nine lines of code? We are importing a library called stdio.h. This library has some code that we don't want to write ourselves, but it still has "lines of code" for showing how big a program is.

Importing stdio.h is normal, so I think most people can agree it is not a big deal, but how about importing a library for interacting with an API? The lines of code you might write are few, but there are still hundreds, if not thousands, of lines of code that are still in your program, but you just did not write them.

Ok, fine, let's just compile the C program and get the binary size. That would be amazing, but sadly, dynamically linked libraries exist, where some code won't actually be installed in the binary but will be installed on your device.

Just remember that next time you get excited about a program being minimal, look at some of its dependencies first and not just look at the line count.