编程笔记

lifelong learning & practice makes perfect

本文讨论了 Go 语言中 `[]Item` 类型的参数如何传递给函数,阐明了是使用副本还是指向同一数据的指针。当一个 `[]Item` 切片传递给函数时,切片的头部信息(包含指针、长度和容量)会被复制,但底层数组不会。这意味着在函数内部修改切片的元素会影响原始切片,因为它们共享同一个底层数组。但是,如果函数追加元素时超过了切片的容量,将会创建一个新的底层数组,而原始切片保持不变。文章提供示例代码来演示这些概念,展示了元素修改和在容量范围内追加如何影响原始切片,而超出容量的追加则不会。总结建议在将切片传递给函数时要小心,并建议创建切片副本以避免修改原始切片。This Go article discusses how `[]Item` type parameters are passed to functions, clarifying whether a copy or a pointer to the same data is used. When a `[]Item` slice is passed to a function, the slice header (containing a pointer, length, and capacity) is copied, but the underlying array is not. This means modifications to the slice's elements within the function will affect the original slice because they share the same underlying array. However, if the function appends elements exceeding the slice's capacity, a new underlying array is created, and the original slice remains unchanged. The article provides example code to demonstrate these concepts, showing how element modification and appending within capacity affect the original slice, while appending beyond capacity does not. It concludes by advising caution when passing slices to functions and suggests creating a slice copy if modifications are to be avoided.

阅读全文 »

手慢无,免费领Perplexity年卡会员 网址:https://www.perplexity.ai/join/p/redeem

验证码:PPLXLIUMBLHOTVAJ2QI

记得用美国的节点。

免费领AI搜索鼻祖perplexity的年卡会员,价值200美刀。

推荐订阅

推荐并获得专业版$10的折扣,推荐给一个朋友,你们俩都可以获得折扣。赠送$10,得到$10。
每推荐一位订阅者,你的下一个计费周期可以减免$10,他们也可以减免$10。你可以推荐尽可能多的人,折扣会在每个计费周期内自动获取一次。

This Go blog post discusses the history and reasons behind the Go team's decision to stop pursuing syntactic language changes for error handling.Go 语言的错误处理,与众不同,报错会单独返回一个值,这导致代码冗余。多年来,使用者一直要求有更好的写法,Go 团队想了很多办法,效果都不好。现在,官方终于宣布,不再寻求更好的写法,保持现状。

阅读全文 »

NLWeb creates a standard protocol that turns any website into a conversational interface that both humans and AI agents can query naturally. It leverages Schema.org structured data and includes built-in support for MCP.NLWeb 是微软新提出的一个接口协议,类似于 MCP 协议,是网站跟 AI 大模型的对话协议,方便大模型从网站获取数据。本文是这个协议的简介。

阅读全文 »

了解如何使用 Cline 规则为 Cline 提供系统级指导,确保一致的行为、项目特定标准,并在您的项目中维护机构知识。

阅读全文 »