gitalk icon indicating copy to clipboard operation
gitalk copied to clipboard

你知道吗?Go新增加了三个内建函数

Open utterances-bot opened this issue 2 years ago • 2 comments

你知道吗?Go新增加了三个内建函数

Go 1.21中新增加了三个内建的函数,相比以前的len、cap、delete、append、close、panic等函数,又有了新的变化,让我们一起来看看吧。

https://colobu.com/2023/05/28/go1-21-whats-new-builtin/

utterances-bot avatar May 30 '23 02:05 utterances-bot

很好用,可以不用自己实现了

fengqi avatar May 30 '23 02:05 fengqi

既然范型正式进入标准库,个人感觉 minmax 作为内建函数,不如做成工具类函数比如:math.Min math.Max,或者为了 Go1 兼容性换个别的名字。

有以下两点:

  1. min max 应该是程序员编程中常用的局部变量名,用 min max 时 IDE 就会提示警告,同时也会在当前代码块中覆盖掉 min max 这俩内建函数。
  2. min max 这种函数不同于 append delete 一样与 Go 语言特性强相关(slice map 类型),如果这种需求都要用内建函数解决,那以后会不会出现更多诸如此类的内建函数。

xmx avatar Jun 03 '23 16:06 xmx