juan_gandhi: (Default)
Juan-Carlos Gandhi ([personal profile] juan_gandhi) wrote2021-12-10 07:54 pm

а я вот что понял

Я первый год в Америке кюеем работал. В те поры девелоперы тестов не писали, это им было западло. И я валял кучу всяких тестов (большинство пойманных мной багов пережили крах Борланда, и теперь живут на небесах). Но следующие шесть лет в Борланде я имел репутацию Этого Странного Кюея. Это там была порядочная толпа идиотов (ну, какие полиформизмы бывают, не знают, но спорить с ними бесполезно, т.к. ты Странный Кюей, а он аж Старший Инженер). Хрен с ними; была и масса больших талантов. Некоторые из них сейчас в колледжах преподают программирование, а кто-то в автогонщики подался; кто-то умер; одна пошла выучилась на врача.

Так вот только недавно я начал понимать, какой это был (бес)ценный опыт. Потому что обычные программисты, без опыта тестирования - они вроде юзеров. Тыкают пальчиком, вдруг заработает.  

Не, я не предлагаю ссылать в кюеи на год (да и дураков нет, они пойдут в другую контору, где их будут ценить). Но чисто для себя.

Ну это как, пойдя в матросы, лучше научиться уже плавать, заранее, а не когда на море качка.

dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-13 02:24 am (UTC)(link)
> софт пытался распарсить, и, по обычаю джавщиков, вернул null

Если мы ожидаем null, как один из нормальных результатов - придется писать код для этого случая.
И расширять unit test [with null value test case].

> Рассчитывать, что все наши параметры адекватные? Я не возражаю, если просто бросать исключение.

Именно так: если метод не поддерживает какой-то диапазон - throw exception.
Тогда и unit test для такого случая не нужен.

И если этот exception случается - значит нужно дописывать код.

dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-13 12:45 pm (UTC)(link)
> оно бросит эксепшен

Да, но только если это неожиданное событие произойдет.

> или вернет дату обрезания Христа

Кто "вернет дату обрезания Христа"?
dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-14 06:30 am (UTC)(link)
> Программа. Дату не распарсили, возвращаем 01.01.0001.

Обычно лучше, если программа throws an exception если распарсить не получается.
Либо какой-нибудь сигнал о том, получилось ли распарсить.

Re: Unit tests for null and negative values?

[personal profile] sassa_nf 2021-12-13 08:03 am (UTC)(link)
how did Y2K happen then?
dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-13 12:52 pm (UTC)(link)
Eventually, time reached new edge condition and caused Y2K.

The obvious fix is to extend functionality to support that new date edge case (years 2000+).

Re: Unit tests for null and negative values?

[personal profile] sassa_nf 2021-12-13 01:20 pm (UTC)(link)
Yes, but the problem was that most of the code did not test for this condition at all, and would neither treat correctly, nor throw. So if you don't test that the method throws on invalid inputs, you are in the same boat as Y2K.
dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-13 01:39 pm (UTC)(link)
> would neither treat correctly, nor throw.

I suggest to throw in case of null [as a default choice in version 1 of the software].

> if you don't test that the method throws on invalid inputs, you are in the same boat as Y2K

1) If I have throwing code, the "throw" part is likely to work even if I do not have unit tests that check for that "throw" behavior.

2) Being "in the same boat as Y2K" -- is not the worst place to be.
That software with Y2K holes in it -- generated a lot of revenue over 10-30 years prior to Y2K event.
dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-14 07:00 am (UTC)(link)
> not 30 years prior, not even 20

Do you mean that almost no software that was working in 1999 was written prior to 1980?
dennisgorelik: 2020-06-13 in my home office (Default)

30 years prior to Y2K

[personal profile] dennisgorelik 2021-12-14 04:01 pm (UTC)(link)
> I mean that nobody worried about Y2K in 1970 or in 1980

Yes.
They worried about creating working product and growing sales.
Then a tiny slice products that survived until 2000 -- had to be patched (Y2K).
dennisgorelik: 2020-06-13 in my home office (Default)

Re: Unit tests for null and negative values?

[personal profile] dennisgorelik 2021-12-14 06:58 am (UTC)(link)
Do you think in 2037 we should expect another problem with overflowing some dates?