Skip to content

ch6-06 译注 get it wrong #65

@AntonioSun

Description

@AntonioSun

当然,我们也可以把IntSet定义为一个slice类型,但这样我们就需要把代码中所有方法里用到的s.words用*s替换掉了:

type IntSet []uint64

尽管这个版本的IntSet在本质上是一样的,但它也允许其它包中可以直接读取并编辑这个slice。换句话说,相对于*s这个表达式会出现在所有的包中,s.words只需要在定义IntSet的包中出现(译注:所以还是推荐后者吧的意思)。

Here is the original text:

Although this version of IntSet would be ess ent ial ly equivalent, it wou ld allow clients from
ot her packages to read and modif y the slice direc tly. Put another way, where as the expression
*s could be used in any package, s.words may appear only in the package that defines
IntSet.

Note the two key works, "could be used" and "may appear only", it emphasizes that the later is too relaxed that the en-capsulized info is leaked out and could be directly accessed anywhere.

Thus, it is not "还是推荐后者吧" but just the opposite.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions