파일 끝에는 new line이 왜 필요한가?

Hyunta·2022년 2월 21일
0

자동차 경주 미션

목록 보기
4/7

파일의 끝에는 new line을 넣어주세요.

해당 피드백을 받고나서 파일 끝에 new line이 왜 필요하지? 호기심이 생겼다. 하지만 매번 신경쓰기는 귀찮은 일이라, 어떻게 자동화하면 좋을지도 찾아봤다.

POSIX 명세

POSIX는 IEEE가 제정한 유닉스의 애플리케이션 프로그래밍 인터페이스(API) 규격이다.

옛날에 IEEE가 책정한 POSIX에서 줄(line)을 그렇게 정의했기 때문이다.

Definitions - 3.392 Text File : A file that contains
characters organized into one or more lines. The lines do
not contain NUL characters and none can exceed {LINE_MAX}
bytes in length, including the Although IEEE Std 1003.1-2001
does not distinguish between text files and binary files
(See the ISO C Standard), many utilities only produce
predictable or meaningful output when operating on text
files. The standard utilities that have such restrictions
always specify “text files”in their STDIN or INPUT FILES
sections.
3.206 Line
A sequence of zero or more non-<newline> characters plus a
terminating <newline> character. 
  • 행의 끝(terminating)은 개행(EOL, end-of-line)
  • 텍스트 파일은 행의 집합이며 행은 반드시 개행으로 끝난다.

따라서 파일을 구분하기 위해서는 개행이 필요했었다.

IntelliJ에서 자동으로 적용하는 방법

설정에서 아래 사항을 체크해두면, IDE에서 자동으로 개행을 해준다.

Reference

https://namu.wiki/w/POSIX

profile
세상을 아름답게!

0개의 댓글