3 ms·
If the assumptions made by the code are wrong, the code is wrong. I would agree with you if the code would preprocessor-check ULONG_MAX and #error out if it is
by layer8 4y ago
If the assumptions made by the code are wrong, the code is wrong.
I would agree with you if the code would preprocessor-check ULONG_MAX and #error out if it isn’t the expected value.
- marginalia_nu 4y agoThe code isn't making assumptions, the programmer is.
- layer8 4y agoThat’s all the same. Then the code the programmer is writing is wrong because the programmer’s assumptions are wrong. Potato, potahto.
- marginalia_nu 4y agoThere's actually a fairly big difference with the context of the language preventing the error. If the code is wrong as in undefined behavior, then the compiler can and maybe should try to prevent it. If the programmer is wrong about the code, then the compiler can't and definitely shouldn't try to prevent it. In short, the compiler can't prevent this int is_empty(char* s) { return strlen(s) > 10; } The compiler maybe could prevent this: is_empty(NULL);
- dahfizz 4y agoIts not the same. The compiler can protect against code which is incorrect. The compiler cannot do anything to help with code that is correct but does the wrong thing.