On line endings and honesty

December 6, 2008

Dear software, I have a small and simple request, from a working system administrator:

Please stop pretending that \r\n and \n are the same thing.

That is, please stop pretending that MS-DOS line endings and Unix line endings are the same thing, because they are not. Pretending that they are is one of those collective hallucinations that only work if absolutely everyone is playing along. Sooner or later (usually sooner) you will run into a program that does not play along, and things go violently off the rails.

(By 'you' I actually mean 'I'.)

If you are a Unix program and you want to be helpful this way, you should have an explicit switch to turn on ignoring the difference, and this switch should not be on by default. (And if you are a Linux distribution, you should not turn this switch on for me to be helpful. Turning it on is not doing me any favours; rather the contrary.)

In fact, let me be pretty strong: programs that are helpful this way (including both vim and less and, as I found out today, kdiff3) are actually harmful, because their lies make it much harder to diagnose what is going on when some program does notice or object, transforming an ordinary problem into a frustrating, time-consuming mystery. If I have to drag out od to diagnose my problems, you are doing it wrong.

(The most frustrating problems are when programs notice in small ways, such as changing the value of the last field in all of the lines because they now have invisible ^Ms at the end. Programs that object are actually the easy case.)

Comments on this page:

From at 2008-12-06 12:04:11:

when you edit a file with dos line endings in vim, it sets the filetype to "dos" and shows this to you in the bottom line (unless you don't have a ruler line):

"test" [dos] 6L, 20C

When you mix dos and unix file endings in one file, it shows the extra \r as an ^M at the end of the line. I find this much more helpfull than forcing me to se the extra ^M all the time. I'm pretty sure you can disable that and make vim always read the file as if it was filetype unix, so that you always get to see the \r. Should be written somewhere on

:help fileformat 

hope that helps,

From at 2008-12-06 18:15:03:

Good. I am not the only one annoyed by this.

/me applauds

Written on 06 December 2008.
« A little gotcha when implementing shell read
One of Python's problems with packages »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sat Dec 6 02:44:00 2008
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.