<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++核心準(zhǔn)則?NL.5:避免在名稱中包含類型信息

          NL.5: Avoid encoding type information in names

          NL.5:避免在名稱中包含類型信息


          Rationale(基本原理)

          If names reflect types rather than functionality, it becomes hard to change the types used to provide that functionality. Also, if the type of a variable is changed, code using it will have to be modified. Minimize unintentional conversions.

          如果名稱反映類型而不是功能,則很難更改用于提供該功能的類型。同樣,如果更改了變量的類型,則必須修改使用該變量的代碼。最小化意外轉(zhuǎn)換。


          Example, bad(反面示例)

          void print_int(int i);
          void print_string(const char*);

          print_int(1); // repetitive, manual type matching
          print_string("xyzzy"); // repetitive, manual type matching
          Example, good(范例)
          void print(int i);
          void print(string_view); // also works on any string-like sequence

          print(1); // clear, automatic type matching
          print("xyzzy"); // clear, automatic type matching
          Note(注意)

          Names with types encoded are either verbose or cryptic.

          包含類型的名稱是冗長的或隱秘的。

          printS  // print a std::string
          prints // print a C-style string
          printi // print an int

          Requiring techniques like Hungarian notation to encode a type has been used in untyped languages, but is generally unnecessary and actively harmful in a strongly statically-typed language like C++, because the annotations get out of date (the warts are just like comments and rot just like them) and they interfere with good use of the language (use the same name and overload resolution instead).

          在非類型化語言中已經(jīng)使用了像匈牙利命名方法這樣的技術(shù)在變量名中包含類型,但是在像C ++這樣的強靜態(tài)類型化語言中,這通常是不必要的甚至是有害的,因為注釋已經(jīng)過時了(注釋就像疣一樣,也會像它們一樣腐爛),并且會干擾語言的良好使用(改用相同的名稱并使用重載方式)。


          Note(注意)

          Some styles use very general (not type-specific) prefixes to denote the general use of a variable.

          一些樣式使用非常通用的(不是特定于類型的)前綴來表示變量的通用用法。

          auto p = new User();
          auto p = make_unique();
          // note: "p" is not being used to say "raw pointer to type User,"
          // just generally to say "this is an indirection"

          auto cntHits = calc_total_of_hits(/*...*/);
          // note: "cnt" is not being used to encode a type,
          // just generally to say "this is a count of something"

          This is not harmful and does not fall under this guideline because it does not encode type information.

          這是無害的,并且不受該準(zhǔn)則約束,因為它表達的不是類型信息。


          Note(注意)

          Some styles distinguish members from local variable, and/or from global variable.

          一些風(fēng)格將成員與局部變量和/或全局變量區(qū)分開。

          struct S {
          int m_;
          S(int m) : m_{abs(m)} { }
          };

          This is not harmful and does not fall under this guideline because it does not encode type information.

          這是無害的,不受該準(zhǔn)則約束,因為它沒有表達類型信息。


          Note(注意)

          Like C++, some styles distinguish types from non-types. For example, by capitalizing type names, but not the names of functions and variables.

          像C ++一樣,某些風(fēng)格將類型與非類型區(qū)分開。例如,通過大寫類型名稱,而不是函數(shù)和變量的名稱。

          typename
          class HashTable { // maps string to T
          // ...
          };

          HashTable index;

          This is not harmful and does not fall under this guideline because it does not encode type information.

          這是無害的,不受該準(zhǔn)則約束,因為它沒有表達類型信息。


          原文鏈接

          https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl5-avoid-encoding-type-information-in-names


          新書介紹

          《實戰(zhàn)Python設(shè)計模式》是作者最近出版的新書,拜托多多關(guān)注!

          本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對23 個設(shè)計模式逐個進行說明。這樣一方面可以使讀者了解真實的軟件開發(fā)工作中每個設(shè)計模式的運用場景和想要解決的問題;另一方面通過對這些問題的解決過程進行說明,讓讀者明白在編寫代碼時如何判斷使用設(shè)計模式的利弊,并合理運用設(shè)計模式。

          對設(shè)計模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計和開發(fā)的參考;使用Python 語言進行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。




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

          關(guān)注微信公眾號【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!

          面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>



          瀏覽 54
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          <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>
                  黑人草逼综合网 | 奇米影视7777狠狠狠狠色 | 久草福利资源网 | 天天操天天射天天日 | 黄色大片在线免费观看 |