Skip to content

Instantly share code, notes, and snippets.

@anacrolix
Created January 9, 2018 03:20
Show Gist options
  • Save anacrolix/d5cb2dbc50ebbc167187fa439998d4bb to your computer and use it in GitHub Desktop.
Save anacrolix/d5cb2dbc50ebbc167187fa439998d4bb to your computer and use it in GitHub Desktop.
condition style
// which would you do? comment below
// distinct ifs
if n == 1 {
single()
}
if n > 1 {
multi()
}
// else if
if n == 1 {
single()
} else if n > 1 {
multi()
}
// switch
switch {
case n == 1:
single()
case n > 1:
multi()
}
@anacrolix
Copy link
Author

Plus the logic does not become entangled. single is called if n is 1, and multi if n is > 0, and three if n == 3.

@i-like-bikes
Copy link

single is called if n is 1, and multi if n is > 0, and three if n == 3.

typo that mutli is called if n > 0 :)
context is needed, as should multi and three both be called if n == 3?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment