Reconsider the use of 2 in conversion function names
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 63/100
- Issue 类型
- 文档
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- matlab
调研方向
先查看仓库的 MATLAB 编码指南,并找到 issue 中引用的“Function name style”部分。审查现有建议和提出的替代方案,然后在维护者接受更改后更新指南。完成标准是:转换命名建议反映该决定,并与相关的风格指南保持一致。
由索引模型根据 Issue 内容生成。
描述
The MATLAB coding guidelines currently state the following under Function name style:
Name functions and methods using a verb or verb phrase to convey the action performed. Alternatively, name functions and methods using a noun or noun phrase if the noun describes the thing being created. Use the numeral "2" in the name of a conversion function. Use the prefix "is" or "has" for a function whose primary output is a logical value. Use complementary names for functions with complementary operations (e.g., start/stop, create/destroy, etc.).
I would like to suggest reconsidering the recommendation to use the numeral 2 in conversion function names.
The type2type convention feels dated and, more importantly, can reduce readability. Using 2 as a substitute for "to" makes names less natural to read and becomes particularly awkward when the type names themselves contain numbers. For example, consider:
myByte = uint82byte(myUint8);
versus:
myByte = uint8ToByte(myUint8);
or:
myByte = byteFromUint8(myUint8);
I find the last form the clearest because it reads naturally as "byte from uint8" and makes the direction of the conversion immediately apparent.
This convention also maps naturally to an object-oriented API. For example, the same operation could conceptually be expressed as:
myByte = Byte.FromUint8(myUint8);
The standalone function name byteFromUint8 follows directly from that same naming pattern.
Beyond aesthetics, avoiding 2 would also eliminate potentially confusing names such as uint82byte, where the 8 belongs to the source type and the 2 represents the word "to".
My suggestion is therefore to reconsider the requirement to use 2 for conversion functions and instead recommend descriptive conversion names such as:
- targetFromSource, e.g. byteFromUint8
- sourceToTarget, e.g. uint8ToByte
Of the two, I would favor targetFromSource because it emphasizes what the function produces and reads naturally at the call site.
- 主要语言
- 没有语言数据
- 星标
- 143
- 派生
- 11
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mathworks/MATLAB-Coding-Guidelines 的其他 Issue
-
linking issue可能重新可做 @dgarriso 于 181 天前认领,目前没有进行中的 PR。 未关闭bug
mathworks/MATLAB-Coding-Guidelines#5 · 1 条评论 · 已指派 1 人 ·
-
难度 5/5 一周以上 新手友好度 35/100
mathworks/MATLAB-Coding-Guidelines#3 · 1 条评论 ·
查看 mathworks/MATLAB-Coding-Guidelines 的全部 Issue
相似的 Issue
-
idea-scout idea:414
难度 2/5 1-3 小时 新手友好度 84/100
jeanibarz/agent-notebook#414 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
-
README demo: offer a controlled video variant next to the GIF for reduced motion and mobile data未关闭accessibility
难度 2/5 1-3 小时 新手友好度 76/100
onetechgroupll/eigen-beam#26 ·
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 76/100
维护者通常 2 天内回复
-
documentation help wanted
难度 2/5 半天 新手友好度 82/100
akshaysharma1088/dataranger#32 ·
维护者通常 1 天内回复