-Поиск по дневнику

Поиск сообщений в rss_thedaily_wtf

 -Подписка по e-mail

 

 -Постоянные читатели

 -Статистика

Статистика LiveInternet.ru: показано количество хитов и посетителей
Создан: 06.04.2008
Записей:
Комментариев:
Написано: 0


CodeSOD: Two Knowing Comments

Вторник, 16 Марта 2021 г. 09:30 + в цитатник

Sometimes, it really is the comment which makes the code. Sometimes, the comments make simple (but still more complex than it needs to be) code less clear.

For example, Thomas provides this code, and comment, which… I understand what is happening here, despite the comment:

/// /// A class file for find the mid value /// public class a { string[] s2 = null; /// /// mid function is to cut the some values from the text which we had given /// /// The offset number /// Number of chars to read from the test /// The string that has to be splited /// returns a string array public string[] mid(int offset, int numcharstoread, string s) { int j = 0; for (int i = numcharstoread; i < offset; i++) { char ch = s[i]; this.s2[j] = Convert.ToString(ch); j++; } return this.s2; } }

It's a substring function. I understand that just from the name: mid. But if I read the comments, I get less confident that it's a substring function. It's also a substring function which relies on class state, treats the substring as an array, and at least with this snippet, wouldn't work (because s2 is null and never gets initialized).

Other times, however, the comment is a perfectly clear summary of how we should feel about some code.

Kerin writes: "This is in the production codebase for an application that I support. Every time I look at it, I die a little more."

function local_luxSheetVoodoo(){ return true; //yes i know, don't email me }

I need to add this to pretty much every line of code I write, I think.

[Advertisement] ProGet’s got you covered with security and access controls on your NuGet feeds. Learn more.

https://thedailywtf.com/articles/two-knowing-comments

Метки:  

 

Добавить комментарий:
Текст комментария: смайлики

Проверка орфографии: (найти ошибки)

Прикрепить картинку:

 Переводить URL в ссылку
 Подписаться на комментарии
 Подписать картинку