C++核心準(zhǔn)則?NL.11:使字面值可讀

NL.11: Make literals readable
NL.11:使字面值可讀
Reason(原因)
Readability.
可讀性。
Example(示例)
Use digit separators to avoid long strings of digits
使用數(shù)字分隔符避免數(shù)字過長(zhǎng)
auto c = 299'792'458; // m/s2
auto q2 = 0b0000'1111'0000'0000;
auto ss_number = 123'456'7890;
Example(示例)
Use literal suffixes where clarification is needed
在需要說明時(shí)使用字面值后綴
auto hello = "Hello!"s; // a std::string
auto world = "world"; // a C-style string
auto interval = 100ms; // using Note(注意)
Literals should not be sprinkled all over the code as?"magic constants", but it is still a good idea to make them readable where they are defined. It is easy to make a typo in a long string of integers.
不應(yīng)將字面值以“魔術(shù)常數(shù)”的形式散布在整個(gè)代碼中,即使這樣做了,使它們?cè)诙x的地方可讀仍是一個(gè)好主意。用一長(zhǎng)串整數(shù)輸入錯(cuò)字很容易。
Enforcement(實(shí)施建議)
Flag long digit sequences. The trouble is to define "long"; maybe 7.
標(biāo)記長(zhǎng)數(shù)字序列。麻煩在于如何定義“長(zhǎng)”;也許長(zhǎng)于7可以作為一個(gè)標(biāo)準(zhǔn)。
原文鏈接
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl11-make-literals-readable
新書介紹
《實(shí)戰(zhàn)Python設(shè)計(jì)模式》是作者最近出版的新書,拜托多多關(guān)注!

本書利用Python 的標(biāo)準(zhǔn)GUI 工具包tkinter,通過可執(zhí)行的示例對(duì)23 個(gè)設(shè)計(jì)模式逐個(gè)進(jìn)行說明。這樣一方面可以使讀者了解真實(shí)的軟件開發(fā)工作中每個(gè)設(shè)計(jì)模式的運(yùn)用場(chǎng)景和想要解決的問題;另一方面通過對(duì)這些問題的解決過程進(jìn)行說明,讓讀者明白在編寫代碼時(shí)如何判斷使用設(shè)計(jì)模式的利弊,并合理運(yùn)用設(shè)計(jì)模式。
對(duì)設(shè)計(jì)模式感興趣而且希望隨學(xué)隨用的讀者通過本書可以快速跨越從理解到運(yùn)用的門檻;希望學(xué)習(xí)Python GUI 編程的讀者可以將本書中的示例作為設(shè)計(jì)和開發(fā)的參考;使用Python 語言進(jìn)行圖像分析、數(shù)據(jù)處理工作的讀者可以直接以本書中的示例為基礎(chǔ),迅速構(gòu)建自己的系統(tǒng)架構(gòu)。
覺得本文有幫助?請(qǐng)分享給更多人。
關(guān)注微信公眾號(hào)【面向?qū)ο笏伎肌枯p松學(xué)習(xí)每一天!
面向?qū)ο箝_發(fā),面向?qū)ο笏伎迹?/span>
