程序员应该避免的5种代码注释
2017-09-24 21:57
381 查看
1.自以为很了不得的程序员
2.过时的程序员
3.多此一举的程序员
4.爱讲故事的程序员
5.“以后再做”的程序员
public class Program { static void Main(string[] args) { string message = "Hello World!"; // 07/24/2010 Bob Console.WriteLine(message); // 07/24/2010 Bob message = "I am so proud of this code!"; // 07/24/2010 Bob Console.WriteLine(message); // 07/24/2010 Bob } }
2.过时的程序员
public class Program { static void Main(string[] args) { /* This block of code is no longer needed * because we found out that Y2K was a hoax * and our systems did not roll over to 1/1/1900 */ //DateTime today = DateTime.Today; //if (today == new DateTime(1900, 1, 1)) //{ // today = today.AddYears(100); // string message = "The date has been fixed for Y2K."; // Console.WriteLine(message); //} } }
3.多此一举的程序员
public class Program { static void Main(string[] args) { /* This is a for loop that prints the * words "I Rule!" to the console screen * 1 million times, each on its own line. It * accomplishes this by starting at 0 and * incrementing by 1. If the value of the * counter equals 1 million the for loop * stops executing.*/ for (int i = 0; i < 1000000; i++) { Console.WriteLine("I Rule!"); } } }
4.爱讲故事的程序员
public class Program { static void Main(string[] args) { /* I discussed with Jim from Sales over coffee * at the Starbucks on main street one day and he * told me that Sales Reps receive commission * based upon the following structure. * Friday: 25% * Wednesday: 15% * All Other Days: 5% * Did I mention that I ordered the Caramel Latte with * a double shot of Espresso? */ double price = 5.00; double commissionRate; double commission; if (DateTime.Today.DayOfWeek == DayOfWeek.Friday) { commissionRate = .25; } else if (DateTime.Today.DayOfWeek == DayOfWeek.Wednesday) { commissionRate = .15; } else { commissionRate = .05; } commission = price * commissionRate; } }
5.“以后再做”的程序员
pub 4000 lic class Program { static void Main(string[] args) { //TODO: I need to fix this someday - 07/24/1995 Bob /* I know this error message is hard coded and * I am relying on a Contains function, but * someday I will make this code print a * meaningful error message and exit gracefully. * I just don't have the time right now. */ string message = "An error has occurred"; if(message.Contains("error")) { throw new Exception(message); } } }
相关文章推荐
- 程序员应该避免的5种代码注释
- 程序员应该避免的5种代码注释
- 程序员应该避免的5种代码注释
- 程序员应该避免六个常见的开发错误
- 程序员为什么应该尽量避免争吵
- 4程序员小飞原计划三天完成某个任务,现在是第三天的下午,他马上就可以做完。但是在实现功能的过程中,他越来越意识到自己原来设计中的弱点,他应该采取另一个办法,才能避免后面集成阶段的额外工作。但是他如果现在就改弦更张,那势必要影响自己原来估计的准确性,并且会花费额外的时间,这样他的老板、同事也许会因此看不起他。如果他按部就班地按既定设计完成,还要花更多时间在后续集成上,但那就不是他个人的问题了,怎么办
- 程序员应该避免六个常见的开发错误
- 程序员应该坚决避免的十种编程坏毛病
- 程序员应该坚决避免的10种编程坏毛病
- 程序员应该避免写注释
- 程序员应该避免写注释
- Python程序员写代码时应该避免的16个“坑”
- 程序员应该避免六个常见的开发错误
- 程序员应该避免的 5 种代码注释
- 5种迹象显示你应该当场聘用程序员
- 程序员应该避免六个常见的开发错误
- 程序员应该避免的坏习惯
- 作为一名java程序员,你应该注意避免哪些问题?
- 软件正在改变世界,程序员应该得到足够尊重
- 程序员应该知道的 13 个设计技巧