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 天內回覆