Source Code Counter (SCC)
SCC is a cross-platform tool written in Java to count the number of lines in source code files. Counting the number of lines in source code files can usually be done using command line tools under Unix or with an IDE, but SCC extends this to be a far easier and more customisable process. This is achieved using the following methods:
- A GUI is used to give the user complete control over which files are processed
- Blank lines are counted separately from lines containing source code statements
- Configurable regular expressions can be applied to count parts of source code files separately
- Regular expressions are applied according to a file type rather than to all files
- SCC can process any textual source code file. Some examples include Java, C/C++/C#, Perl, Python, PHP, Ruby, TCL
- The line count is split between blank, counted and remaining lines
- Results and summaries can be exported to a csv file for further processing
Apart from an abstract interest in the number of lines of code in a particular project, there are two main use cases for SCC.
The first use case is when developing software commercially it is important to be able to demonstrate some level of productivity. As a measure of productivity or function count, lines of code is actually a poor indicator but is often used when no other indicators are readily available. SCC makes it fairly easy to count lines of code and remove blank lines and boilerplate statements such as copyright and coding comments that can distort the actual programmer created lines of code written.
The second use case is checking the quality of code to ensure that certain things are present (e.g. copyright statement) or alternatively missing (e.g. missing alt attribute from HTML img tags). In the Java world tools like Checkstyle and PMD can be run to verify certain things based on rules. These tools should still be used, but SCC augments this checking process in a few ways.
- By allowing a user to apply checks to all the files in a project (e.g. HTML, text) and not just the source code files.
- By allowing anyone to process the source code without having to set-up a tool suite or IDE like a developer.
- Java has a very good array of code quality checking tools. This isn't necessarily the case for some other languages.
- Code quality tools often look at the structure of the code. SCC is purely concerned with the content of files. Regular expressions allow some greater freedoms in how code is processed compared to the relatively difficult task of writing a custom rule in one of the code quality tools.
Other Features
- Easy step-by-step approach to selecting and counting files
- Tooltips available wherever possible
- Keyboard accelerators for accessibility
- Popup menu for entries in the file selection and results table
- Internal file viewer
- Can handle files encoded using different character sets
- UI is extensible to support different languages (e.g. French, German, etc)
Licence
SCC is open source software distributed under the terms of the GPLv3.
Download v1.0
Note: You will need the Java 6 JRE installed for your operating system to run Source Code Counter.
Updates
You can subscribe to updates at Freshmeat.net
Screen Shots
Tab 1 - Selected files to count
Files can either be dragged from your operating system's file manager or you can use the Add Files button. A file selection can be saved for later re-use. Note that unknown file types are highlighted in red. Makefiles have been selected in the File Types list on the left, which has selected all Makefiles in the File Selection Table on the right.
Tab 2 - Selecting counters to apply
Which counters (regular expressions) to apply can be configured here.
Tab 3 - Count the files and see the results
The Count button is clicked to process the selected files and the results displayed in the tables.
FAQ
- How do I print?
- Export the results or file selection to a csv or text file respectively and open in a spreadsheet or text editor.
- Why are some comments not counted?
- The default regular expressions are looking for lines that start with either blank space or a comment. If you want to
count comments regardless of where they appear remove the
^[ \t]*
from the beginning of the regular expression. - What are unknown files?
- Unkown files are files that don't have a definition on tab 2 within the file types tree, i.e. their file extension or file name is undefined. An example would be a Microsoft Word file such as cv.doc.
- Why aren't unknown files treated as text by default?
Because unknown files are more likely to be binary than text and there's no point in trying to process a binary file. If you know that a file type is definitely textual you can add it to the file types list on tab 2.
You can however override this default behaviour by setting how unknown files should be treated from the Options menu.
- Why isn't programming language X covered?
I've tried to cover as many languages as possible but have probably missed a few lesser known languages. You can add your own within the File Types tree on tab 2.
Alternatively, if there are languages you aren't going to use, just delete them (you can always get them back by resetting the list).
The default (non-exhaustive) list currently includes: Ada, Algol, ASP, Assembly, Awk, Bean Shell, C/C++/C#, Makefile, COBOL, CSS, CSV, Delphi/Pascal, Drools, Erlang, F#, Flex, Forth, Fortran, Groovy, Haskell, HTML, Java, JSP, JavaScript, LaTeX/TeX, Linux Kernel Config, Lisp, Lua, Modula3, Objective-C, Perl, PHP, Prolog, Python, Ruby, Scala, SED, Shell script, SQL, TCL/TK, Text, (Visual) Basic, Windows Batch script, XML (DTD, RelaxNG, Schema, Schematron, XSLT), XQuery, Yacc/Bison
- Why do some files cause an error?
- There are a number of reasons why a file may not be able to be read by the program.
- Check that the file permissions allow you to read the file
- Check that the file you're trying to read contains text
- Check that you are reading the file with the right character set. If you see an error like Input length = 1 or an error on the console like java.nio.charset.MalformedInputException try changing the character set encoding in use from the Options menu.
- When I add a directory why does it carry on adding files?
- Check that there are no symbolic links creating a circular directory tree as SourceCodeCounter can't detect symbolic links.
- How can I stop SCC from adding or counting files?
- Click the rotating circle in the bottom right corner of the window.
- How fast is Source Code Counter?
This rather depends on the machine you run it on, the number of files you want to process and the number of regular expressions. On an AMD Athlon 64 3000+ machine running Linux SCC can add the Linux source tree (~24,000 files) to the file selection table in a matter of seconds and be able to count all the files in a couple of minutes (193 files/second).
If you have a machine with a number of processing cores you can increase the number of file counters from the Options menu to count files in parallel and thus increase the speed.
- How do I learn regular expressions?
- Information on regular expressions (regex for short) can be found at Wikipedia and at Regular-Expressions.info. Java specific regex information can be found in the API documentation.