clean code style(1)

2021-03-03 WXCOP無限靠譜

/**  *c00kiemon5ter 2015-9-20 add  SquareState  * c00kiemon5ter 2015-10-1 change the symbol  */ public enum SquareState {     BLACK('●'),     WHITE('○'),
    PSSBL('.'),     EMPTY(' ');    
    private final char symbol;     SquareState(char symbol) {  
        this.symbol = symbol;     }  
       
    public char symbol() {  
        return this.symbol;     } }

     正例:

public enum SquareState {     BLACK('●'),     WHITE('○'),     PSSBL('.'),     EMPTY(' ');    
    private final char symbol;     SquareState(char symbol) {    
         this.symbol = symbol;     }    
   
    public char symbol() {  
        return this.symbol;     } }

$git commit -m "change BLACK symbol from x to ●, WHITE from ○ to O"

/**  * @author c00kiemon5ter  */ public enum Player {     BLACK(SquareState.BLACK),     WHITE(SquareState.WHITE);    
    private SquareState color;
   
    private Player(SquareState color) {
       this.color = color;     }    
      
    public Player opponent() {    
       return this == BLACK ? WHITE : BLACK;     }    
      
    public SquareState color() {  
        return color;     } }

正例:

public enum Player {     BLACK(SquareState.BLACK),     WHITE(SquareState.WHITE);    
    private SquareState color;
   
    private Player(SquareState color) {    
        this.color = color;     }
       
    public Player opponent() {  
       return this == BLACK ? WHITE : BLACK;     }
      
    public SquareState color() {  
       return color;     } }

public Point evalMove() {     AbstractSearcher searcher;     Evaluation evalfunc;     searcher = new NegaMax();
        evalfunc = new ScoreDiffEval();
        return searcher.simpleSearch(board, player, depth, evalfunc).getPoint(); }

正例:

public Point evalMove() {     AbstractSearcher searcher;     Evaluation evalfunc;     searcher = new NegaMax();     evalfunc = new ScoreDiffEval();
    return searcher.simpleSearch(board, player, depth, evalfunc).getPoint(); }

WORD32 GetCharge(T_Customer* tCustomer) {     ... }

正例:

WORD32 GetTotalRentalCharge(Customer* customer) {     ... }

public static Set<Point> explore(final Board board, final SquareState state) {     Set<Point> possibleMoves = new HashSet<Point>();     Set<Point> statePoints = board.getSquares(state);
    for (Point seed : statePoints) {  
        for (Direction direction : Direction.values()) {  
            if (shouldSearch(board, seed, direction)) {                 Point nextPoint = direction.next(seed);                 nextPoint = direction.next(nextPoint);
                while (pointIsValid(nextPoint)) {      
                    if (board.getSquareState(nextPoint) == state) {                                              break;                     } else if (board.getSquareState(nextPoint) == SquareState.EMPTY) {                         possibleMoves.add(nextPoint);                         break;                     }                     nextPoint = direction.next(nextPoint);                 }             }         }     }     return possibleMoves; }

public synchronized void waitForClose(final long timeoutMillis) throws Exception {
 if(!closed)  {       wait(timeoutMillis);     if(!closed)     throw new Exception("MockResponseSender could not be closed"); }}

正例:

public synchronized void waitForClose(final long timeoutMillis) throws Exception { if(!closed) {     wait(timeoutMillis);
    if(!closed)
    throw new Exception("MockResponseSender could not be closed"); }}

class GTEST_API_ AssertionResult {
    public:             AssertionResult(const AssertionResult& other);
        explicit AssertionResult(bool success) : success_(success) {}
   
        operator bool() const { return success_; }       private:
        bool success_; };

正例:

class GTEST_API_ AssertionResult {
public:     AssertionResult(const AssertionResult& other);
    explicit AssertionResult(bool success) : success_(success) {}
    operator bool() const { return success_; }
   
private:
     bool success_; };

 請繼續閱讀「clean code style(2)」  

相關焦點

  • 聊聊clean code
    本文主要針對面向對象編程的clean code來闡述,面向過程代碼的思路會比較不同,不在本文的討論範疇。代碼大部分時候是用來維護的,而不是用來實現功能的這個原則適用於大部分的工程。我們的代碼,一方面是編譯好讓機器執行,完成功能需求;另一方面,是寫給身邊的隊友和自己看的,需要長期維護,而且大部分項目都不是朝生夕死的短命鬼。
  • 廉政準則 code of ethics
    廉政準則 code of ethics[ 2010-02-25 11:42 ]中共中央近日印發黨員領導幹部廉政準則,詳細規定了領導幹部從政行為八大方面52種「不準」行為請看新華社的報導:The Communist Party of China (CPC) Central Committee issued a code of ethics for CPC cadres to follow Tuesday to ensure clean practice in their work and prevent
  • Clean是乾淨,cut是切,clean-cut可不是「乾淨的一刀切」啊!
    1. clean-cut是啥什麼意思?當我們說一個人非常乾淨利落,習慣性用一個表達叫做clean-cut。Clean是乾淨,cut是切,clean-cut可不是「乾淨的一刀切」啊!Clean-cut means you look quite neat and clean,所以,Clean-cut形容一個人看上去乾淨整潔,清清爽爽喲!看看下面這個人,是不是這樣?
  • Goodbye Clean Code,這是對代碼編寫與重構的新感悟
    .){//5uniquelinesofmath},}組合成各種行為特性:let{top,bottom,left,right}=Directions;functioncreateHandle(directions){//20linesofcode}letfourCorners=[createHandle
  • Code Runner for VS Code 突破 2000 萬下載量!支持超過 50 種語言
    code-runner.executorMap{ "code-runner.executorMap": { "javascript": "node", "php": "C:\\php\\php.exe", "python": "python", "perl": "perl
  • Java on Visual Studio Code 九月更新
    Other new code actions最新版本中還包括了一些其他代碼操作和修復: Invert local variable:可以將布爾變量的值變為相反值 Convert lambda to anonymous class(將 lambda 轉換為匿名類) Create unresolved types(創建未解析類型):它包括在各種場景中創建簡單的 class/enum/interface/annotationLinting and Checkstyle
  • Clean slate
    with a clean slate.Naturally one prefers drawing on a clean slate. This is what Mao referred to as a 「clean sheet」.
  • Let the spooks come out in style with these cocktails
    Get spooked in styleExtending beyond traditional haunted houses, you will be entering a classicOctober 31- November 1, 9pm till lateWhat?Halloween Party at The Ritz Bar & LoungeFrom RMB98 per cocktailWhere?
  • clean sweep
    11月1日,第四屆東亞運動會田徑比賽燃起硝煙。中國選手在首日決出的9項金牌中狂掠8金,女子萬米比賽中國新秀包桂英在離終點還有300米時加速超越日本老將大南博美,奪得冠軍。 請看外電報導:Bao Guiying has led a clean sweep for China of the East Asian Games' opening athletics events, with victory in the women's 10,000m.
  • The Only Ingredient You Need to Clean Up Your Whole House
    Keeping your house clean is something we all regularly have to do, but why does it have to include cleaners that have so many toxic and synthetic chemicals?
  • 6 個實用的Code Review 實踐技巧
    怎麼做 code review?本文分享了 Shopify 非常實用的 6 個 code review 實踐技巧。 Code reviews 是打造高效團隊的重要方面,這已經成為共識。現實中,許多企業的無數團隊都進行過某種形式的 code reviews。
  • 「come」是來,「clean」是乾淨的,那come clean是啥呢?
    犯錯後女朋友叫我「come clean」,是要我弄乾淨點去找她嗎?1. Come clean「come」是來,「clean」是乾淨的,那come clean是啥呢?根據英文意思可以知道come clean就是坦白承認,說出一切,好好交代。有一種坦白從寬,抗拒從嚴的感覺。比如說下面這一個人,真讓人想笑。
  • 6 個實用的 Code Review 實踐技巧
    現實中,許多企業的無數團隊都進行過某種形式的 code reviews。而實際情況是,code reviews 剛開始時,人們的激情高漲,之後,code reviews 則流於形式,或者要麼反饋不清晰、要麼讓人難以執行。長久以往,這讓團隊錯失了加快學習、分享知識的機會,最終難以提高代碼的質量。在 Shopify,我們不僅立足長遠,而且希望追求發展更快。
  • 一步步學寫Windows下的Shellcode
    ,需要在WIN7下做一些自定義shellcode,自己之前自定義的shellcode居然無法在WIN7下運行,於是想起這篇未完工的文章,藉此對shellcode編寫做一次總結與複習。前文我們編寫的MessageBoxA的地址是硬編碼的,導致這段shellcode只能利用於windows xp sp0。但是Windows並不支持像Linux那樣的int 0x80中斷呼叫函數的操作,於是唯一的方法就是通過PE文件中的函數導出表獲取函數此刻的地址,這個方法在提高可移植性的同時,還可以一勞永逸地解決ASLR帶來的地址偏移問題。1.