DEV Community

Cover image for Code Smell 12 - Null
Maxi Contieri
Maxi Contieri

Posted on • Updated on • Originally published at maximilianocontieri.com

Code Smell 12 - Null

Programmers use Null as different flags. It can hint an absence, an undefined value, en error etc.
Multiple semantics lead to coupling and errors.

TL;DR: Null is schizofrenic and does not exist in real world. His creator regreted and programmers around the world suffer it. Don't be a part of it.

Problems

  • Coupling among the callers and the senders.

  • Mismatch among the callers and the senders.

  • If/Switch/Case Polluting.

  • Null is not polymorphic with real objects. Hence, Null Pointer Exception

  • Null does not exist on real world. Thus, it violates Bijection Principle

Solutions