DEV Community

Discussion on: How do you handle the disposable IF statements ?

Collapse
 
juancarlospaco profile image
Juan Carlos

This completely removes the code, using dead code elimination, at compiletime:

when conditionThatsRarelyTrue:
  discard

For runtime alternative, compiler uses branch optimization:

if unlikely(conditionThatsRarelyTrue):
  discard
elif likely(conditionThatsUsuallyTrue):
  discard
else:
  discard

The likely() will be faster, the unlikely() will be slower.
This is Nim lang.