3 ms·
I agree with the article, yet, despite what the table at the end suggest I got significantly less problems with NullPointerExceptions since I switched from Java
by aurelian15 11y ago
I agree with the article, yet, despite what the table at the end suggest I got significantly less problems with NullPointerExceptions since I switched from Java to C++ for my work.
C++ has an inbuilt alternative: references. References in conjunction with the Null Object Pattern have solved my problems until now.
References simply cannot be null -- and I generally do not use raw pointers in my code unless some library forces me to.
- _yosefk 11y agoA null pointer can be dereferenced into a "null reference" which can be passed around, however. Theoretically UB, in practice, typically represented identically to the null pointer and behaves the same when used. Still helps in that the null bug root cause can hide in less places (modulo memory overwriting which adds root causes unimaginable in Java)