Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Generic proposal in Go

Generic proposal in Go

By Joel

Buzzvil

June 30, 2021
Tweet

More Decks by Buzzvil

Other Decks in Programming

Transcript

  1. Copyright ⓒ All Right Reserved by Buzzvil Golang Generic Proposal

    톺아보기 ProdOps Team Joel Lim 2021.06.30
  2. Copyright ⓒ All Right Reserved by Buzzvil Generic이란? 데이터 형식에

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

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

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

    없이 어떻게 했을까? 혼자서도 잘해요 - generic 없이 generic 쓰기 - https://appliedgo.net/generics/
  6. Copyright ⓒ All Right Reserved by Buzzvil 1. 꼭 써야

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

    사용 with empty interface https://appliedgo.net/generics/
  8. Copyright ⓒ All Right Reserved by Buzzvil Generic 없이도 살만하지만…

    뭔가 2% 부족하다... https://appliedgo.net/generics/
  9. Copyright ⓒ All Right Reserved by Buzzvil https://blog.golang.org/survey2020-results 그래서 모두가

    원하고 있던 Generic https://jaxenter.com/golang-dev-survey-171243.html
  10. Copyright ⓒ All Right Reserved by Buzzvil Type parameters Type

    parameter T: parameter name any: constraints - * any = all type
  11. 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.
  12. Copyright ⓒ All Right Reserved by Buzzvil Generic types generic

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

    있는 것들 https://blog.golang.org/why-generics
  14. Copyright ⓒ All Right Reserved by Buzzvil 디자인의 문제점 -

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

    Identifying the matched predeclared type https://blog.golang.org/why-generics
  16. 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