10

Why do text editors have to add an empty line at the end of files? It is making me and my C++ programs confused!

Comments
  • 1
    o_O just handle an optional trailing newline?
  • 1
    because it can confuse some programs (that's what I read at least). GitHub and GitLab display a notice when the file doesn't have a newline at the end. (and flake8(python linter) gives an error)
  • 1
    @Olverine maybe this can help you

    "The 'newline' character or more accurately 'end of line' character (<EOL>) means 'whatever comes after this point must be considered to be on another line'. With this interpretation — <EOL> is a line terminator — the last line of the file is effectively the last one with an <EOL>.

    The problem is that most editors and IDEs have a different interpretation — <EOL> is a line separator — and, logically, default to not add an <EOL> at the end of the last line of a new file and, when they encounter an <EOL>, add a superfluous 'new line' after the real last line."
  • 1
    @GitBug ues it makes sense but im kimda pissed that i've been debugging my code for days and just realized that the program is reading from a file with an empty line at the end. Which is causing a bug.
  • 0
    How do you even get this problem? Never ever never wrote code without trimming your inputs (unless you need the non-trimmed input)... It's like hello world stuff.
  • 1
    @Bikonja Just didn't think about it. I mean, I wrote the file myself and thought I knew exactly what it contained. It was just gonna be a quick test so I just made it as simple as it could get.
  • 0
    @Olverine fair enough. Quick test with own input never work though 😵
Add Comment