-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,017 additions
and
218 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1053,4 +1053,3 @@ fs 0x0 | |
gs 0x0 | ||
exit status 2 | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,8 +103,8 @@ Changed User Email To [email protected] | |
|
||
아래 예제들은 실제 Go의 표준 라이브러리에서 사용하는 코드들이다. 이들을 공부해보면, 값에 의한 호출과 참조에 의한 호출\(pointer semantic\) 중 하나를 일관되게 사용하는 것이 얼마나 중요한지 알 수 있다. 따라서 변수의 타입을 정할 때, 다음의 질문에 스스로 답해보자. | ||
|
||
* 이 타입은 값에 의한 호출과 참조에 의한 호출 중 어느 것이 더 적합한가? | ||
* 만약 이 변수의 값을 변경해야 한다면, 새로운 값을 가지는 복사본을 만드는 것과, 다른 곳에서도 이 변경된 값을 확인할 수 있게 이 변수의 값을 직접 변경하는 것 중 어느 것이 더 적합한가? | ||
- 이 타입은 값에 의한 호출과 참조에 의한 호출 중 어느 것이 더 적합한가? | ||
- 만약 이 변수의 값을 변경해야 한다면, 새로운 값을 가지는 복사본을 만드는 것과, 다른 곳에서도 이 변경된 값을 확인할 수 있게 이 변수의 값을 직접 변경하는 것 중 어느 것이 더 적합한가? | ||
|
||
가장 중요한 것은 일관성이다. 처음에 한 결정이 잘못되었다고 판단되면, 그때 이를 변경하면 된다. | ||
|
||
|
@@ -462,10 +462,10 @@ p := pipe{"cfg_service"} | |
|
||
`iTable`은 다음의 두 가지를 제공한다: | ||
|
||
* 첫 번째 부분은 저장된 데이터의 타입을 나타낸다. 이 예제에서는 `file` 타입을 말한다. | ||
* 두 번째 부분은 함수 포인터의 모체로서, 인터페이스를 통해 메서드를 호출할 때 정확한 메서드를 호출하기 위하여 사용된다. | ||
- 첫 번째 부분은 저장된 데이터의 타입을 나타낸다. 이 예제에서는 `file` 타입을 말한다. | ||
- 두 번째 부분은 함수 포인터의 모체로서, 인터페이스를 통해 메서드를 호출할 때 정확한 메서드를 호출하기 위하여 사용된다. | ||
|
||
 | ||
 | ||
|
||
인터페이스를 통해서 `read`를 호출하면, `iTable`을 확인해서 이 타입에 맞는 `read` 함수를 찾고 이를 호출한다. 결과적으로 구체적 타입의 `read` 메서드를 호출하는 것이다. | ||
|
||
|
@@ -475,7 +475,7 @@ retrieve(f) | |
|
||
`p`도 이와 동일하다. `reader` 인터페이스의 첫 번째 워드는 `pipe` 타입을 가리키고, 두번째 워드는 `p`의 복사본을 가리킨다. | ||
|
||
 | ||
 | ||
|
||
데이터가 변경되었기 때문에, 동작도 다르다. | ||
|
||
|
@@ -575,8 +575,8 @@ u := user{"Hoanh", "[email protected]"} | |
|
||
다음은 그 규칙들이다. | ||
|
||
* 주어진 타입 T의 어떤 값에 대해, 값 리시버로 구현한 메서드들만이 이 타입의 메서드 집합에 속한다. | ||
* 주어진 타입 \*T \(타입 T의 포인터\)의 어떤 값에 대해, 값 리시버와 포인터 리시버를 사용하는 모든 메서드들이 이 타입의 메서드 집합에 속한다. | ||
- 주어진 타입 T의 어떤 값에 대해, 값 리시버로 구현한 메서드들만이 이 타입의 메서드 집합에 속한다. | ||
- 주어진 타입 \*T \(타입 T의 포인터\)의 어떤 값에 대해, 값 리시버와 포인터 리시버를 사용하는 모든 메서드들이 이 타입의 메서드 집합에 속한다. | ||
|
||
즉, 어떤 타입의 포인터를 사용한다면 선언된 모든 메서드들은 모두 이 포인터를 통해 사용이 가능하다. 만약 어떤 타입의 값을 사용한다면 값에 의한 호출을 사용하는 메서드들만이 사용이 가능하다. | ||
|
||
|
@@ -602,8 +602,8 @@ func (d *duration) notify() { | |
|
||
`42`를 받아서, 이를 `duration` 타입으로 변경 후 `notify` 메서드를 호출해보자. 이때, 컴파일러는 다음과 같은 에러 메시지를 보여준다. | ||
|
||
* "cannot call pointer method on duration\(42\)" | ||
* "cannot take the address of duration\(42\)" | ||
- "cannot call pointer method on duration\(42\)" | ||
- "cannot take the address of duration\(42\)" | ||
|
||
```go | ||
duration(42).notify() | ||
|
@@ -619,7 +619,7 @@ duration(42).notify() | |
|
||
이 문제를 해결하기 위해서는, `u` 대신 `u`의 주소 값\(&u\)를 전달해야 한다. `user`의 값을 만들고 이 값의 주소 값을 전달하면, 인터페이스는 `user` 타입의 주소 값을 가지게 되고 원본 값을 가리킬 수 있게 된다. | ||
|
||
 | ||
 | ||
|
||
```go | ||
sendNotification(&u) | ||
|
@@ -688,4 +688,3 @@ for _, e := range entities { | |
My name is Hoanh and my email is [email protected] | ||
My name is Hoanh An and my email is [email protected] | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.