Skip to content

숫자게임 [STEP1] 애종, LJ - #138

Merged
bar-d merged 13 commits into
yagom-academy:ic_7_lj777from
jylim72:main
Aug 19, 2022
Merged

bar-d merged 13 commits into
yagom-academy:ic_7_lj777from
jylim72:main

Conversation

@jylim72

@jylim72 jylim72 commented Aug 18, 2022

Copy link
Copy Markdown

@bar-d

STEP 1

고민했던 점

  • 볼과 스트라이크를 비교하는 과정을 어떻게 설계할까 고민했습니다. 3가지의 경우의 수로 나누어 어떤것부터 제외해 나갈까 고민한 후 최종적으로 ‘순서에 상관없이 숫자를 포함하는 경우’ 를 먼저 guard로 묶은 후 순서의 일치 여부에 따라 볼과 스트라이크를 구분했습니다.
  • 순서도를 참고하면서 코드 작성할 때 반복문을 for-in, while 중 어떤걸 써야 하는지, 함수로 분해할 때 리턴값을 줄지 여부 등을 고민했습니다.

조언을 얻고 싶은 부분

  • guard 에 return 을 입력했을 때 for 문만 벗어나는게 아니라 checkBallStrike 함수 자체를 end 하는 것처럼 보였습니다. 함수 statement안의 return은 함수 종료를 뜻하는 것 맞나요?

//
//

import Foundation

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Foundation 어떠한 역할을 해주나요?
해당 프레임워크가 현재 필요할까요?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

현재는 swift standard library 정도에서 충분한 내용이므로 필요없다고 보여집니다!!
Foundation이 필요한지 아닌지 궁금할 땐 import Foundation 지워볼게요 !

Comment on lines +9 to +10
var comNumArray: Array<Int> = []
var tempNumArray: Array<Int> = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

변수명을 번역해보면 현재번호의 배열로 보이는데 이 변수는 값이 변할 일이 있을까요?
축약형은 지양해주세요
https://swift.org/documentation/api-design-guidelines/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

넵, API가이드 Naming 읽어보았습니다.😀

  • 모든단어를 포함하기 (이유: 코드보는 사람에 따른 해석의 애매모호함을 피하기 위해)
  • 불필요한 단어 생략하기 (예: 매개변수 타입에 element를 명시해주었다면, 이름에는 ~~element 접미사가 중복으로 불필요함)
  • 타입제약조건이 아닌 해당 변수/파라미터/관련타입의 역할에 따라 이름짓기
  • weak(약한참조?) 매개변수의 역할을 명확히 하기위해 type정보를 보완한다.(예: 매개변수 for:~~ -> forKeyPath: ~~)

변수 선언할 때 변경예정이라면 var 키워드, 변경가능성이 없다면 let 키워드를 이용하여 선언해야한다는 점, 명심할게요😀

Comment on lines +9 to +13
var comNumArray: Array<Int> = []
var tempNumArray: Array<Int> = []
var tryCount: Int = 9
var strikeCount: Int = 0
var ballCount: Int = 0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

전역변수는 최대한 지양해주는 편이 좋아요
무엇 때문일까요?
프로젝트 명세서에 지정된 전역변수가 아니면 전역변수를 없애봅시다
통일성 있게 타입 명시를 해준 점은 👍
컨벤션 통일 좋습니다

@jylim72 jylim72 Aug 19, 2022 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

전역변수는 최대한 지양해야하는 이유 찾아보았습니다.

  • 함수의 독립성을 높인다. (같은함수를 다른프로젝트에서도 사용 가능)
  • 디버깅 효율 향상 (전역변수 사용하면 디버깅할 때 살펴봐야할 변수의 수가 많아짐, 어떤 함수가 이 변수를 잘못건드린건지 찾아내기 어려움)
  • 메모리 절약, 메모리 할당 시간길이가 더 짧아서 절약 가능
    운영체제 -> 메모리 -> 프로그램공간할당
    할당된 메모리공간은 4가지영역으로 구성, 코드 / 데이터 / 힙 / 스택
  • 전역변수 - 데이터영역에 저장 (메모리 할당시점: 프로그램시작~종료)
  • 지역변수 - 스택영역에 저장 (메모리 할당시점: 함수시작~종료)

var strikeCount: Int = 0
var ballCount: Int = 0

func createRandomNumbers() -> [Int] {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

배열 파라미터는 타입을 명시해줄 때 Array<Int>로 명시해 주었는데 반환값은 [Int]로 명시해주고 있어요
컨벤션을 통일해주세요
직관적인 함수명 좋습니다 👍

var ballCount: Int = 0

func createRandomNumbers() -> [Int] {
var numbersSet: Set<Int> = []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

set 타입을 사용해주신 이유가 무엇일까요?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

3개의 중복되지 않는 랜덤 숫자를 모아 배열로 반환해야 했기 때문에 사용했습니다. 내부에 중복을 허용하지 않는 Set 의 특성을 이용해 중복을 없애는 기능을 대신했습니다.

}
}

func startGame() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

군더더기 없는 함수명이네요 👍

Comment on lines +35 to +60
func startGame() {
comNumArray = createRandomNumbers()
while tryCount > 0 {
strikeCount = 0
ballCount = 0
tempNumArray = createRandomNumbers()

print("임의의 수 : \(tempNumArray)")

checkBallStrike()

print("\(strikeCount) 스트라이크, \(ballCount) 볼")

if strikeCount == 3 {
print("사용자 승리...!")
break
}
tryCount -= 1

print("남은 기회 : \(tryCount) \n")
}

if strikeCount != 3 {
print("컴퓨터 승리...!")
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

함수분리를 해보시는건 어떨까요?
예를 들어 사용자가 이겼는지 컴퓨터가 이겼는지를 나타내주는 출력문을 함수로 분리할 수 있을 것 같아요


startGame()


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

불필요한 개행은 지워주세요

Comment thread README.md
@@ -1,6 +1,35 @@
## iOS 커리어 스타터 캠프
# 숫자야구 프로젝트 저장소

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM 👍

Comment thread README.md Outdated
<!--[![xcode](https://img.shields.io/badge/Xcode-13.3-blue)]()-->

# 순서도
<img width="683" alt="STEP2 flowChart" src="https://github.com/lj-7-77/ios-number-baseball/blob/main/flowchart.svg">

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

README 내부에 순서도 파일이 svg파일로 되어있어서 깨지고있는 것 같아요
png파일로 한번 변경해볼까요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

수정했습니다.😀

@bar-d

bar-d commented Aug 18, 2022

Copy link
Copy Markdown

안녕하세요 LJ, 애종
숫자게임 STEP1을 진행하느라 고생하셨습니다.
짧은 시간 내에 구현해내시다니.. 대단하십니다

👏칭찬드리고 싶은 점

공식 문서를 꼼꼼히 읽어보시고 시작한 점 너무 좋아요👏

문서를 꼼꼼히 읽어보아도 처음부터 완벽히 이해하지는 못해도 읽고 시작하는것과 읽지않고 시작하는 차이점은 매우 큽니다
늦게 PR을 보낸다고 자신의 실력이 안좋아지는 것은 아니니, 프로젝트 수행시 참고문서는 읽어주세요

커밋 컨벤션을 잘 지켜주신 것 같아요👏

기능 단위별로 최대한 커밋할려고 노력해주신점 좋습니다

README 작성 아주 좋습니다. 👏👏

이 다음 프로젝트를 할 때에도 README 작성을 잊지말아주세요

순서도가 한번에 이해가 되네요! 👏

해당 순서도를 가지고 다른 언어로도 충분히 숫자게임을 작성할수 있을 것 같아요
다만, STEP1 기준으로 작성된 것이 아니라 STEP2 기준으로 작성되어서 아쉬운 것 같아요
순서도에도 조금의 오류가 있어요
공식문서 한번 읽어보고 디코에서 다시 이야기 해볼까요?


⚠️프로젝트 명세서를 다시 확인해주세요

  • 실행 화면이 프로젝트 요구사항과는 조금 다른 것 같아요
  • 띄어쓰기, 출력 형식, 출력 내용을 다시 한번 확인해주세요
    Screen Shot 2022-08-19 at 2 12 07 AM

고민했던 점

볼과 스트라이크를 비교하는 과정을 어떻게 설계할까 고민했습니다.
3가지의 경우의 수로 나누어 어떤것부터 제외해 나갈까 고민한 후 최종적으로 ‘순서에 상관없이 숫자를 포함하는 경우’ 를 먼저 guard로 묶은 후 순서의 일치 여부에 따라 볼과 스트라이크를 구분했습니다.
순서도를 참고하면서 코드 작성할 때 반복문을 for-in, while 중 어떤걸 써야 하는지, 함수로 분해할 때 리턴값을 줄지 여부 등을 고민했습니다.

  • 어떠한 고민을 하시고 어떻게 해결했는지 구체적으로 적어주시면 더 좋을 것 같아요
  • 반복문 중 어떤 것을 사용하였고, 채택한 이유가 무엇일까요?
  • 함수에 리턴값의 여부는 무엇으로 결정될까요?

조언을 얻고 싶은 부분

guard 에 return 을 입력했을 때 for 문만 벗어나는게 아니라 checkBallStrike 함수 자체를 end 하는 것처럼 보였습니다.
함수 statement안의 return은 함수 종료를 뜻하는 것 맞나요?

  • 제대로 알고 계신 것 같은데요?
    가드문을 통과하지 못하였을 때 return뒤에 반환 값이 없으면 메서드가 종료됩니다
    guard
    return 공식 문서를 보시면 더 확실히 이해하실 수 있으실거에요
  • 해당 문서들을 읽어보고 return, break, continue의 차이점을 정리해보시는 건 어떨까요?

드리고싶은 말씀

  • 앞서 채팅으로 말씀드린 것처럼 제가 커멘트를 남긴 것들이 꼭 정답은 아니에요(저 또한 같이 공부하는 캠퍼입니다)
  • 자신이 쓴 코드에 대해 사용한 이유가 타당하다면 제가 말씀드린것을 꼭 수정할 필요가 없어요
  • 나머지 궁금하신 점이나 이해안되시는 부분이 있다면 채팅방에서 소통해봐요
  • 나머지 프로젝트 기간도 파이팅입니다

//
// NumberBaseball - main.swift
// Created by yagom.
// Created by 애종, LJ.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
// Created by 애종, LJ.
// Created by 애종, LJ.

사소한 것도 고쳐주시면 좋을 것 같아요

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

수정했습니다.😀

jylim72 and others added 4 commits August 19, 2022 16:44
- 변수명 comNumArray -> computerNumberArray
- 변수명 tempNumArray  -> randomNumberArray
- 함수명 checkBallStrike -> checkStrikeAndBall
- judgeVictory 함수 추가
- printRemainTryCount 함수 추가
- printRandomNumberArray 함수 추가
- randomNumberArray -> 전역변수에서 지역변수로
- strikeCount, ballCount -> 전역변수에서 지역변수로
- checkStrikeAndBall parameter, return값(Array<Int>) 추가
- "임의의 수:" <- 출력문 수정
@jylim72 jylim72 closed this Aug 19, 2022
@bar-d bar-d reopened this Aug 19, 2022
@bar-d

bar-d commented Aug 19, 2022

Copy link
Copy Markdown

고생하셨습니다~

@bar-d
bar-d merged commit 0ce08bc into yagom-academy:ic_7_lj777 Aug 19, 2022
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.

3 participants