How many characters are in one line?

Hy guys.

I got a noob question, tried to look on the internet without success. Look the following notice:

Linux kernel exceeds 15 million lines of code

Now, how many characters are in one line ? I opened my text editor to the figure this out and got this crazy thing:

Screenshot

Thanks

2

2 Answers

Your question cannot really be reasonably answered. You're kind of asking the wrong question here.

There is no constant number of characters per line. A line, in the general, technical sense, can be an arbitrarily long sequence of characters that ends with a newline character \n. If that character just doesn't occur, the line can become extremely long. It really depends on the contents of what you write. It's not like in a word processor (or on this web site), where line breaks occur automatically, and the possible line length depends on font size, or page orientation.

In source code, this is also coupled with the difficulty of determining what exactly a line of code is. Do source code comments, that aren't actually code, i.e. processing instructions, count? Do empty lines (lines with only whitespace) count? For source code, there's a metric called Source Lines of Code, or SLOC. This article has some more information about it.

In a linked article, the H states:

It's worth noting that these figures do include the comments, blank lines, documentation, scripts and userland tools included with the kernel (find . -type f -not -regex '\./\.git.*' | xargs cat | wc -l).

So it's really the number of newline characters, including comments, empty lines, etc. of all files excluding the revision control metadata (git) files. This measures the physical lines (counting the \n characters), and really depends on things like source code formatting.

Well, for the linux kernel, there is actually a hard limit of 80 characters per line enforced.

However, you can figure out the average line length by taking the the file sizes and dividing by the rough number of lines (or using any line/character tool such as wc)

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like