Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LBP] 남궁혜민 계산기 과제 제출합니다. #1

Open
wants to merge 12 commits into
base: hyeminililo
Choose a base branch
from

Conversation

hyeminililo
Copy link

스터디명

질문

  1. docs에 필요한 기능을 기재해뒀는데, 추가적으로 필요한 기능이 있을까요?
  2. docs에 적여져 있는 기능 단위로 함수를 나누려고하였는데 적절히 함수를 구현했는지 궁금합니다.
    3.구분 지정자는 구현을 하였지만, 커스텀 구분자를 확인해보면 NumberFormatException이 생기는 상태입니다. 어떤식으로 접근을 해야할지 모르겠습니다.
    4, 커스텀 구분 지정자는 하나의 문자만 등록하게 해도 괜찮은가요? 2개이상은 예외처리를 하면 되는것인지 궁금합니다.

어려웠던 점

코틀린 언어 실력이 아직 부족해, 코틀린 언어를 사용하는 것에서 미숙한 부분이 많은 것 같습니다. 우선 돌아가는 것에 중점을 두고 페어와 같이 구현했습니다. 돌아간 이후에 코틀린의 장점과 특징을 살려서 리팩토링을 하고 싶은데 어떤식으로 접근해야하는지 어렵습니다.

Copy link

@cucumber99 cucumber99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아직 코틀린 문법을 제대로 숙지하지 못한 상태에서 최선을 다해 주신 것 같아요.
우선 질문에 대한 답을 해볼게요.

  1. docs에 필요한 기능을 기재해뒀는데, 추가적으로 필요한 기능이 있을까요?
  2. docs에 적여져 있는 기능 단위로 함수를 나누려고하였는데 적절히 함수를 구현했는지 궁금합니다.
  • README.md 파일에 작성한 내용을 말씀하시는 것 같은데, 제대로 업로드가 안된 것 같아요.
  1. 구분 지정자는 구현을 하였지만, 커스텀 구분자를 확인해보면 NumberFormatException이 생기는 상태입니다. 어떤식으로 접근을 해야할지 모르겠습니다.
  • NumberFormatException은 숫자가 아닌 값을 숫자로 변경하려고 시도할 때 발생하는 오류예요. 제가 질문을 보지 않은 상태에서 코드 리뷰를 작성했는데, 역시 문제가 발생하네요. 사실 이 미션에서의 해결 방법은 간단해요. 사용자가 잘못된 값을 입력할 경우 예외 처리 후 프로그램을 바로 종료시키면 되기 때문에, toInt()를 호출하기 전에 값에 대한 검증을 하면 되겠죠? 이렇듯 프로그램에서 발생할 수 있는 다양한 문제를 일일이 생각하면서 코드를 작성할 수 없기 때문에 테스트 코드를 작성해야 해요. 뿐만 아니라 각 객체와 기능이 단위에 따라 적절하게 분리되어 있으면 테스트 코드를 작성하기 수월할뿐더러 오류가 발생했을 때 어느 기능에서 문제가 발생했는지 쉽게 파악할 수 있어요. 객체 지향 프로그래밍이 왜 중요한지에 대해 이런 경험에서 알아갔으면 좋겠어요.
  1. 커스텀 구분 지정자는 하나의 문자만 등록하게 해도 괜찮은가요? 2개이상은 예외처리를 하면 되는것인지 궁금합니다.
  • 저 또한 이 미션을 해결했던 적이 있는데, 이러한 의문점을 가졌었어요. 제 경우에는 단 하나의 커스텀 구분 지정자만을 사용하게 하였고, 그 이상은 예외 처리를 했어요. 여기에는 정답이 없으므로, 생각한 대로 하시면 될 것 같아요.

아직 코틀린에 익숙하지 않으셔서 생기는 문제가 대다수라고 생각합니다.
처음부터 잘하는 사람은 없으니 하나씩 고쳐가면 충분히 나아질 수 있어요.

  1. 코딩 컨벤션에 맞지 않는 부분이 많아요. 인텔리제이의 경우 Ctrl + Shift + L 단축키를 사용하면 해당 언어에 맞게끔 알아서 수정해주니 코드를 작성하고 나서 활용해보세요. 또한 Kotlin Style Guide 문서나 코틀린 공식 문서를 보는 것을 적극 권장드려요.
  2. 프로그램에서 사용되는 핵심적인 값 (이 미션에서는 숫자, 구분자 등) 에 대한 처리를 개선하면 좋을 것 같아요. 특정 값을 객체로 감싸면 타입 안정성이나 캡슐화 등을 보장할 수 있을 뿐만 아니라 객체가 생성될 때 init을 활용하여 유효성 검사를 할 수도 있어요. 위에서 언급했듯이 테스트 용이성도 있겠죠? 객체를 어떻게 활용해야 할지 모르겠다면, 다른 사람들의 코드를 보는 것도 하나의 방법이 될 수 있어요.
  3. 입력값에서 숫자와 구분자를 분리하는 기능이 조금 불안정한 것 같아요. 코드를 보면 slice()에 인덱스를 입력하여 분리하고 있는데, 리뷰에서 언급한 것처럼 예상치 못한 형식으로 값이 입력된다면 문제가 될 수 있어요. 사람마다 다르겠지만, 이러한 경우 저는 정규표현식을 활용할 때가 많아요. 정규표현식에 대해 학습하고 리팩토링에 적용해보세요.

리팩토링 파이팅입니다! 궁금하거나 막히는 부분이 있으면 꼭 저에게 질문해주세요!

}

var numList = mutableListOf<Int>()
var isCoustom = identifySign(num)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 스펠링 오류!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하겠습니다 !

fun main() {
// TODO: 프로그램 구현
print("덧셈할 문자열을 입력해 주세요.")
var num = readLine().toString()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readLine()의 반환형은 문자열인데, 왜 toString()을 사용하셨나요?
또한 해당 문제에서는 Console API의 readLine()을 사용하셔야 해요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반환형이 문자열이라고 생각을 못했던 것 같아요! 수정했습니다 :)

var num = readLine().toString()


if(num == " " || num == ""){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

입력값이 존재하지 않는 경우는 문자열 객체의 메소드를 이용하여 검증할 수 있습니다.
isEmpty(), isBlank() 등 다양한 메소드가 있으니 찾아보고 리팩토링하는걸 추천드려요~

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

객체 메소드를 사용해서 수정했습니다 :)

var isCoustom = identifySign(num)
if(isCoustom){
val sign = extractSign(num)
print(num.slice(5..<num.length))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

값을 확인하기 위한 print인가요?
제가 생각한 것이 맞다면 프로그램 실행 예시와 다르기 때문에 지우셔야 해요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이것으로 인해 오류가 난 것 같더라고요 😭 수정했습니다 :)

}
val result = sum(numList)

print("결과값은 : ${result}")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

출력 형식이 실행 예시와 달라요!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수정하겠습니다.

Comment on lines 93 to 95
for(i in a){
if(i <= 0 ){ inputNotPositive()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 컬렉션 함수를 활용하면 indent depth를 줄일 수 있을 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

찾아보고 추가적으로 수정하겠습니다!

Comment on lines 107 to 111
fun getResult(result :Int
) {
print("결과값은 : ${result} 입니다.")

}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

결과값 출력에 사용되는 메소드를 정의하였는데, 제대로 활용하지 못한 것 같아요.
중복된 로직을 없앨 수 있어요! 한번 main 함수의 코드를 살펴보세요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인했습니다 :)

Comment on lines 51 to 53
fun zeroReturn():Int{
return 0;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0이라는 값을 메소드를 통해 반환하지 않고, 상수로 정의해두는 것은 어떨까요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 리뷰처럼 수정하겠습니다 :)

Comment on lines 37 to 48
// 예외처리 부분
fun inputNotPositive() {
throw IllegalArgumentException("입력값이 양수가 아닙니다. ")
}

fun incorrectSign(){
throw IllegalArgumentException("구분자와 양수가 아닌 문자가 입력되었습니다.")
}

fun undefineSign(){
throw IllegalArgumentException("//와\n사이에 커스텀 구분자를 정의하지 않았습니다.")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 상황들 외에도 예외 처리가 필요한 더 많은 상황이 존재할 것 같아요.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코드리뷰를 보고 추가적으로 예외처리를 만들려고 했는데 리팩토링 이후에 추가적으로 더 필요한 예외처리가 있을까요?

}


fun extractSign(a : String) : Char{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

부호를 Char 형으로 사용하신 이유는 무엇인가요?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커스텀 구분 연산자가 하나의 문자라고 가정을 하고 반환을 하려다 보니 Char형으로 선언한 것 같습니다. 정규식을 이용해서 이 부분 수정했습니다.

cucumber99

This comment was marked as duplicate.

@hyeminililo
Copy link
Author

코드 리뷰를 바탕으로 수정했습니다 :) Readme 파일이 페어와 하다보니 제 깃에는 누락되었던 것 같습니다. 추가적으로 올려두었습니다. 그리고 코드리뷰를 읽어보면서 isBlank()와 같은 메소드를 사용하도록 리팩토링하였습니다! 그리고 코드리뷰처럼 정규식을 이용해 리팩토링을 하니, 커스텀 구분자가 있는지 확인하고 추출하는 함수를 하나의 함수로 합치는 것이 더 좋을 것 같아 하나의 함수로 합쳐 리팩토링 진행했습니다 :)

@hangillee hangillee requested a review from cucumber99 February 10, 2025 13:35
Copy link

@cucumber99 cucumber99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

리팩토링 고생하셨어요~
문법 측면에서 확실하게 개선된 것 같아요.
다만 예외 처리 로직이나, 변수 선언 등 아쉬운 점은 아직 존재하는 것 같아요.
다음 미션에서는 아쉬운 점을 보완하고, 클래스를 이용한 분리가 제대로 이루어졌으면 합니다.
궁금한 점이 있으면 물어보세요~파이팅👍

Comment on lines +46 to +47
val b = input.substringAfter("\\n")
return b.split(sign)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수명을 조금 더 의미있고 명확하게 작성하는것도 중요한 요소 중 하나라고 생각해요!
b라고만 하면 어떤 코드인지 한 눈에 파악하기 힘들 것 같아요.

Comment on lines +77 to +83
fun sum(numList: List<Int>): Int {
var result: Int = 0
for (i in numList) {
result += i
}
return result
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

직접 구현하는 것도 괜찮지만, List<Int>의 컬렉션 API를 활용하는 방법도 있어요.
for문을 이용해 합을 계산하는 것과, 컬렉션 API를 통해 계산하는 것은 어떤 차이가 있는지 생각해보는 것도 좋을 것 같아요.

if (matchResult == null) {
undefineSign()
}
return matchResult?.groupValues?.get(1) // "//"와 "\n" 사이의 문자열 그대로 반환

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nullable을 이용하는 것 말고 더 좋은 방법이 있을까요?

Comment on lines +21 to +22
val splitList = basicSplit(inputNumber)
var intList = stringToInt(splitList)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

intListvar로 선언하신 이유는 무엇인가요?
valvar의 차이에 대해 자세히 알아보아요~

@hyeminililo
Copy link
Author

다른 차시 미션을 하다보니 답장이 늦어졌네요 ,, 죄송합니다 😭 2차 코드리뷰 다시 읽어보면서 리팩토링 완료하였습니다 ! 그런데 nullable을 이용하는 것 말고 더 좋은 방법이 있을까요? 요부분에 대해서는 아직 정답을 잘 모르겠습니다🥹

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants