2

You see pretty often here people saying that they have a x million of lines of code project. How is this measured? Is this number, the number shown under 'Information' menu? The manual says that only the compilable lines are counted (so, without comments and empty lines):

Source compiled -> Displays total number of lines compiled.

But the manual doesn't explain how a piece of code as if/then/else is counted:

if B=true
then 
   for i:= 0 to 100 
    do Stuff
else ;
  1. Is every line that has a blue dot is a "compiled line"?
  2. The Embarcadero code (the RTL and VCL code) and 3rd party libraries are also included into the count?
  3. (The conclusion) What does it mean when somebody says about a Delphi program that it has 1 million lines?
Gabriel
  • 20,797
  • 27
  • 159
  • 293
  • Looks like Embarcadero code is not counted. This is gooood. – Gabriel May 18 '14 at 13:49
  • It is trivially easy for you to work this out for yourself – David Heffernan May 18 '14 at 20:58
  • I don't think I've *ever* seen someone on Stack Overflow talk about how many millions of lines of code they have. Where have you been reading? If you're unclear what someone meant, why didn't you directly ask that person to clarify? And where does the manual say that only compilable lines are counted? (And what makes you think comments and blank lines aren't compilable, anyway? The compiler obviously accepts them.) – Rob Kennedy May 19 '14 at 18:33
  • @RobKennedy-Hi Rob. You can actually see the "I have x million lines of code program" quite often here on stack overflow. Here is an example by Mason Wheeler: http://stackoverflow.com/questions/2188479/why-does-line-count-change-so-much-from-d2007-to-d2010 – Gabriel May 21 '14 at 07:51
  • Here is another example: http://stackoverflow.com/questions/2644973/getting-around-circular-references-in-delphi/2645817#comment36461555_2645817 – Gabriel May 21 '14 at 08:00
  • "And what makes you think comments and blank lines aren't compilable, anyway?" - If the compiler compiles blank lines, what kind of ASM code does it generate for them? :) – Gabriel May 21 '14 at 08:08

1 Answers1

4

The Total lines the compiler tells you is counting the number of lines in the unit(s), regardless of what code is (or isn't) there. It even counts blank lines. Start a new project. Compile it and note the number of lines it says (mine says 42). Then, add just one line break somewhere, and compile again. It will claim there is one more line of code (43). So it does not seem the compiler takes any code into consideration for this number - only the actual line breaks.

In fact, if you add the total number of lines in the main form's unit (new project) as well as the project's main file, it will total to 2 less than what the compiler tells you (40 out of 42). So I wouldn't trust this number to mean much other than a rough estimate.

Libraries such as VCL, RTL, and Indy are not included in this count because those are pre-compiled. It is possible that your project might refer to a library or external unit which needs to be compiled, thus it will also include those into the count.

As far as your mention of how it counts if..then..else blocks, keep in mind that your 5 lines of code can be combined into just 1 line of code (stripping line breaks) and it will still compile, and the compiler will count only 1 line, not 5 lines.

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327
  • 1
    It depends on whether the source of those libraries needs to be compiled or not. VCL and RTL are certainly not counted, because they're already compiled. – Jerry Dodge May 18 '14 at 14:22
  • Interesting find. There seems to be 2 lines coming up from somewhere else however, the smaller I can make is `program Project1; begin end.` which counts as 3 lines. The smallest blank new VCL forms application is 6 lines, because there's an additional unit. – Sertac Akyuz May 18 '14 at 14:42
  • 3
    I wonder how one could be able to come up with such incredibly useless idea of counting loc. And put it in a product which is sold around the world. – Sertac Akyuz May 18 '14 at 14:46
  • 1
    .. in which case I'll note [this question](http://stackoverflow.com/questions/1421058/loc-lines-of-code-metrics-for-delphi). There might be some alternatives there with some intellect. – Sertac Akyuz May 18 '14 at 14:49
  • 1
    Moral of the story: you can't always trust information, even if it's given to you by a very credible source. – Jerry Dodge May 18 '14 at 14:51
  • @SertacAkyuz, the only metric which makes some sense is decimal order of magnitude. Exact count is completely useless for anything besides code golf. – Free Consulting May 18 '14 at 15:08
  • @JerryDodge, no, `DFM` is binary resource stored in the text format for your convenience, `*PROJ` is Microsoft replacement for `makefile` (or `build.xml` if you wish). – Free Consulting May 18 '14 at 15:21
  • Anyway, LoC number is not about "weight", it is about **approximate** program code complexity, eg: if `INT(log10(SLOC(Program1))) > INT(log10(SLOC(Program2)))` then you can say with certain confidence what amongst two **similar** programs, `Program1` is more complex than `Program2`. That's all. – Free Consulting May 18 '14 at 15:31
  • 1
    @JerryDodge, because you were totally wrong with those ideas, yet were trying to argue. Nothing is unrelated here because the question itself is incredibly unspecific. – Free Consulting May 18 '14 at 15:40
  • 2
    @FreeConsulting I already confirmed that you were right and I was wrong, yet you continued to comment about it. Anyway I'm deleting all my comments in this conversation, no need to keep going on and on. – Jerry Dodge May 18 '14 at 15:42
  • So when somebody says that his Delphi program is 1 million lines, it literary means nothing else than 'My program compiles'? – Gabriel May 19 '14 at 14:57
  • @Altar Essentially it's probably actually something like 700k lines, but imagine if the developer has a habit of putting something like 10 line breaks in-between every function and winds up with more line breaks than actual code... – Jerry Dodge May 19 '14 at 15:17
  • But how do you know if the program is actually 10K and the rest are 3rd party libraries? Jedi is pretty big :) – Gabriel May 19 '14 at 15:20
  • @Altar It all depends on how the library was designed and installed, usually large libraries like that are pre-compiled and don't need to be compiled again, but it is still possible that a library can be designed where it's compiled along with the app. One example I can think of is `SuperObject` which is a JSON unit, and needs to be compiled with the app. – Jerry Dodge May 19 '14 at 15:21