rather than spreading through the code1 [C++ Core Guidelines] P.11 지저분하게 코딩하지 말고 캡슐화하자 P.11: Encapsulate messy constructs, rather than spreading through the code 이유지저분한 코드는 버그를 숨길 가능성이 높고 유지보수가 어렵습니다. 인터페이스를 만들면 사용하기 쉽고 안전합니다. 예시 (나쁜 예)int sz = 100;int* p = (int*) malloc(sizeof(int) * sz);int count = 0;// ...for (;;) { // ... x 값을 계속 입력받고, 파일 끝(EOF)에 도달하면 루프를 종료하는 코드 ... // ... x 값이 정상적인지 검증하는 코드 ... if (count == sz) p = (int*) realloc(p, sizeof(int) * sz * 2); .. 2024. 4. 26. 이전 1 다음