In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "java code comments in the 5 and 3 do not be what", in daily operation, I believe many people in java code comments in the 5 and 3 do not be what the problem is there are doubts, Xiaobian consulted all kinds of information, sorting out simple and easy to use operation methods, I hope to answer "java code comments in the 5 and 3 do not be what" doubts help! Next, please follow the small series to learn together!
Code comments are arguably more important than the code itself. Here are a few ways to make sure comments you write in your code are friendly:
Do not repeat what the reader already knows.
Comments that clearly state what the code does are not helpful.
// If the color is red, turn it greenif (color.is_red()) { color.turn_green();}
To annotate reasoning and history
If the business logic in the code may need to be updated or changed later, leave a comment:)
/* The API currently returns an array of itemseven though that will change in an upcoming ticket.Therefore, be sure to change the loop style here so thatwe 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++) { ...} 同一行的注释不要写得很长 没什么比拖动水平滚动条来阅读注释更令开发人员发指的了。事实上,大多数开发人员都会选择忽略这类注释,因为读起来真的很不方便。 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} 要把长注释放在逻辑上面,短注释放在后面 注释如果不超过120个字符那可以放在代码旁边。否则,就应该直接把注释放到语句上面。 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; } };} 不要为了注释而添加不必要的注释 画蛇添足的注释会造成混乱。也许在学校里老师教你要给所有语句添加注释,这会帮助开发人员更好地理解。但这是错的。谁要这么说,那你就立马上给他个两大耳刮子。代码应该保持干净简洁,这是毋庸置疑的。如果你的代码需要逐行解释说明,那么你最需要做的是重构。 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}
Comments should be spelled correctly
Don't make excuses for spelling errors in code comments. The IDE can check spelling for you. If you don't have this feature, download the plug-in and do it yourself!
Practice more.
Practice makes perfect. Try writing useful comments and ask other developers if your comments are useful. Over time, you'll learn what a friendly comment is.
To censor other people's comments
When reviewing code, we tend to ignore comments. Don't be afraid to ask for more comments, you should ask questions. The world would be a better place if everyone got into the habit of writing good notes.
At this point, about "java code comments in the 5 and 3 do not be what" the study is over, I hope to solve everyone's doubts. Theory and practice can better match to help you learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.