Counting Lines of Code (LOC)


#1

Sometimes people refers the number of Lines of Code (LOC) when comparing the size of an app.

There are several ways of counting how many lines of code you have in your app.
Which method of counting LOC makes most sense?

  1. Sum of line count in every .elm file YOU wrote (excl. installed packages)

    find src/ -type f -name '*.elm' | xargs cat | wc -l
    
  2. Sum of line count in every .elm file (incl. installed packages)

    find . -type f -name '*.elm' | xargs cat | wc -l
    
  3. Count lines of code in the compiled javascript file

    wc -l main.js
    

These three methods gives me very different results on one of my apps:

  1. ~65k lines (excl. packages)
  2. ~195k lines (incl. packages)
  3. ~118k lines (compiled javascript)

Factors that affects LOC:

  • Counting .elm files counts comments and docs aswell.
  • Your coding style can make a big difference when counting LOC in Elm files. I was writing quite compact code before I started using elm-format. LOC was probably increased with a factor of two.
  • Including LOC count from installed packages will also count files not imported in your app.

Questions:

  • Is the LOC count from the compiled javascript file a more objective way of comparing?
  • At least the above factors would be eliminated when counting the compiled js file, right?
  • Is there any other way of counting that makes more sense?

#2

The metric I believe matters most is the size when minified and gzipped.


#3

What is the reason you want to count the lines of code? Depending on the reason, you might use completely different methods.

(Also, maybe we have a case of the http://xyproblem.info/ here)


#4

Counting lines of code is imo one of the aproximate measures of application complexity. It doesn’t make sense to include libraries or measure compiled code because it’s about what programmer maintains not about what is ran by computer. Of course everyone knows this is always rough measurment at that there is big difference between types of code and complexity of the problem and domain. Anyway as an aproximation is helpful as it is very cheap and simple to measure.

when it comes to how to measure LOC I’m personaly using exclusively CLOC https://github.com/AlDanial/cloc. Another solution is to use git and add all additions and substract all deletations in project history. Advantage of git is that you (should) have all deps and caches excluded for free but otherwise cloc is imo botter.


#5

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.