What would be the most readable / best way to write multiple conditional checks like the one below?
Two possibilities that I could think of (this is Java, but this language doesnβt really matter):
Option 1:
boolean c1 = passwordField.getPassword().length > 0; boolean c2 = !stationIDTextField.getText().trim().isEmpty(); boolean c3 = !userNameTextField.getText().trim().isEmpty(); if (c1 && c2 && c3) { okButton.setEnabled(true); }
Option 2:
if (passwordField.getPassword().length > 0 && !stationIDTextField.getText().trim().isEmpty() && !userNameTextField.getText().trim().isEmpty() { okButton.setEnabled(true); }
What I don't like about option 2 is that the line wraps around and then the indentation becomes a pain. What I don't like about option 1 is that it creates variables for nothing and requires a search in two places.
And what do you think? Any other options?
language-agnostic coding-style conditional-statements
JRL
source share