<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          C++核心準則ES.8:避免看起來差不多的名稱?

          共 1410字,需瀏覽 3分鐘

           ·

          2020-04-19 23:21

          12259f31e79de4b630e5757dd15ce993.webp

          ES.8: Avoid similar-looking names

          ES.8:避免看起來差不多的名稱


          Reason(原因)

          Code clarity and readability. Too-similar names slow down combiiaoprehension and increase the likelihood of error.

          代碼整潔性和可讀性。過于相似的名稱會減緩理解進程并增加出錯的可能性。


          Example, bad(反面示例)


          if (readable(i1 + l1 + ol + o1 + o0 + ol + o1 + I0 + l0)) surprise();
          Example, bad(反面示例)

          Do not declare a non-type with the same name as a type in the same scope. This removes the need to disambiguate with a keyword such as?struct?or?enum. It also removes a source of errors, as?struct X?can implicitly declare?X?if lookup fails.

          不要用一個名稱定義類型之后,在同一個作用域中又使用這個名稱定義非類型。這種做法使消除名稱和像struct或enum那樣的關鍵詞之間的歧義不再必要。同時也減少了一個錯誤的源頭,例如如果名稱檢索失敗,struct X可以隱性聲明X類型。

          struct foo { int n; };
          struct foo foo(); // BAD, foo is a type already in scope
          struct foo x = foo(); // requires disambiguation
          Exception(例外)

          Antique header files might declare non-types and types with the same name in the same scope.

          特別早期的頭文件可能會使用同一個名稱聲明類型和非類型。


          Enforcement(實施建議)

          • Check names against a list of known confusing letter and digit combinations.

          • 使用一個已知的容易混淆的字母和數(shù)字的列表檢查名稱。

          • Flag a declaration of a variable, function, or enumerator that hides a class or enumeration declared in the same scope.

          • 標記同一作用域中可能隱藏類或枚舉類型聲明的變量、函數(shù)、枚舉類型的聲明。


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es8-avoid-similar-looking-names




          覺得本文有幫助?請分享給更多人。

          關注微信公眾號【面向對象思考】輕松學習每一天!

          面向對象開發(fā),面向對象思考!


          瀏覽 38
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  一级黄色录像免费看 | 婷婷国产精品久久久 | 中字三级视频网站在线观看 | 高清在线免费观看亚洲视频 | 看片地址|