Created
July 23, 2012 04:19
-
-
Save andrewvc/3161953 to your computer and use it in GitHub Desktop.
Counting SLOC in clojure is pretty easy since the syntax is so simple.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Count SLOC | |
export SLF=`mktemp -t cljsloc`; find src test -name "*.clj" | xargs egrep -v "(^[[:space:]]*$|^[[:space:]]*;)" | cut -d: -f1 > $SLF && echo "Files"; uniq -c $SLF; echo "Total" `cat $SLF | wc -l`; rm $SLF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello. This is elegant and quite an eye opener on the power of the Unix shell, and certainly should work for all languages that introduce every comment line with a special character, like Python with #.
Unfortunately in the case of Clojure this snippet also counts docstrings as code lines, and their amount is usually significant, as is their importance in code documentation quality. For instance, in Clojure's own source tree, over 2700 lines of docstring are more numerous than the 2470 blank lines that this expression filters out, and much more so than the 913 comment lines.
If a sloc measurement is actually needed to give an idea of code/comment ratio, I may suggest something more accurate though less gracious, and given that the lines have already been written, it shouldn't be a problem that there are many of them : https://github.com/mdolidon/clj-sloc
Regards.