Merge pull request #3 from smowton/smowton/fix/misleading-comment

Fix misleading comment in logicalOperators.go; expand on others
This commit is contained in:
Chris Smowton 2021-03-26 09:37:06 +00:00 коммит произвёл GitHub
Родитель 285c127615 b9a430471a
Коммит 6b4d5f65c7
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 5 добавлений и 5 удалений

Просмотреть файл

@ -75,7 +75,7 @@ func logicalAndElseBranchAlwaysBad2() {
if errorSource() == ErrNone && someOtherCondition() { if errorSource() == ErrNone && someOtherCondition() {
doSomething() doSomething()
} else { } else {
// Bad: On error we may enter either branch, but neither one returns. // Bad: there is no return statement at all.
insteadOfReturn() insteadOfReturn()
} }
doSomething() doSomething()
@ -85,7 +85,7 @@ func logicalAndElseBranchAlwaysBad2() {
func logicalAndThenBranchGood() { func logicalAndThenBranchGood() {
if someOtherCondition() && errorSource() != ErrNone { if someOtherCondition() && errorSource() != ErrNone {
// Good: whenever an error is indicated we return. // Good: whenever an error is indicated we return (note errorSource() is not called until someOtherCondition() passes)
return return
} }
doSomething() doSomething()
@ -95,7 +95,7 @@ func logicalAndThenBranchGood() {
func logicalAndElseBranchGood() { func logicalAndElseBranchGood() {
if someOtherCondition() && errorSource() == ErrNone { if someOtherCondition() && errorSource() == ErrNone {
// Good: whenever an error is indicated we return. // Good: whenever an error is indicated we return (note errorSource() is not called until someOtherCondition() passes)
doSomething() doSomething()
} else { } else {
return return
@ -154,7 +154,7 @@ func logicalOrThenBranchAlwaysBad() {
func logicalOrThenBranchGood() { func logicalOrThenBranchGood() {
if someOtherCondition() || errorSource() != ErrNone { if someOtherCondition() || errorSource() != ErrNone {
// Good: whenever an error is indicated we return. // Good: whenever an error is indicated we return. (note errorSource() is not called until someOtherCondition() fails)
return return
} }
doSomething() doSomething()
@ -164,7 +164,7 @@ func logicalOrThenBranchGood() {
func logicalOrElseBranchGood() { func logicalOrElseBranchGood() {
if someOtherCondition() || errorSource() == ErrNone { if someOtherCondition() || errorSource() == ErrNone {
// Good: whenever an error is indicated we return. // Good: whenever an error is indicated we return. (note errorSource() is not called until someOtherCondition() fails)
doSomething() doSomething()
} else { } else {
return return