Encapsulate Boundary Conditions

Putting boundary conditions/checks in a function keeps you from having to rewrite said cases in multiple places. The more places they are hard coded the more places you have to accidently miss them and add off-by-one bugs.

if (level + 1 < tags.length) {
  parts = new Parse(body, tags, level + 1, offset + endTag)

vs

int nextLevel = level + 1;
if (nextLevel < tags.length) {
  parts = new Parse(body, tags, nextLevel, offset + endTag);

Adding nextLevel prevents us from having to write level + 1 twice which reduces the chance of adding bugs/errors.



bj 2019-09-22