Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why some large projects compile to small assemblies?

Tags:

c#

.net

For instance, the last release of the famous library HtmlAgilityPack source is something like 110 000 lines of C#, and the assembly is 132 KB.

https://www.openhub.net/p/htmlagilitypack

My project is about 6500 lines and compiles to 300 KB assembly.

I haven't looked extensively at the source, but it is clearly not 100K loc usable classes. So what is that enormous amount of code doing?

like image 767
JDE Avatar asked Jun 09 '16 13:06

JDE


1 Answers

In addition to differences such as debug vs release mode, etc., I suspect that comparing your 6,500 lines to the "110,000" lines in their source is misleading.

Lines of code is a quirky metric. If you look at the breakdown by language, you see that there are only about 55 KLOC in C# for all projects (only one of which is the actual Agility Pack assembly), much of which is (I suspect) braces and other "whitespace" that does not directly get represented in the binaries. Also, just browsing through it, it does not use a lot of automatically-implemented properties, which use less lines of code for the same functionality. For example:

internal int _lineposition;

public int LinePosition
{
    get
    {
        return this._lineposition;
    }
    internal set
    {
        this._lineposition = value;
    }
}

versus

public int LinePosition {get; internal set;}

12 lines of code versus 1 for the same amount of compiled code.

All that to say that there are a lot of caveats to using lines of code as a metric for the "size" of a program.

like image 181
D Stanley Avatar answered Nov 13 '22 22:11

D Stanley