首页 > 其他分享 >codestyle

codestyle

时间:2022-10-12 18:34:57浏览次数:38  
标签:use Name CamelCase codestyle name letter first

Initially,I only write cpp code,but now,I also write C#,python, and javascript. I need an unidentified code style.

1. Name

1.1 Dir Name

There are no special styles, any style is OK, but all dir names should have the same style.

1.2 File Name

  1. Typically, don't use uppercase. like hello.h, hello.cs, hello.js, and hello.py are better.
  2. Using uppercase is also OK, usually, that occurred when I use C# with asp.net.
  3. _ and - are forbid

1.3 Class or Region

  1. class name The first letter is capitalized. Using CamelCase. the namespace name is the same style.
  2. variable member the first word is _, The interval in words is also _, don't use uppercase. if the variable is a group type, use like _s_name.
  3. function member. Using CamelCase. the first letter is not capitalized, but in C#, the first letter can be capitalized.

for example:

CPP


class Human {
public:
    void eat();
    std::vector<GirlFriend> _s_girl_friend;
    std::string _name;

}

C#

class Human 
{
    public void eat(){};
    public List<GirlFriend> _s_girl_friend {get;set;}
    public string _name{get;set;};

}
  1. [Vue]if a variable is a 'ref' value. using like const _name = ref('ZhaoYouya'), it is similar to variable members in a class.
  2. [Vue]usually, a variable name uses CamelCase style, the first letter is not capital. this has a good difference with 'ref' variables.

1.4 Function and Lambda

  1. parameter end with _(for no other need), using CamelCase.
  2. if I don't need a name with some meaning, use _,1_, and so on.

CPP

int add(int l_,int r_) {
    return l_ + r_;
}

for(auto& _:_s_girl_friend) {
    std::cout<<_._name();
}

js

arr.forEach(_=>{
    console.log(_)
    _.forEach(1_=>{
         console.log(1_)
    })

})

1.5 SQL Name.

  1. DB Name use CamelCase, the first letter is capital.
  2. Table Name. they have a prefix, and use _ as an interval word. like sys_user, don't use camelcase.
  3. Field Name use CamelCase, the first letter is capital.

2. Code Construct

2.1 Class and Region

  1. let variable members in a region, and function members in another region

bad


<script setup>
const _name = ref('zhaolei')
function eat() {

}
let age = 10
</script>

good


<script setup>
const _name = ref('zhaolei')
let age = 10

function eat() {

}

</script>

标签:use,Name,CamelCase,codestyle,name,letter,first
From: https://www.cnblogs.com/zhaoyouya/p/16785542.html

相关文章