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

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

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

 

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

 -Статистика

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


CodeSOD: Count on Me

Понедельник, 14 Декабря 2020 г. 09:30 + в цитатник

There is no task so simple that a developer can't find a harder, more wasteful, and pointless way to do it. For example, let's say you want to know how many rows are in a data grid object?

Hans found this C# snippet in production a few years ago:

int count = 0; for(int i = 0; i <= dgView.Rows.Count; i++) { count++; }

To find out how many rows are in our dgView, we start a for loop which counts from 0 to the… Rows.Count in the view. Worse, this has an off-by-one bug, as they use <= to compare, ensuring an extra iteration.

The old saying is "work smarter, not harder," but this code doesn't just work harder, it also works dumber.

[Advertisement] Otter - Provision your servers automatically without ever needing to log-in to a command prompt. Get started today!

https://thedailywtf.com/articles/count-on-me

Метки:  

 

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

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

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

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