DEV Community

Discussion on: short-circuits && clean code

Collapse
 
evanoman profile image
Evan Oman • Edited

My answer after reading the title: sure, short-circuiting is a handy tool sometimes.

My answer after reading that snippet: dear god kill it with fire.

I think short-circuiting is fine as long as it is still performing a normal boolean operation -- they should never be used to run arbitrary code.

I would avoid anything more complicated than something like

boolean fileIsValid = file.exists() && !file.isEmpty()