V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Akiyu
V2EX  ›  English

在 go 官方文档中看到的一句话

  •  
  •   Akiyu · 2019-12-12 18:11:14 +08:00 · 2204 次点击
    这是一个创建于 1590 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原地址 : https://golang.org/ref/mem
    在其中的 advice 中 :

    If you must read the rest of this document to understand the behavior of your program, you are being too clever.
    Don't be clever.
    

    这个是啥意思呢?

    13 条回复    2019-12-12 20:31:52 +08:00
    AndrewGhost
        1
    AndrewGhost  
       2019-12-12 18:16:38 +08:00
    Don’t be clever, 不要自作聪明。
    gstqc
        2
    gstqc  
       2019-12-12 18:17:44 +08:00 via Android
    tl, dr 的加强版
    ClericPy
        3
    ClericPy  
       2019-12-12 18:17:57 +08:00
    考 4 级时候遇到过

    It's not a good thing to be too clever.

    不过似乎语境不一样, 帮顶
    ClericPy
        4
    ClericPy  
       2019-12-12 18:22:27 +08:00
    点到文档看了下, 没有其他意思, 就是不建议看剩下的文档, 新手不要轻易尝试 memory operations, 用现成的 channel 或者 sync
    shintendo
        5
    shintendo  
       2019-12-12 18:23:48 +08:00
    我觉得 too clever 不是说你读文档,而是说你的程序。
    如果你的程序需要读完下面的文档才能理解,那么你的程序写得 too clever 了(类似奇技淫巧的意思?)。
    没学过 go,纯猜想
    orzorzorzorz
        6
    orzorzorzorz  
       2019-12-12 18:24:03 +08:00
    看上去像是嘲讽啊...别看,看就秃了。
    Akiyu
        7
    Akiyu  
    OP
       2019-12-12 18:27:37 +08:00
    感觉有三种含义:
    1. 比较嘲讽的那种, 如果把所有文档看完才明白, 那就"太聪明"了.
    不过一个官方文档应该不会这么做

    2. 作者不太建议一定要看完所有, 类似于 "好读书不求甚解", 理解为重, 不要全部看完
    就是建议不要太死板, 自作聪明

    3. 就是 @ClericPy 说的, 新手老老实实就行
    lhx2008
        8
    lhx2008  
       2019-12-12 18:30:43 +08:00 via Android
    手机打不开,我猜是理解抽象的接口就可以了,没有必要用底层实现的东西。这也没有错,你会写,你的同事不会,协作就成问题
    dbw9580
        9
    dbw9580  
       2019-12-12 18:30:49 +08:00 via Android
    文档是关于 go routine 不做同步也一定能够保证并发安全的几个条件。
    下面几句话叫你用 channel/sync atomic 做显式同步,而不要依赖这个文档里描述的条件而不做同步。
    WilsonGGG
        10
    WilsonGGG  
       2019-12-12 18:32:10 +08:00
    实践指导理论,先干了再说
    catror
        11
    catror  
       2019-12-12 19:29:28 +08:00 via Android
    翻译:
    如果你一定要读这篇文档才能确定你的程序行为,那么你一定是自作聪明了(隐含意:程序行为依赖于这篇文档中描述的行为,不建议这么做)。
    别自作聪明。
    lance6716
        12
    lance6716  
       2019-12-12 20:13:08 +08:00 via Android
    用简单、明显的 sync,不要了解 go 内部的这些难懂难用的 happens before
    Vegetable
        13
    Vegetable  
       2019-12-12 20:31:52 +08:00
    实际上是说,不要尝试通过过于底层的 api 去操作内存.

    Advice
    Programs that modify data being simultaneously accessed by multiple goroutines must serialize such access.

    To serialize access, protect the data with channel operations or other synchronization primitives such as those in the sync and sync/atomic packages.

    If you must read the rest of this document to understand the behavior of your program, you are being too clever.

    Don't be clever.

    忠告

    修改由多个 goroutine 同时访问的数据的程序必须序列化此类访问。

    要序列化访问,请使用通道操作或其他同步原语(例如 sync 和 sync / atomic 包中的原语)保护数据。

    如果您必须阅读本文档的其余部分以了解程序的行为,那么您就太聪明了。

    别聪明
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   854 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 315ms · UTC 21:39 · PVG 05:39 · LAX 14:39 · JFK 17:39
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.