..

platform's coding style --- updating

声明

  • 所有内容都在持续更新,今天存在,明天可能就会消失,总之 WIP
  • 持续记录总结一下 platform 项目的代码规范,争取整理一个合理的文档,之后统一大家的代码规范。

唯一原则

  • 可读性是唯一原则。代码是为人阅读的,不能使用奇技婬巧而损失了可读性。

内容更新

9.2 - 更新

Code Style

Introduction of dependency

correct style:

use std::{env, thread, rand::random};
use clap::Arg;

wrong style:

extern crate rand;

use std::env;
use std::thread;
use rand::random;

// avoid '*' in importing
use clap::*;

Warnings

Warnings are not allowed in any formal code; However, they are allowed in the test code.

correct style:

// lib.rs
#![deny(warnings)]

wrong style:

// any formal modular
#![allow(warnings)]

Comments & Document

correct style:

mod abc {
    //!
    //! # Modular Docs
    //!

    #![deny(missing_docs)]

    fn xxx() {}
}

wrong style:

/// # Modular Docs
mod abc {
    #![allow(missing_docs)]

    fn xxx() {}
}

The order of mod and use

correct style:

mod a;
mod b;

use std::env;

wrong style:

use std::env;

mod a;
mod b;

9.1 - 更新

  • preclude 内容就用 *声明,不用展开,如
    use ruc::*;
    
  • 文档注释和源码空格一行,如 a.rs ```rust //! //! data sources for the query api //!

use bnc::map; ```