Skip to content

Commit dcf462a

Browse files
committed
feat: why new line article
1 parent cf6ab33 commit dcf462a

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

posts/clean-code/why-new-line.mdx

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
---
2+
title: "파일 끝에 개행이 필요한 이유"
3+
date: "2024-06-10"
4+
tags: ["Clean Code"]
5+
summary: "File dose not end with a newline"
6+
description: "파일 끝에 개행이 필요한 이유와 POSIX 표준에 대해서 간략히 알아보자."
7+
---
8+
9+
10+
:::info
11+
파일 끝에 개행이 없는 경우는 CheckStyle 을 돌리거나, github 으로 Pull Request 를 하면 경고가 뜨는 이유는
12+
POSIX 명세 때문인데, 그 현상과 POSIX 표준에 대해서 간략히 알아보자.
13+
:::
14+
15+
---
16+
17+
### 파일 끝에 개행이 없는 경우의 현상
18+
19+
Check Style 의 결과로 `File does not end with a newline.` 경고가 발생한다.
20+
![warning](/img/post/clean-code/new-line/check-style-result.png)
21+
22+
github 에서 `Pull Request` 할 때 이상한 마크도 표시되는 것을 볼 수 있다.
23+
24+
![github-pr](/img/post/clean-code/new-line/github-pr.png)
25+
26+
하지만, 프로그램을 돌리거나 코드 상에 이상이 있는 것은 전혀 아니다.
27+
이는 `POSIX` 명세 때문에 경고로 알려주는 것이다.
28+
29+
30+
---
31+
32+
### POSIX 표준이란?
33+
34+
`POSIX(Portable operating system interface)`는 운영체제 간의 호환성을 유지하기 위해 1980년대에 IEEE 에서 개발한 표준이다.
35+
소프트웨어가 `POSIX` 표준을 충족한다면 다른 `POSIX` 호환 운영 체제와도 호환되어야 하는 것과 같다.
36+
37+
`POSIX` 표준은 1988년에 출시된 반면에 IEEE Std 1003.1-2017 은 2017에 출시되었다.
38+
`POSIX` 표준 개발에는 여러가지 이유가 있는데 그 중에서도 응용프로그램 개발과 이식성을 쉽게 하기 위해 만들어졌기 때문에
39+
UNIX 뿐만 아니라 다른 Non_UNIX 시스템에서도 사용할 수 있도록 만들었다.
40+
41+
이 표준은 어플리케이션이나 운영체제의 개발을 정의하지 않고 단지 어플리케이션과 운영체제의 계약을 설명한다.
42+
`POSIX` 표준은 C언어로 작성되었지만 모든 언어와 함께 사용할 수 있다.
43+
`POSIX` 는 성능 저하 없이 이식성을 달성할 수 있도록 설계 되었고, 개발자의 시간과 비용을 절약할 수 있다.
44+
이식성을 달성할 수 없는 경우 모든 시스템에 대해서 코드를 작성해야하는데 이는 시간과 비용이 많이 드는 프로세스이다.
45+
46+
간단히 말해서 `POSIX` 는 전 세계 개발자가 어플리케이션을 `POSIX` 표준 기능과 호환 되도록 만들기 위해 따르는 **일련의 규칙 및 지침이다.**
47+
이는 어플리케이션이 다른 운영 체제에서 실행될 수 있는 이유다.
48+
따라서, 파일에 개행이 없는 경우, 경고를 만나게 되는 것이다.
49+
50+
추가적으로, [IEEE Std 1003.1-2001 표준](https://pubs.opengroup.org/onlinepubs/007904875/basedefs/xbd_chap03.html) 에 따르면,
51+
Text File 은 `<newline>` 이 포함된 하나 이상의 줄로 구성된 문자가 포함된 파일이다.
52+
53+
:::neutral
54+
Definitions - 3.392 Text File
55+
A file that contains characters organized into one or more lines.
56+
The lines do not contain NUL characters and none can exceed LINE_MAX bytes in length, including the `<newline>`.
57+
Although IEEE Std 1003.1-2001 does not distinguish between text files and binary files (see the ISO C standard),
58+
many utilities only produce predictable or meaningful output when operating on text files.
59+
The standard utilities that have such restrictions always specify "text files" in their STDIN or INPUT FILES sections.
60+
:::
61+
62+
63+
Line 은 0개 이상의 `<newline>` 이 아닌 시작과 끝에 `<newline>` 을 더한 시퀀스이다.
64+
:::neutral
65+
Definitions - 3.205 Line : `A sequence of zero or more non- <newline>s plus a terminating <newline>.`
66+
:::
67+
68+
IntelliJ 기준으로 자동으로 마지막 개행을 추가하는 옵션은 default 로 활성화 되어 있다. <br />
69+
Preference > Editor > General > On Save > Ensure every saved file ends with a line break
70+
71+
![intellij-settings.png](/img/post/clean-code/new-line/intellij-settings.png)
72+
73+
---
74+
75+
:::success
76+
<b>개인적인 생각</b>
77+
알고 쓰는 것과 모르고 쓰는 것은 차이가 있다고 생각한다.
78+
POSIX 명세에 의해서 표준 기능과 호환 되도록 만들기 위해서 따르는 일련의 규칙과 지침을 잘 따라보자!
79+
:::
80+
81+
<br/>
82+
83+
---
84+
85+
### 📚 Reference
86+
87+
* [IEEE Std 1003.1-2001 표준](https://pubs.opengroup.org/onlinepubs/007904875/basedefs/xbd_chap03.html)
88+
* [A Guide to POSIX](https://www.baeldung.com/linux/posix)
89+
* [POSIX](https://medium.com/@cloud.devops.enthusiast/posix-59d0ee68b498)
90+
91+
<br/><br/>
43.5 KB
Loading
28.7 KB
Loading
132 KB
Loading

0 commit comments

Comments
 (0)