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
- Typically, don't use uppercase. like
hello.h
,hello.cs
,hello.js
, andhello.py
are better. - Using uppercase is also OK, usually, that occurred when I use C# with asp.net.
_
and-
are forbid
1.3 Class or Region
class name
The first letter is capitalized. Using CamelCase. the namespace name is the same style.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
.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;};
}
[Vue]
if a variable is a 'ref' value. using likeconst _name = ref('ZhaoYouya')
, it is similar to variable members in a class.[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
parameter
end with_
(for no other need), using CamelCase.- 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.
DB Name
use CamelCase, the first letter is capital.Table Name
. they have a prefix, and use_
as an interval word. likesys_user
, don't use camelcase.Field Name
use CamelCase, the first letter is capital.
2. Code Construct
2.1 Class and Region
- 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