DEV Community

Discussion on: Don't be afraid to expand your code for readability

Collapse
kevinrstone711 profile image
Kevin R Stone

Separating complex conditionals into their own function is a great choice. Once inside I think code format is less important than having tests.
Additionally, this format can work too.

function shouldSave(doc) {
   return doc.hasChanged && 
          !doc.isReadOnly && 
          fs.hasFreeSpace && 
          user.wantsToSave;
}

Collapse
andrespineros profile image
Andrés Felipe Piñeros

Right, and if you want to debug, just print the values of the variables inside the shouldSave(doc) function.