日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

c++编码风格指南_100%正确编码样式指南

發(fā)布時(shí)間:2023/11/29 c/c++ 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++编码风格指南_100%正确编码样式指南 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c++編碼風(fēng)格指南

Tabs or spaces? Curly brace on the same line or a new line? 80 character width or 120?

制表符或空格? 在同一行或新行上大括號(hào)? 80個(gè)字符的寬度還是120個(gè)字符?

Coders love to argue about this kind of stuff. The tabs vs. spaces debate even made it into a famous episode of the HBO show Silicon Valley.

編碼人員喜歡爭(zhēng)論這種事情。 標(biāo)簽與空間的辯論甚至使它成為了HBO節(jié)目《 硅谷》中的著名一集 。

Well in this article, I will finally give you the definitive answers you seek.

好吧,在本文中,我將最終為您提供確定的答案。

Early in my career, I engaged in all kinds of holy wars. I would read some article about why a particular convention was correct, while another was totally wrong. I would get right up there on my high and mighty horse and proclaim to anyone who would listen that they were wrong and I was right.

在我職業(yè)生涯的早期,我參加了各種圣戰(zhàn)。 我會(huì)讀一些文章,說(shuō)明為什么某個(gè)特定約定正確,而另一個(gè)完全錯(cuò)誤。 我會(huì)騎著高大而有力的馬上去,向任何聽(tīng)他們說(shuō)錯(cuò)了而我是對(duì)的人宣告。

It took me years to find the right answers but I’ve finally done it and it turns out the answer is…

我花了多年的時(shí)間才找到正確的答案,但我終于做到了,事實(shí)證明答案是…

These things don’t matter.

這些都沒(méi)關(guān)系。

Consistency matters. Readability matters. Arguing and stressing about one convention over another matters not.

一致性很重要。 可讀性很重要。 爭(zhēng)論和強(qiáng)調(diào)一個(gè)公約而不是另一個(gè)公約并不重要。

Over the past 20+ years, I’ve followed every imaginable trend. I’ve followed the different conventions of different languages. None of it has impacted my bug count or made my code any more efficient.

在過(guò)去的20多年中,我一直關(guān)注著每一個(gè)可以想象的趨勢(shì)。 我遵循了不同語(yǔ)言的不同約定。 這些都不會(huì)影響我的錯(cuò)誤計(jì)數(shù)或提高我的代碼效率。

Don’t get me wrong, clean-looking, well-formatted code will be easier to change and maintain over time, and that’s a good thing.

別誤會(huì),外觀簡(jiǎn)潔,格式正確的代碼將隨著時(shí)間的推移更易于更改和維護(hù),這是一件好事。

There’s also nothing wrong with wanting your code to look beautiful. But too often, this is used to justify what essentially boils down to procrastination.

希望代碼看起來(lái)很漂亮也沒(méi)有錯(cuò)。 但是很多時(shí)候,這是用來(lái)證明本質(zhì)上歸結(jié)為拖延的理由。

We procrastinate like this because coding is hard. Things can get complicated in a hurry and we — especially those of us who may be new to this level of complexity — can become intimidated by this complexity and grow insecure about our ability to tame it.

我們這樣拖延是因?yàn)榫幋a很難。 事情可能會(huì)急忙變得復(fù)雜,而我們-尤其是對(duì)于那些剛剛接觸到這種復(fù)雜性水平的人-可能會(huì)被這種復(fù)雜性嚇倒,并對(duì)我們馴服它的能力變得不安全。

It’s much safer to argue over trivial things. Our perceived incompetence is less likely to be exposed that way.

在瑣碎的事情上爭(zhēng)論要安全得多。 我們認(rèn)為自己的無(wú)能這樣暴露的可能性較小。

The phenomena of debating trivialities to avoid hard problems is so common that there are a number of popular theories that describe it.

為了避免難題而進(jìn)行瑣碎辯論的現(xiàn)象非常普遍,以至于有許多流行的理論對(duì)此進(jìn)行了描述。

One of the most popular is Parkinson’s Law of Triviality which states that members of an organization give disproportionate weight to trivial issues.

最受歡迎的方法之一是帕金森的瑣碎法則,其中指出組織成員對(duì)瑣碎問(wèn)題的重視程度過(guò)高。

In illustrating this law, Parkinson used the fictional example of a committee whose job it was to approve plans for a new nuclear plant, but who spent the majority of their time arguing over what materials to use for the staff bike shed. They neglected the proposed design of the plant itself, which was a far more important but also far more complex issue.

在說(shuō)明這項(xiàng)法律時(shí),帕金森舉了一個(gè)虛構(gòu)的例子來(lái)說(shuō)明這個(gè)委員會(huì)的工作,該委員會(huì)的工作是批準(zhǔn)新核電站的計(jì)劃,但他花了大部分時(shí)間在討論用于員工自行車(chē)棚的材料。 他們忽略了工廠本身的擬議設(shè)計(jì),這不僅是重要的問(wèn)題,而且也是更為復(fù)雜的問(wèn)題。

Because of the reference to a bike shed in this canonical example, Danish developer, Poul-Henning Kamp later coined the term “bike shed effect” or simply “bike shedding” to describe it.

由于在此典型示例中提到了自行車(chē)棚,丹麥開(kāi)發(fā)商Poul-Henning Kamp后來(lái)創(chuàng)造了術(shù)語(yǔ)“自行車(chē)棚效應(yīng)”或簡(jiǎn)稱(chēng)為“自行車(chē)脫落”來(lái)描述它。

If you work in software development — and especially if you hang out with other coders on social media — you’re likely to come across some form of bike-shedding almost daily.

如果您從事軟件開(kāi)發(fā)工作,特別是如果您在社交媒體上與其他編碼員一起閑逛,那么您幾乎每天都可能會(huì)碰到某種形式的騎自行車(chē)。

If you find yourself getting into an unusually heated debate with your fellow coders, online or in-person, it’s probably also worth remembering Sayre’s Law…

如果您發(fā)現(xiàn)自己與在線或面對(duì)面的編碼員展開(kāi)了異常激烈的辯論,那么也有必要記住塞勒定律 ……

“In any dispute the intensity of feeling is inversely proportional to the value of the issues at stake.”“在任何爭(zhēng)議中,感覺(jué)的強(qiáng)度與所涉問(wèn)題的價(jià)值成反比。”

As a consultant, I bounce from client to client, and each one has their own rules and conventions. I decided long ago that the only way for me to succeed was to let go of the trivialities and focus on the hard problems. When it comes to coding standards, I take what I get and I don’t get upset.

作為顧問(wèn),我在客戶(hù)之間跳來(lái)跳去,每個(gè)人都有自己的規(guī)則和約定。 我很久以前就決定,我要成功的唯一方法就是放下瑣碎的事,集中精力解決棘手的問(wèn)題。 當(dāng)涉及到編碼標(biāo)準(zhǔn)時(shí),我會(huì)接受,但不會(huì)感到沮喪。

If you happen to find yourself in a position to pick your own style guide, I recommend that you ask yourself these two simple questions:

如果您碰巧發(fā)現(xiàn)自己可以選擇自己的風(fēng)格指南,則建議您自問(wèn)以下兩個(gè)簡(jiǎn)單問(wèn)題:

  • Is there tooling that will automatically apply the style rules to my code with little to no intervention from me?

    是否有工具可以將樣式規(guī)則自動(dòng)應(yīng)用于我的代碼,而幾乎不需要我干預(yù)?
  • Are the tools and underlying styles actively maintained and/or used by reputable organizations?

    信譽(yù)良好的組織是否積極維護(hù)和/或使用了工具和基礎(chǔ)樣式?
  • If you can answer “yes” to both of those questions, then you’re good to go. Simple as that.

    如果您對(duì)這兩個(gè)問(wèn)題都回答“是”,那么您就很好了。 就那么簡(jiǎn)單。

    Here are some options that fit the bill for some of today’s more popular web languages:

    以下是一些適合當(dāng)今一些較流行的網(wǎng)絡(luò)語(yǔ)言的選項(xiàng):

    DotNet Code Formatter

    DotNet代碼格式化程序

    Java: Google-Java-Format

    Java:Google Java格式

    Javascript Standard Style (N.B. this is a product name, not an actual, official JavaScript standard)

    Javascript標(biāo)準(zhǔn)樣式 (注意,這是產(chǎn)品名稱(chēng),而不是實(shí)際的官方JavaScript標(biāo)準(zhǔn))

    PHP Coding Standards Fixer

    PHP編碼標(biāo)準(zhǔn)修復(fù)程序

    Python: Google’s YAPF

    Python:Google的YAPF

    Ruby: Rubocop

    Ruby:Rubocop

    If you enjoyed this article, please smash the clap icon at the bottom of this post repeatedly to help spread the word. And if you want to read more stuff like this, please sign up for my weekly Dev Mastery newsletter below.

    如果您喜歡這篇文章,請(qǐng)反復(fù)粉碎這篇文章底部的拍手圖標(biāo),以幫助傳播這個(gè)詞。 如果您想類(lèi)似的內(nèi)容,請(qǐng)?jiān)谙旅孀?cè)我的每周開(kāi)發(fā)精通通訊。

    翻譯自: https://www.freecodecamp.org/news/the-100-correct-coding-style-guide-5b594a1655f0/

    c++編碼風(fēng)格指南

    總結(jié)

    以上是生活随笔為你收集整理的c++编码风格指南_100%正确编码样式指南的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。