The Go Programming Language
› http://golang.org/
› Go Playground
Go Projects
› Revel Web Framework
Jooooooooo

Go 终于要搞泛型了 (1.18 版本)

  •  
  •   Jooooooooo · Oct 28, 2021 · 5857 views
    This topic created in 1834 days ago, the information mentioned may be changed or developed.

    groups.google.com/g/golang-dev/c/iuB22_G9Kbo/m/7B1jd1I3BQAJ

    "Go 1.18 will include support for generics."

    26 replies  •  2021-10-29 08:44:31 +08:00
    iyear
    iyear
    Oct 28, 2021
    1
    kiripeng
    kiripeng
    Oct 28, 2021
    2
    是啊,不过确实火星了
    Jooooooooo
    Jooooooooo
    OP
    Oct 28, 2021
    3
    @iyear 不一样吧, 看那个 thread 还在讨论要不要加. 这里说是确定要加了.
    iyear
    iyear
    Oct 28, 2021
    4
    @Jooooooooo #3 没细看😂
    shyrock
    shyrock
    Oct 28, 2021
    5
    没泛型有啥干不了的吗?
    Jooooooooo
    Jooooooooo
    OP
    Oct 28, 2021
    6
    这里面提到一点蛮有意思的, 说因为大家都没用过 go 的泛型, 所以官方文档也没法给出特别好的最佳实践.

    we can't provide anything as prescriptive about style and best practices. We simply don't know them yet.
    SmiteChow
    SmiteChow
    Oct 28, 2021
    7
    @shyrock 都能干,只是要多干猛干
    kidlj
    kidlj
    Oct 28, 2021
    8
    范型意味着多了一种抽象方式,写大型代码更简单了(抽象的角度),阅读大型代码更困难了(理解抽象)。
    defage
    defage
    Oct 28, 2021
    9
    希望不要弄个假泛型或者半吊子泛。
    janxin
    janxin
    Oct 28, 2021
    10
    @defage 什么样子是假泛型?
    aababc
    aababc
    Oct 28, 2021
    11
    @janxin 感觉好像在说 JAVA
    darknoll
    darknoll
    Oct 28, 2021
    12
    @defage 举个例子
    CodeCodeStudy
    CodeCodeStudy
    Oct 28, 2021
    13
    Go 语言之父:不要在 Go 1.18 标准库中使用泛型
    https://www.oschina.net/news/164554/do-not-change-the-libraries-in-1-18
    Leviathann
    Leviathann
    Oct 28, 2021❤️1
    14
    @darknoll 这个提法一般特指 java 的泛型擦除且类型系统表达力很弱
    因为同样是擦除的 typescript 和 Haskell 好像没人说它们是假泛型🐶
    Jooooooooo
    Jooooooooo
    OP
    Oct 28, 2021
    15
    @CodeCodeStudy 旧新闻了, 我发的这个是新的. 今天出的.
    wingoo
    wingoo
    Oct 28, 2021
    16
    1.18 很早就计划上泛型的, 这个讨论只是说 1.18 的版本不会把 go 的内部库改成泛型版本, 等大家都在使用了, 有了实践之后再修改
    INCerry
    INCerry
    Oct 28, 2021
    17
    要泛型?那大家来用 C#吧
    iamzuoxinyu
    iamzuoxinyu
    Oct 28, 2021❤️1
    18
    @janxin 通俗来说,**编译时**进行类型展开的做法是真泛型,**运行时**把类型退化到 top type 叫做假泛型。
    sagaxu
    sagaxu
    Oct 28, 2021 via Android❤️3
    19
    岂不违背大道至简原则?
    EscYezi
    EscYezi
    Oct 28, 2021 via iPhone
    20
    @shyrock #5 没有泛型就少了很多好用的工具类库。比如 java 里大量的集合操作类。
    SingeeKing
    SingeeKing
    Oct 28, 2021
    21
    告诉你个秘密,Go 1.17 已经可以通过 flag 开启范型了(只不过不能 export )
    24bit
    24bit
    Oct 28, 2021
    22
    https://go.googlesource.com/proposal/+/refs/heads/master/design/43651-type-parameters.md

    ```
    This is the design for adding generic programming using type parameters to the Go language. This design has been proposed and accepted as a future language change. We currently expect that this change will be available in the Go 1.18 release in early 2022.
    ```
    BeautifulSoap
    BeautifulSoap
    Oct 28, 2021
    23
    靠来晚了,被楼上老哥抢先了。偷偷跟你们说个秘密,go 1.17 就支持泛型了。编译的时候加上-gcflags=-G=3 这个 flag 就能编译有范型的代码了
    QingXuJiaZhi
    QingXuJiaZhi
    Oct 28, 2021
    24
    @sagaxu golang 官方应该没有提出过这个原则吧,网友戏言岂可当真。
    SorcererXW
    SorcererXW
    Oct 29, 2021
    25
    @cmdOptionKana

    Less is exponentially more -- Rob Pike
    defage
    defage
    Oct 29, 2021
    26
    @janxin 请看 Java
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1563 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 23:37 · PVG 07:37 · LAX 15:37 · JFK 18:37
    ♥ Do have faith in what you're doing.