Slide 1

Slide 1 text

Copyright ⓒ All Right Reserved by Buzzvil Golang Generic Proposal 톺아보기 ProdOps Team Joel Lim 2021.06.30

Slide 2

Slide 2 text

Copyright ⓒ All Right Reserved by Buzzvil 원래 주제

Slide 3

Slide 3 text

Copyright ⓒ All Right Reserved by Buzzvil 원래 주제

Slide 4

Slide 4 text

Copyright ⓒ All Right Reserved by Buzzvil But... 응 이 미 했 어 ~

Slide 5

Slide 5 text

Copyright ⓒ All Right Reserved by Buzzvil Go Scheduling

Slide 6

Slide 6 text

Copyright ⓒ All Right Reserved by Buzzvil But... ㅎㅎ ㅈㅅ

Slide 7

Slide 7 text

Copyright ⓒ All Right Reserved by Buzzvil 그래서 오늘 주제는?

Slide 8

Slide 8 text

Copyright ⓒ All Right Reserved by Buzzvil 그래서 오늘 주제는? Golang Generic proposal 톺아보기

Slide 9

Slide 9 text

Copyright ⓒ All Right Reserved by Buzzvil Generic이란? 데이터 형식에 의존하지 않고, 하나의 값이 여러 다른 데이터 타입들을 가질 수 있는 기술에 중점을 두어 재사용성을 높일 수 있는 프로그래밍 방식

Slide 10

Slide 10 text

Copyright ⓒ All Right Reserved by Buzzvil Generic이란? e.g. Java C++

Slide 11

Slide 11 text

Copyright ⓒ All Right Reserved by Buzzvil 하지만 Go에는 generic이 없다... https://appliedgo.net/generics/

Slide 12

Slide 12 text

Copyright ⓒ All Right Reserved by Buzzvil If Generic existed... * 물론 sort.Sort()를 사용하면 generic처럼 사용할 수 있습니다

Slide 13

Slide 13 text

Copyright ⓒ All Right Reserved by Buzzvil 왜 Go는 Generic이 없나요? 언어를 단순하게 만들고 싶어서 뺐다. 복잡한 건 Go와 맞지 않다

Slide 14

Slide 14 text

Copyright ⓒ All Right Reserved by Buzzvil 그럼 그동안은 Generic 없이 어떻게 했을까? 혼자서도 잘해요 - generic 없이 generic 쓰기 - https://appliedgo.net/generics/

Slide 15

Slide 15 text

Copyright ⓒ All Right Reserved by Buzzvil 1. 꼭 써야 하니? - 요구사항 검토 Go에는 Go에 맞는 방법이 있다. 문제를 Composition이나 embeding으로 해결할 순 없는지 한번 더 고려해보자

Slide 16

Slide 16 text

Copyright ⓒ All Right Reserved by Buzzvil 2. 코드복붙 https://appliedgo.net/generics/

Slide 17

Slide 17 text

Copyright ⓒ All Right Reserved by Buzzvil 3. 인터페이스 사용 - 가장 권장하는 방식

Slide 18

Slide 18 text

Copyright ⓒ All Right Reserved by Buzzvil 4. type assertion 사용 with empty interface https://appliedgo.net/generics/

Slide 19

Slide 19 text

Copyright ⓒ All Right Reserved by Buzzvil 5. reflection을 사용 https://appliedgo.net/generics/

Slide 20

Slide 20 text

Copyright ⓒ All Right Reserved by Buzzvil Generic 없이도 살만하지만… 뭔가 2% 부족하다... https://appliedgo.net/generics/

Slide 21

Slide 21 text

Copyright ⓒ All Right Reserved by Buzzvil https://blog.golang.org/survey2020-results 그래서 모두가 원하고 있던 Generic https://jaxenter.com/golang-dev-survey-171243.html

Slide 22

Slide 22 text

Copyright ⓒ All Right Reserved by Buzzvil 그리고 바야흐로 2021년 1월 13일..

Slide 23

Slide 23 text

Copyright ⓒ All Right Reserved by Buzzvil 드디어!! 🎉

Slide 24

Slide 24 text

Copyright ⓒ All Right Reserved by Buzzvil 드디어!! 🎉

Slide 25

Slide 25 text

Copyright ⓒ All Right Reserved by Buzzvil 본격적으로 알아보기 - Detail Proposal Document

Slide 26

Slide 26 text

Copyright ⓒ All Right Reserved by Buzzvil Type parameters

Slide 27

Slide 27 text

Copyright ⓒ All Right Reserved by Buzzvil Type parameters Type parameter T: parameter name any: constraints - * any = all type

Slide 28

Slide 28 text

Copyright ⓒ All Right Reserved by Buzzvil Constraints ?

Slide 29

Slide 29 text

Copyright ⓒ All Right Reserved by Buzzvil Constraints ❌ This might seem OK at first glance, but in this example v has type T, and T can be any type. This means that T need not have a String method. So the call to v.String() is invalid.

Slide 30

Slide 30 text

Copyright ⓒ All Right Reserved by Buzzvil Constraints

Slide 31

Slide 31 text

Copyright ⓒ All Right Reserved by Buzzvil Defining constraints - using interface

Slide 32

Slide 32 text

Copyright ⓒ All Right Reserved by Buzzvil Defining constraints

Slide 33

Slide 33 text

Copyright ⓒ All Right Reserved by Buzzvil Defining constraints any type은 사실 ==

Slide 34

Slide 34 text

Copyright ⓒ All Right Reserved by Buzzvil Generic types

Slide 35

Slide 35 text

Copyright ⓒ All Right Reserved by Buzzvil Generic types generic type은 메서드를 가질 수 있음 generic type은 자신을 참조할 수 있음 단, 자신을 참조할때 type parameter의 순서는 같아야함

Slide 36

Slide 36 text

Copyright ⓒ All Right Reserved by Buzzvil Generic types

Slide 37

Slide 37 text

Copyright ⓒ All Right Reserved by Buzzvil Operators

Slide 38

Slide 38 text

Copyright ⓒ All Right Reserved by Buzzvil Operators

Slide 39

Slide 39 text

Copyright ⓒ All Right Reserved by Buzzvil Operators

Slide 40

Slide 40 text

Copyright ⓒ All Right Reserved by Buzzvil Type inference

Slide 41

Slide 41 text

Copyright ⓒ All Right Reserved by Buzzvil Generic으로 할 수 있는 것들. 예제1 - FP

Slide 42

Slide 42 text

Copyright ⓒ All Right Reserved by Buzzvil Generic으로 할 수 있는 것들. 예제2 - Map Keys

Slide 43

Slide 43 text

Copyright ⓒ All Right Reserved by Buzzvil 그 외 할수 있는 것들 https://blog.golang.org/why-generics

Slide 44

Slide 44 text

Copyright ⓒ All Right Reserved by Buzzvil 디자인의 문제점 - zero value https://blog.golang.org/why-generics

Slide 45

Slide 45 text

Copyright ⓒ All Right Reserved by Buzzvil 디자인의 문제점 - Identifying the matched predeclared type https://blog.golang.org/why-generics

Slide 46

Slide 46 text

Copyright ⓒ All Right Reserved by Buzzvil 요약 https://blog.golang.org/why-generics

Slide 47

Slide 47 text

Copyright ⓒ All Right Reserved by Buzzvil 참고 https://blog.golang.org/why-generics [1] Generic proposal, Ian Lance Taylor, https://github.com/golang/go/issues/43651 [2] Proposal detail, Ian Lance Taylor, https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md [3] Who needs generics?, Christoph Berger, , https://appliedgo.net/ [4] Why generics?, Oracle, https://blog.golang.org/why-generics [5] Go generic 왜 없었고, 왜 생겼고, 무엇이 달라질까?, 김형준, https://github.com/golangkorea/gophercon-talks/blob/master/slides/202102/go-generic-why-wasn't-it-why-did-it-m ake-what-is-the-different.pdf

Slide 48

Slide 48 text

Copyright ⓒ All Right Reserved by Buzzvil Thank you ProdOps Team Joel Lim 2021.06.30