{"id":8250,"date":"2019-02-23T18:12:33","date_gmt":"2019-02-23T23:12:33","guid":{"rendered":"http:\/\/esr.ibiblio.org\/?p=8250"},"modified":"2019-02-23T18:12:48","modified_gmt":"2019-02-23T23:12:48","slug":"announcing-loccount-2-0-now-up-to-74-languages","status":"publish","type":"post","link":"http:\/\/esr.ibiblio.org\/?p=8250","title":{"rendered":"Announcing loccount 2.0 &#8211; now up to 74 languages"},"content":{"rendered":"<p>I just released the 2.0 version of <a href=\"http:\/\/www.catb.org\/~esr\/loccount\/\">loccount<\/a>.<\/p>\n<p>This is a major release with many new features and upgrades.  It&#8217;s gone well beyond just being a faster, cleaner, bug-fixed port of David A. Wheeler&#8217;s sloccount. The count of supported languages is now up to 74 from sloccount&#8217;s 30.  But the bigger change is that for 33 of those languages the tool can now deliver a statement count (LLOC = Logical Lines Of Code) as well as opposed to a line count (SLOC = Source Lines of Code, ignoring whitespace and comments)<\/p>\n<p>To go with this, the tool can now perform COCOMO II cost and schedule estimation based on LLOC as well as COCOMO I based on SLOC.  <\/p>\n<p>The manual page includes the following cautions:<\/p>\n<p><!--more--><\/p>\n<blockquote><p>\nSLOC\/LLOC figures should be used with caution.  While they do predict project costs and defect incidence reasonably well, they are not appropriate for use as &#8216;productivity&#8217; measures; good code is often less bulky than bad code.  Comparing SLOC across languages is also dubious, as differing languages can have very different complexity per line.<\/p>\n<p>With these qualifications, SLOC\/LLOC does have some other uses. It is quite effective for tracking changes in complexity and attack surface as a codebase evolves over time.\n<\/p><\/blockquote>\n<p>That&#8217;s how I&#8217;ve used it &#8211; to track the drastic reduction in NTPsec&#8217;s codebase size. It was also my finger exercise in learning Go.  For those of you who enjoy reading code, there are a couple of points of interest&#8230;<\/p>\n<p>One is how much of the program&#8217;s intelligence is in tables rather than executable code.  Adding support for a new language is usually as simple as adding a new table entry and a test load. Some of the internal changes in 2.0 relate to enriching the table format &#8211; for example, two things you can now declare are that a language uses the C preprocessor and that C-style backslash escapes are implemented in its string constants.  I&#8217;ve often advocated this kind of programming by declarative specification in my writings; here you can see it in action.<\/p>\n<p>The contrast with sloccount is extreme; sloccount was clever, but it&#8217;s a messy pile of scripting-language hacks that makes adding a new language &#8211; or, really, changing anything about it at all &#8211; rather difficult. This is probably why it hasn&#8217;t been updated since 2004.<\/p>\n<p>Another point of interest is the way the program uses Go&#8217;s CSP concurrency primitives. It&#8217;s a pattern that could generalize to other ways of data-mining file trees. Walk the tree, spawning a thread to  gather stats on each file; each thread writes a summary to one single rendezvous channel; the main thread reads summary blocks off the rendezvous channel and aggregates them into a report.  There&#8217;s no explicit lock or release anywhere, all the synchronization is supplied by the  channel&#8217;s atomicity guarantees.<\/p>\n<p>That&#8217;s pretty simple, but as a readily accessible demonstration of why CSP rocks compared to conventional mailbox-and-mutex synchronization its very simplicity makes it hard to beat.<\/p>\n<p>Ironically, one of the source languages this tool written in Go cannot deliver LLOC reports for is Go itself. That&#8217;s because Go doesn&#8217;t have an explicit end-of-statement marker; counting statements would in principle require a full parse.  Something might be done with the assumption that the input source in in the canonical form that go fmt produces.<\/p>\n<p>Plans for future releases:<\/p>\n<p>* Beat Go into not barfing on ABC comments?  (We have a test load)<\/p>\n<p>* Tell Objective-C .m from MUMPS .m with a verifier?<\/p>\n<p>* sloccount handles different asm comment conventions.  We should too.<\/p>\n<p>* How to weight EAF: https:\/\/dwheeler.com\/sloccount\/sloccount.html#cocomo<\/p>\n<p>* Check that we handle every extension in sloccount&#8217;s list.<\/p>\n<p>* Detect inline assembler in C?  https:\/\/en.wikipedia.org\/wiki\/Inline_assembler.<\/p>\n<p>Here&#8217;s the set of languages supported: ada algol60 asm autotools awk c c# c++ c-header clojure clojurescript clu cobol cobra csh css d dart eiffel elisp erlang expect f# fortran fortran03 fortran90 fortran95 go haskell icon java javascript kotlin lex lisp lua m4 makefile ml modula2 modula3 mumps oberon objective-c occam pascal perl php php3 php4 php5 php6 php7 pl\/1 pop11 prolog python rebol ruby rust sather scheme scons sed shell simula sql swift tcl verilog vhdl vrml waf yacc.<\/p>\n<p>If something you actually use isn&#8217;t on there, send me a code sample with the name of the language in it. The code samples should contain a block comment and a winged comment as well as code comprising at least one full statement. &#8220;Hello, world&#8221; will do.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I just released the 2.0 version of loccount. This is a major release with many new features and upgrades. It&#8217;s gone well beyond just being a faster, cleaner, bug-fixed port of David A. Wheeler&#8217;s sloccount. The count of supported languages is now up to 74 from sloccount&#8217;s 30. But the bigger change is that for&hellip; <a class=\"more-link\" href=\"http:\/\/esr.ibiblio.org\/?p=8250\">Continue reading <span class=\"screen-reader-text\">Announcing loccount 2.0 &#8211; now up to 74 languages<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-8250","post","type-post","status-publish","format-standard","hentry","category-software","entry"],"_links":{"self":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts\/8250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8250"}],"version-history":[{"count":2,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts\/8250\/revisions"}],"predecessor-version":[{"id":8252,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=\/wp\/v2\/posts\/8250\/revisions\/8252"}],"wp:attachment":[{"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8250"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/esr.ibiblio.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}