Reconsider the use of 2 in conversion function names

未關閉 適合新手
#7 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
63/100
Issue 類型
文件
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
matlab
領域
documentation

研究方向

先查看儲存庫的 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,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

mathworks/MATLAB-Coding-Guidelines 的其他 Issue

查看 mathworks/MATLAB-Coding-Guidelines 的全部 Issue

相似的 Issue

更多 Documentation Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。