c++編碼風格指南_100%正確編碼樣式指南

c++編碼風格指南

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

制表符或空格? 在同一行或新行上大括號? 80個字符的寬度還是120個字符?

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.

編碼人員喜歡爭論這種事情。 標簽與空間的辯論甚至使它成為了HBO節目《 硅谷》中的著名一集 。

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.

在我職業生涯的早期,我參加了各種圣戰。 我會讀一些文章,說明為什么某個特定約定正確,而另一個完全錯誤。 我會騎著高大而有力的馬上去,向任何聽他們說錯了而我是對的人宣告。

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

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

These things don’t matter.

這些都沒關系。

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

一致性很重要。 可讀性很重要。 爭論和強調一個公約而不是另一個公約并不重要。

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.

在過去的20多年中,我一直關注著每一個可以想象的趨勢。 我遵循了不同語言的不同約定。 這些都不會影響我的錯誤計數或提高我的代碼效率。

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.

別誤會,外觀簡潔,格式正確的代碼將隨著時間的推移更易于更改和維護,這是一件好事。

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.

希望代碼看起來很漂亮也沒有錯。 但是很多時候,這是用來證明本質上歸結為拖延的理由。

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.

我們這樣拖延是因為編碼很難。 事情可能會急忙變得復雜,而我們-尤其是對于那些剛剛接觸到這種復雜性水平的人-可能會被這種復雜性嚇倒,并對我們馴服它的能力變得不安全。

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

在瑣碎的事情上爭論要安全得多。 我們認為自己的無能這樣暴露的可能性較小。

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

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

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

最受歡迎的方法之一是帕金森的瑣碎法則,其中指出組織成員對瑣碎問題的重視程度過高。

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.

在說明這項法律時,帕金森舉了一個虛構的例子來說明這個委員會的工作,該委員會的工作是批準新核電站的計劃,但他花了大部分時間在討論用于員工自行車棚的材料。 他們忽略了工廠本身的擬議設計,這不僅是重要的問題,而且也是更為復雜的問題。

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.

由于在此典型示例中提到了自行車棚,丹麥開發商Poul-Henning Kamp后來創造了術語“自行車棚效應”或簡稱為“自行車脫落”來描述它。

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.

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

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

如果您發現自己與在線或面對面的編碼員展開了異常激烈的辯論,那么也有必要記住塞勒定律 ……

“In any dispute the intensity of feeling is inversely proportional to the value of the issues at stake.”
“在任何爭議中,感覺的強度與所涉問題的價值成反比。”

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.

作為顧問,我在客戶之間跳來跳去,每個人都有自己的規則和約定。 我很久以前就決定,我要成功的唯一方法就是放下瑣碎的事,集中精力解決棘手的問題。 當涉及到編碼標準時,我會接受,但不會感到沮喪。

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:

如果您碰巧發現自己可以選擇自己的風格指南,則建議您自問以下兩個簡單問題:

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

    是否有工具可以將樣式規則自動應用于我的代碼,而幾乎不需要我干預?
  2. Are the tools and underlying styles actively maintained and/or used by reputable organizations?

    信譽良好的組織是否積極維護和/或使用了工具和基礎樣式?

If you can answer “yes” to both of those questions, then you’re good to go. Simple as that.

如果您對這兩個問題都回答“是”,那么您就很好了。 就那么簡單。

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

以下是一些適合當今一些較流行的網絡語言的選項:

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標準樣式 (注意,這是產品名稱,而不是實際的官方JavaScript標準)

PHP Coding Standards Fixer

PHP編碼標準修復程序

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.

如果您喜歡這篇文章,請反復粉碎這篇文章底部的拍手圖標,以幫助傳播這個詞。 如果您想類似的內容,請在下面注冊我的每周開發精通通訊。

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

c++編碼風格指南

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/395666.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/395666.shtml
英文地址,請注明出處:http://en.pswp.cn/news/395666.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

Netty源碼注釋翻譯-Channel類

定義為一個通往網絡socket或者一個由I/O讀寫能力的組件。 通道提供: 1,通道的當前狀態,打開?已連接? 2,跟通道關聯的配置信息ChannelConfig,包括buffer大小等。 3,通道支持的I/O操作…

Today is weekend不是應該一定會輸出嗎

判斷語句 If…else塊&#xff0c;請看下面這個例子&#xff1a; <%! int day 3; %>                       //聲明變量感嘆號 <html> <head><title>IF...ELSE Example</title></head> <body> <% if (day …

時間模塊和時間工具

一、time模塊 三種格式 時間戳時間&#xff1a;浮點數 單位為秒 時間戳起始時間&#xff1a; 1970.1.1 0:0:0 英國倫敦時間 1970.1.1 8:0:0 我國(東8區) 結構化時間&#xff1a;元組(struct_time) 格式化時間&#xff1a;str數據類型的 1、常用方法 import timetime.sleep(secs…

redux擴展工具_用鴨子擴展您的Redux App

redux擴展工具How does your front-end application scale? How do you make sure that the code you’re writing is maintainable 6 months from now?您的前端應用程序如何擴展&#xff1f; 您如何確定您正在編寫的代碼從現在起6個月內可維護&#xff1f; Redux took the …

mac下源碼安裝redis

轉載&#xff1a;http://www.jianshu.com/p/6b5eca8d908b 下載安裝包 redis-3.0.7.tar.gz 官網地址&#xff1a;http://redis.io/download 解壓&#xff1a;tar -zvxf redis-3.0.7.tar.gz 將解壓后的文件夾放到 /usr/local目錄下 編譯測試:接下來在終端中切換到/usr/local/red…

代碼掃描工具測試覆蓋率工具

測試覆蓋率工具轉載于:https://www.cnblogs.com/vivian-test/p/5398289.html

php splqueue 5.5安裝,解析PHP標準庫SPL數據結構

SPL提供了雙向鏈表、堆棧、隊列、堆、降序堆、升序堆、優先級隊列、定長數組、對象容器SplQueue 隊列類進出異端&#xff0c;先進先出<?php $obj new SplQueue();//插入一個節點到top位置$obj->enqueue(1);$obj->enqueue(2);$obj->enqueue(3);/**SplQueue Object…

Beta階段敏捷沖刺總結

設想和目標 1. 我們的軟件要解決什么問題&#xff1f;是否定義得很清楚&#xff1f;是否對典型用戶和典型場景有清晰的描述&#xff1f; 在最開始的時候我們就是為了解決集美大學計算機工程學院網頁沒有搜索引擎的問題。因為沒有搜索引擎&#xff0c;在搜索內容時需要根據查找信…

c語言 二進制壓縮算法_使用C ++解釋的二進制搜索算法

c語言 二進制壓縮算法by Pablo E. Cortez由Pablo E.Cortez 使用C 解釋的二進制搜索算法 (Binary Search Algorithms Explained using C) Binary search is one of those algorithms that you’ll come across on every (good) introductory computer science class. It’s an …

【LATEX】個人版latex論文模板

以下是我的個人論文模板&#xff0c;運行環境為Xelatex(在線ide&#xff1a;Sharelatex.com) 鑒于本人常有插入程序的需求&#xff0c;故引用了lstlisting \RequirePackage{ifxetex} \ifxetex\documentclass[hyperref, UTF8, c5size, no-math, winfonts&#xff0c;a4paper]{ct…

初識virtual memory

一、先談幾個重要的東西 virtual memory是一個抽象概念&#xff0c;書上的原文是"an abstraction of main memory known as virtual memory"&#xff08;參考資料p776&#xff09;。那么什么是抽象概念。下面說說我個人對這個東西的理解。 所謂抽象概念是指抽象出來的…

java創建mysql驅動,JDBC之Java連接mysql實現增刪改查

使用軟件&#xff1a;mysql、eclipse鏈接步驟&#xff1a;1.注冊驅動2.創建一個連接對象3.寫sql語句4.執行sql語句并返回一個結果或者結果集5.關閉鏈接(一般就是connection、statement、setresult)這三個連接對象&#xff0c;關閉順序一般是(setresult ---> statement …

算法第五章作業

1.你對回溯算法的理解&#xff08;2分&#xff09; 回溯法&#xff08;探索與回溯法&#xff09;是一種選優搜索法&#xff0c;又稱為試探法&#xff0c;按選優條件向前搜索&#xff0c;以達到目標。但當探索到某一步時&#xff0c;發現原先選擇并不優或達不到目標&#xff0c;…

c++編碼風格指南_100%正確的編碼樣式指南

c編碼風格指南Here are three links worth your time:這是三個值得您花費時間的鏈接&#xff1a; The 100% correct coding style guide (4 minute read) 100&#xff05;正確的編碼樣式指南( 閱讀4分鐘 ) I wrote a programming language. Here’s how you can, too (10 minu…

xp開機黑屏故障分析

今天裝完xp系統之后&#xff0c;重啟開機發現竟然黑屏了&#xff0c;查資料發現有很多用戶在修改分辨率后&#xff0c;因顯示器不支持修改后的分辨率&#xff0c;會出現電腦黑屏的情況。分辨率調高了&#xff0c;超出了屏幕的范圍&#xff0c;肯定會黑屏&#xff0c;而且這個問…

應用程序圖標_如何制作完美的應用程序圖標

應用程序圖標by Nabeena Mali通過Nabeena Mali 如何制作完美的應用程序圖標 (How to Make the Perfect App Icon) With just 24 app icon slots on the first page of an iPhone home screen, or 28 if you have a fancy iPhone 7, creating the perfect app icon is a vital …

Luogu3702 SDOI2017 序列計數 矩陣DP

傳送門 不考慮質數的條件&#xff0c;可以考慮到一個很明顯的$DP:$設$f_{i,j}$表示選$i$個數&#xff0c;和$mod\ pj$的方案數&#xff0c;顯然是可以矩陣優化$DP$的。 而且轉移矩陣是循環矩陣&#xff0c;所以可以只用第一行的數字代替整個矩陣。當然了這道題$p \leq 100$矩陣…

java閏年的年份,Java案例-判斷給定年份是閏年

專注學子高考志愿填報&#xff0c;分享你所不知道信息。Java案例-判斷給定年份是閏年案例描述編寫程序&#xff0c;判斷給定的某個年份是否是閏年。閏年的判斷規則如下&#xff1a;(1)若某個年份能被4整除但不能被100整除&#xff0c;則是閏年。(2)若某個年份能被400整除&#…

通過path繪制點擊區域

通過path繪制點擊區域 效果 源碼 https://github.com/YouXianMing/Animations // // TapDrawImageView.h // TapDrawImageView // // Created by YouXianMing on 16/5/9. // Copyright © 2016年 YouXianMing. All rights reserved. //#import <UIKit/UIKit.h> #…

Raft與MongoDB復制集協議比較

在一文搞懂raft算法一文中&#xff0c;從raft論文出發&#xff0c;詳細介紹了raft的工作流程以及對特殊情況的處理。但算法、協議這種偏抽象的東西&#xff0c;僅僅看論文還是比較難以掌握的&#xff0c;需要看看在工業界的具體實現。本文關注MongoDB是如何在復制集中使用raft協…