Skip to main content
added 46 characters in body
Source Link
Legato
  • 9.8k
  • 4
  • 49
  • 116

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference for writing what you have and reasoning forbehind it.

String message = ( 
       !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns on the same line.

Without more information I can't be too specific, but from the comments below your question, it seems like this would ideally be fully encapsulated into its own Trip class. In which validate is a method, or the constructor itself handles validation before instantiating the object.

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.

Without more information I can't be too specific, but from the comments below your question it seems like this would ideally be fully encapsulated into its own Trip class. In which validate is a method, or the constructor itself handles validation before instantiating the object.

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference for writing what you have and reasoning behind it.

String message = ( 
       !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns on the same line.

Without more information I can't be too specific, but from the comments below your question, it seems like this would ideally be fully encapsulated into its own Trip class. In which validate is a method, or the constructor itself handles validation before instantiating the object.

added 285 characters in body
Source Link
Legato
  • 9.8k
  • 4
  • 49
  • 116

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.

Without more information I can't be too specific, but from the comments below your question it seems like this would ideally be fully encapsulated into its own Trip class. In which validate is a method, or the constructor itself handles validation before instantiating the object.

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.

Without more information I can't be too specific, but from the comments below your question it seems like this would ideally be fully encapsulated into its own Trip class. In which validate is a method, or the constructor itself handles validation before instantiating the object.

deleted 1 character in body
Source Link
Legato
  • 9.8k
  • 4
  • 49
  • 116

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. ThewThe && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. Thew && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.

To my knowledge there isn't a standard for this, but since it's a formatting question I'll address my preference and reasoning for it.

String message = ( 
    !isNameBlank
    && !isDestinationBlank
    && isDestinationValid
    && isAmountValid)
? "Have a safe trip!" : "Please try again!";
  1. variable declaration includes open parentheses and indicates something follows and is reminiscent of similar style for code blocks.
  2. Each clause is on its own line which makes them both easily readable and modifiable regardless of the statement length.
  3. The && and || operators are at the beginning of the line, this is conventional and preferable when clause names are long, or nested
  4. Ternary operator is lined up to initial declaration indicative of its end, and precedes the typical two returns.
Source Link
Legato
  • 9.8k
  • 4
  • 49
  • 116
Loading