What is your line/char count?

I was working on my little game engine and I was a bit curious… So I made this simple script to see how many lines of code (in total) I had and also how much characters (in total):


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;

public class Count {
	public static void main(String[] args) {
		System.out.println(getLineCount(new File("src")) + " lines of code.");
		System.out.println(getCharCount(new File("src")) + " characters.");
	}
	public static int getLineCount(File file) {
		if (file.isDirectory()) {
			int count = 0;
			for (File child : file.listFiles()) {
				count += getLineCount(child);
			}
			return count;
		}
		int count = 0;
		try {
			BufferedReader reader = new BufferedReader(new FileReader(file));
			while (reader.readLine() != null) {
				count++;
			}
			reader.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return count;
	}
	public static int getCharCount(File file) {
		if (file.isDirectory()) {
			int count = 0;
			for (File child : file.listFiles()) {
				count += getCharCount(child);
			}
			return count;
		}
		int count = 0;
		try {
			FileReader reader = new FileReader(file);
			while (reader.read() != -1) {
				count++;
			}
			reader.close();
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		return count;
	}
}

For me:

Project: Red Game 2D Engine
8176 lines of code.
228337 characters.
About 1000 lines where generated (but I typed the code to generate it).

And I was wondering how many lines/chars other people’s projects had… So give it a try…

If you’re on Linux (and maybe Mac), and you have the globstar option set in your shell (shopt -s globstar in bash), you can do wc -l src/**/*.java for lines and wc -m src/**/*.java for chars.

Never knew that… But I use windows 8.1…

But I’m just curious on how big some people’s projects are… (just a random thought: does Github have a global line/char count thing?)

I use the Statistic plugin in IntelliJ IDEA. (Click on image to see full size)


http://i.imgur.com/3u5cekf.png


http://i.imgur.com/Q6GFHTN.png

Complete source code statistics, and it also categorizes files by extensions. Works fine for me.

Dayum I thought my project was a bit bigger :smiley:

Only 7k lines with lots of empty lines :slight_smile:

SPGL2, the enginey-frameworky-mishmash underpinning new stuff here at Puppy Towers, currently comes in at:

2.9m characters
58 kloc
532 classes
104 interfaces

Cas :slight_smile:

Ugh for my ship core class , 1000 lines , 2766 words and 25462 characters. At a total amount I estimate about 8-10k lines

According to your code, Retro-Pixel Castles has:

40425 lines of code.
1327042 characters.
(in 403 .class files)

Quality > Quantity :wink:

Yeah but however it’s interesting.

In my current game engine that I’m developing there are

5401 lines,
432997 chars.

And I’m only at the beginning of my engine.

This is a funny little piece of code, as it always does this for me:


# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (classFileParser.cpp:3470), pid=5108, tid=5536
#  Error: ShouldNotReachHere()

… ???

Mercury has about 11,803 lines, and 295,463 characters.

However, the real fun is in github. It tells you how many lines of code you have deleted and added:

http://puu.sh/fXPl1/8ac3afa68a.png

Old one Engine :slight_smile:
25943 lines of code.
806716 characters.

New One. (That I rewriting)
11412 lines of code.
320973 characters.

30k lines - its big (even can’t belive that i do XD)
Some times forgot how masive projects becomes, and how many time and work we trow on them ^^

p.s (find in google ;))
Minecraft (1.6.4), 242,138 (auto gen decompiled)
Linux have 15mil lines ^^ we still so small

Up:
^^

getCharCount() = File size

Try read file biger then hi is

  • file restricted access (or used and blocked another program)
  • or wrong OS Java implementation.
    or broken part of hdd.

https://bugs.openjdk.java.net/browse/JDK-7144885

In my Battlefield hack I’m estimating around 4k lines of the actual hack and about 3k more of the reversed SDK.
About a year ago I was working on that block game which had around 8k if I remember correctly.

When you think about it, it’s really impressive that we can remember all the data structures, class flow, and everything our code does. It’s thousands of lines and in [removed: some] many cases hacky little fixes that our brains can process in milliseconds.

I use Metrics plugin, and it says that my libgdx core project has 13886 lines :open_mouth:

Quite true , I have a 500 line graphics class , a thousand line ship class a 300 line ship handler class particle systems , vertex classes , cameras , effects and I know what every function does and how to use it , if there is a bug I almost instantly know whats caused it. Weird.

I once wrote a 851 line object class. It is part of my first game engine (in Java2D of course).

Not hard when it’s mostly comments. :stuck_out_tongue:

Yes it is, but it is still a large amount of data to type, and the question being line/char count, not code lines only not comments.

In the recent open-sourcing of .NET core CLR, gc.cpp was uncovered at >35 kloc!
https://raw.githubusercontent.com/dotnet/coreclr/master/src/gc/gc.cpp

Ctrl-U in chrome to get line numbers.