On 1/6/21 9:19 AM, Paavo Helde wrote:
> 06.01.2021 00:47 Öö Tiib kirjutas:
>> On Tuesday, 5 January 2021 at 15:45:54 UTC+2, ijw wij wrote:
>>>>>
>>>>> Presumably in the production version they're disabled by a build
>>>>> option?
>>>> Yes, in release builds these are disabled, both for speed and for
>>>> avoiding spurious false alarms (when you write thousands of asserts,
>>>> some of those are bound to be buggy (i.e. over-cautious)).
>>> Funny!
>>
>> No, it is just human nature. We are all ignorant about some aspect,
>> misremembering, absent minded, tired and fallible. We just learn,
>> memorize, recall, concentrate our focus and correct if we notice
>> as we go.
>
> Agreed.
>
> Here we are talking about assert lines which are themselves meant for
> validating other code. If I leave them in in the production, then
> someone would need to take extra care of validating of validations.
Agreed on the agreement :)
I like the "validate the validation" part.
>
>> When dealing with code base of hundreds thousands
>> of lines it is important to let every line you altered to be validated
>> by other people as it will catch most issues earlier.
>
> In my experience, no. Validating my code by myself by writing assert
> lines has detected much more bugs in my code than code review by other
> people.
I am also a fan of asserts - I tend to spread them around a lot, and I
agree that as far as debugging goes they are probably more effective
than code reviews - probably related with my programming habits.
Nonetheless code reviews do have their value, especially with respect to
code maintainability - some extra pairs of eyes /can/ make code more
clear and readable. They can occasionally spot mistakes, if the
reviewers are member of the same team that share knowledge about the
problem domain.
Reviews in general, however, are /very/ useful, especially when working
in team.
>
> This probably also depends on the project type. Imagine implementing
> something like JPEG compression algorithm, what are the chances a human
> reviewer would notice an one-off mistake somewhere deep in the algorithm?
This is also true, the problem domain plays a significant role in
asserts' effectiveness. I guess because of how it impacts code structure.