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
class nameThe first letter is capitalized. Using CamelCase. the namespace name is the same style.variable memberthe first word is_, The interval in words is also_, don't use uppercase. if the variable is a group type, use like_s_name.function member. Using CamelCase. the first letter is not capitalized.templateUsing 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
- if a function is not a member of a class, the first letter is capitalized.
parameterend with_(for no other need), using CamelCase.- 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
- If a variable is a 'ref' value. using like
const _name = ref('ZhaoYouya'), it is similar to variable members in a class. - usually, a variable name uses a style like
const your_name = 'zhaolei', this is a difference with 'ref' variables. - 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.
class nameThe first letter is capitalized. Using CamelCase. the namespace name is the same style.variable memberthe first word is_, The interval in words is also_, don't use uppercase. if the variable is a group type, use like_s_name.function member. Using CamelCase. the first letteris 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
DB Nameuse CamelCase, the first letter is capitalized.Table Name. they have a prefix, and use_as an interval word. likesys_user, don't use camelcase.Field Nameuses CamelCase, and the first letter is capitalized.
for example:
create table sys_user (
Id int,
Name varchar(20)
)

浙公网安备 33010602011771号