Re: assert not for public methods
От: insighter ОАЭ  
Дата: 10.01.14 16:06
Оценка:
Здравствуйте, Hard_Club, Вы писали:

H_C>Недавно прочитал в одной книге, что с помощью assert нельля проверять аргументы в публичных методах, т.к. его можно оключить, а public-методы должны всегда проверять входящие параметры. Откуда взялось такое правило? Кто его установил?


http://stackoverflow.com/a/1957656

Assertions are designed to be cheap to write, you can use them almost everywhere and I'm using this rule of thumb: the more an assertion statement looks stupid, the more valuable it is and the more information it embeds. When debugging a program that does not behave the right way, you will surely check the more obvious failure possibilities based on your experience. Then you will check for problems that just cannot happen: this is exactly when assertions help a lot and save time.


согласен с выделенным, сдается мне что именно из этих соображений Блох и компания добавила их в язык.
java шараги -> enterprise галеры, банки -> highload microservices + bigdata/ml
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.