codestyle

There are nothing about the best code style, and, unfortunately, I have to switch my style in some case.

0. Common

0.1 Dir Name

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

For Csharp, I prefer to use camelCase, for others, I prefer to use lower-case words with _.

0.2 File Name

For languages except for Csharp, don't use uppercase. like hello.h, hello.cs, hello.js, and hello.py are better, in some cases use _
2. For CSharp, using uppercase is better.

0.3 Repository Name

Use CamelCase, and the first letter is capitalized.

1. C++

1.1 Class and 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.
  4. template Using CamelCase. the first letter is capitalized

for example:

namespace Earth {
template<typename T,int Age>
class Human {
public:
  void eat();
  std::vector<GirlFriend> _s_girl_friend;
  std::string _name;
}
} 

1.4 Function and Lambda

  1. if a function is not a member of a class, the first letter is capitalized.
  2. parameter end with _(for no other need), using CamelCase.
  3. if I don't need a name with some meaning, use _,1_, and so on.
int Add(int l_,int r_) {
    return l_ + r_;
}

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

2. Javascript

Now, mostly, I just write javascript code that runs on browsers, and I often use Vue.

2.1 Name

  1. If a variable is a 'ref' value. using like const _name = ref('ZhaoYouya'), it is similar to variable members in a class.
  2. usually, a variable name uses a style like const your_name = 'zhaolei', this is a difference with 'ref' variables.
  3. But, if a variable is from a database, using like Id, Name. CamelCase and the first letter are capitalized.

For function:

It's similar to CPP.

js

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

})

2.2 Code Arrangement

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>

3. CSharp

3.1 Class and Region

Microsoft always has differences from others.

  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 capitalized.

3.4 Function and Lambda

It's similar to CPP.

for example:

class Human 
{
    public void Eat(List<Food> food_s_){
      foreach (var _ in food_s_)
      {
        
      }
    };
    public List<GirlFriend> _s_girl_friend {get;set;}
    public string _name{get;set;};

}

4. Python

It's similar to CPP.

5. SQL

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

for example:

create table sys_user (
  Id int,
  Name varchar(20)
)
posted @ 2022-10-12 18:24  渊默、  阅读(25)  评论(0)    收藏  举报