A few recommended best practices related to the if-else statement and switch
statement are as follows:
Always use positive logic e.g. write if (true) rather than if (! false).
Prefer switch statement rather than multiple if-else statements.
Always end a case with a break or return or throw statement unless a fall
through mechanism is intentionally used. When a fall through mechanism
is used a comment should be given like //fall through so that it is clear to
every reader.
statement are as follows:
Always use positive logic e.g. write if (true) rather than if (! false).
Prefer switch statement rather than multiple if-else statements.
Always end a case with a break or return or throw statement unless a fall
through mechanism is intentionally used. When a fall through mechanism
is used a comment should be given like //fall through so that it is clear to
every reader.
No comments:
Post a Comment