All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
一年内4000家企业退市,LED行业剧烈洗牌 - LED
买了“携程”无效票,损失应该谁来赔? - 携程,机票
In 2013, “the other ones“ invention,
英特尔总裁蕾妮·詹姆斯离职 - 英特尔,Intel
美国公司设计末日地下避难所,堪称现代诺亚方舟 - 避难所,末日
雪姨急了:HTC股价再暴跌,市值仅剩65亿 - HTC
国防部官方微博微信正式开通,第一条微博好萌 - 国防部,微博,微信
4G not hot, 5G has begun hot dishes,
任志强微博账号被关闭 - 任志强,微博
土豪金,中国首辆3D打印概念汽车面世 - 3d打印概念汽车,3D打印
Reading number is top 10 pictures
这才是真正的人体艺术5
HongMenYan premiere XinLiangGong clairvoyant outfit PK YiFeiLiu1
大人物的礼物
人美胸美腿更美2
无题
A letter to parents choose world of warcraft seven big reason
到南昌西站了3
30 beautiful school beauty4
赵惟依写真2
西班牙山村小景3
Download software ranking
White deer villiage
Tram sex maniac 2 (H) rar bag5
Boxer Classic video3
Proficient in JavaScript
Kung.Fu.Panda.2
Popkart Cracked versions Mobile phone games
Boxer's Top ten classic battle4
Unix video tutorial6
Unix video tutorial14
超级战舰
qq published in(发表于) 2015/6/6 7:30:10 Edit(编辑)
Code comment: note the “5 should not be 3“

Code comment: note the “5 should not be 3“

Code comment: note the "5 should not be 3"-code-IT information

Code comments, can be said to be more important than the code itself. Here are some ways to make sure that you write in the comments in the code are friendly:

Do not repeat readers already know the content of

Comment can clearly describe what the code is doing is not helpful to us.

If the color is red, turn it green

if (color.is_red()) {

color.turn_green();

}

Explanatory reasoning and history

If the business logic in your code may need to be updated or changed, that should leave a comment:)

/* The API currently returns an array of items

even though that will change in an upcoming ticket.

Therefore, be sure to change the loop style here so that

we properly iterate over an object */

var api_result = {items: ["one", "two"]},

items = api_result.items,

num_items = items.length;

for(var x = 0; x < num_items; x++) {

...

}

Same line don't write very long

Drag the horizontal scroll bar to read the comment nothing developers even more heinous. In fact, most developers will choose to ignore these comments, because reading is really inconvenient.

function Person(name) {

this.name = name;

this.first_name = name.split(" ")[0];?This is just a shot in the dark here. If we can extract the first name, let's do it

}

Long comment should be placed in the logic above, short annotations in the back

Note If you do not exceed 120 characters that can be placed next to the code. Otherwise, they should direct comments to the statement above.

if (person.age < 21) {

person.can_drink = false; 21 drinking age

/* Fees are given to those under 25, but only in

some states. */

person.has_car_rental_fee = function(state) {

if (state === "MI") {

return true;

}

};

}

Not to comment while adding unnecessary comments

Superfluous comment was confusing. Maybe in school teacher teaches you to add comments to all the statements, which will help developers understand better. But this is wrong. Who's to say, you pitch to him at once two big erguazi. Code should be clean and simple, this is beyond doubt. If your code line-by-line explanations, then you need to do is to refactor.

if (person.age >= 21) {

person.can_drink = true; A person can drink at 21

person.can_smoke = true; A person can smoke at 18

person.can_wed = true; A person can get married at 18

person.can_see_all_movies = true; A person can see all movies at 17

I hate babies and children and all things pure because I comment too much

}

Note to correct spelling

Don't excuse spelling errors in the code comments. IDE can check spelling for you. If you do not have this feature, so go download the plugin yourself!

To practice

Practice makes perfect. Try to write some useful comments, you can ask your comment is useful for other developers. As time goes on, you will have learned how to be a friendly note.

To review other people's comments

In the code review, we tend to ignore the view notes. Don't be afraid to ask for more notes, you should be questioning. If everyone can form good habits of writing comments, then the world will be more beautiful.

Summary

Comments are an important part of the development process, but we should not comment in order to comment. Comments should be useful, simple, should be a complement to the code. Comments should not be used to explain the code line-by-line, on the contrary, it should be used to explain the business logic, reasoning, and inspiration for the future.








添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.