Skip to content

Commit

Permalink
Update 2024-04-29-code-study-interface-idiomspatterns-in-zig-standard…
Browse files Browse the repository at this point in the history
…-libraries.md
  • Loading branch information
fwx5618177 authored May 25, 2024
1 parent 256964e commit ce69826
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Zig 标准库应用了一些代码习语或模式以达到类似效果。
这里有一些显著的不同:

- Go 的接口与它们抽象的类型/实例是独立的。当观察到不同类型之间的公共 API/方法模式时,可以随时添加新接口。
不需要回过头去更改类型以实现新接口,这是 Java 所必需的
无需像在 Java 中那样回过头去修改类型以实现新的接口
- Go 的接口只包含用于动态分派的 `vtab`,并且偏好小型方法集/`vtable`,例如 `io.Reader``io.Writer`
只有一个方法。常见的工具函数如`io.Copy``CopyN``ReadFull``ReadAtLeast` 等,作为包函数提供,
使用这些小接口。与之相比,Zig 的接口,如 `std.mem.Allocator`,通常包含 `vtable` 和作为方法的常用工具;
Expand Down

0 comments on commit ce69826

Please sign in to comment.