The classic “null pointer exception” happens when we try to access some object tha is null. This might be a problem in a first look, but it delivers an advantage:

  1. A java program will never cause a “Segmentation Fault”, i.e it can always keep running (if you try/catch the exceptions). The program will never crash.

However, this avoidance of segmentation faults essentially means that java is checking our memory integrity in runtime.

  • This also means, that for all object access that java code will do, an implicit “if” is addedd. This “if” wrappers the “memory-access” responsible function, to check if the object is not null, before any access attempt occurs .

“Java is simply a language that prefers LBYL over EAPL”

  • Meaning: you look before you leap, instead of asking for foreignness instead of permission.

https://devblogs.microsoft.com/python/idiomatic-python-eafp-versus-lbyl/


🌱 Back to Garden