# Line break formats and character numbers [duplicate]

I've recently saw someone, who says that their code is 350 characters long.

### Problem

It can vary depending on platform.

### My suggestions

Do either one of these:

• Add an automatic character count, so it will be consistent.
• Require users to use a specific line break format (stated in the FAQ or when asking/answering questions), and calculate character count based on that. It can be done very easily with most text editors, like Notepad++.

## marked as duplicate by Martin EnderSep 22 '16 at 21:30

I would always treat newlines as single characters. Their representation as 2 bytes on windows is a historical oddity (and perhaps an abomination, too, but that is another story).

Figuring out how to count that way is your problem.

Unix people have an equivalent (if less distressing) issue where many editors append a trailing (and unnecessary) newline to files automatically for historical reasons relating to fragile core command-line tools. Usually I just accept the one character penalty on mine.

• for vim, :set binary noel. – ninjalj Feb 4 '11 at 20:28
• Interesting that Unix people treat CRLF as historical oddity and abomination but fail to see the same thing in terminal emulators ;-) – Joey Feb 5 '11 at 15:24
• On a related note: I have yet to see a language that mandates CRLF (not even batch files on Windows) or a trailing LF (some C compilers emit a warning but I guess most of them have outgrown the 1960s by now and none throws up on it). – Joey Feb 5 '11 at 15:27
• @Joey Oh "terminal emulators" as such are a historical oddity and we can be thankful that few people are targeting the more obscure terminals these days, but the command line persists because it is the Interface of the Gods. – dmckee Feb 5 '11 at 15:40
• Oh, nothing wrong with CLIs in my eyes ;-). Just treating text as an API always sounded quite wrong to me. And at one time something spit out a manpage in the form of b^Hbo^Hol^Hld^Hd text and I bet even NULs after line feeds are still eaten ;-) – Joey Feb 5 '11 at 15:51
• @Joey: Go mandates a trailing newline: ideone.com/0EEAu – Joey Adams May 3 '11 at 15:57
• @Joey: Yikes, that's a serious WTF. Who on earth thought that to be a good idea? – Joey May 3 '11 at 16:09
• It's a good idea insofar as it sidesteps the religious war. It sucks for code golf (I'm in the "no trailing newline counted if it isn't necessary" camp) – J B Sep 28 '11 at 22:30
• Text editors append a trailing LF because text files should have one. Without it, displaying a text file in a terminal emulator won't put the prompt on a new line, concatenating two text files will join the last line of the first with the first line of the second and some tools (apt-get) and compilers (C) and interpreters (PHP) will show errors or at least warnings. – Dennis May 19 '14 at 5:27