Skip to content

Instantly share code, notes, and snippets.

@anhanh11001
Last active December 9, 2022 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anhanh11001/f2109775581eb71f775435c0d08ade52 to your computer and use it in GitHub Desktop.
Save anhanh11001/f2109775581eb71f775435c0d08ade52 to your computer and use it in GitHub Desktop.
// The code below is a perfectly formatted code regardings to ktlint
// To compare with ktfmt, copy this and format it in https://facebook.github.io/ktfmt/index.html
// Please decide yourself whether you think one is better than the other, comment below is my personal preferences
// Cases where I think code looks good before reformatting (💪 ktlint 💪)
fun aFuncName(
inputOne: String,
inputTwo: String,
inputThree: Boolean
): String {
val result = if (inputThree) {
inputOne
} else {
inputTwo
}
val appInfo = mapOf(
"appinfo.info1" to "info_001",
"appinfo.info2" to "info_002",
"appinfo.info3" to "info_003",
"appinfo.info4" to "info_004",
"appinfo.info5" to BuildConfig.VERSION_NAME,
)
if (params.useLogicOne == null)
doAFunctionWithData(data)
else
doAnotherFunctionWithMoreData(data1, data2, data3)
return result
}
private fun createSomeOption(
params: InformationParams,
params2: InformationParams,
) = SomeOption.newBuilder().apply {
information1 = true
information2 = params.type == Type.CRAZY_ONE
information3 = params.type == Type.AMAZING_INCREDIBLE_ONE
information4 = params.type == Type.CRAZY_TWO || params.type == Type.CRAZY_THREE
information5 = params.type == Type.CRAZY_FOUR
information6 = params.type
doSomethingWithInformation = params.doValidate
}.build()
// Cases where I think code looks good after reformatting (💪 ktfmt 💪)
val longBuilder =
SomeOption.Builder().append(info1).append(info2).append(info3).append(info4).append(info5).append(info6)
fun randomFun(
)
// See more other cases of ktfmt in this README: https://github.com/facebook/ktfmt
// I personally think some cases are really extreme in the sense that it's clearly bad unreadable code.
// I don't expect decent dev write those kind of code and I don't it would even reach the formatter.
// This can be seen as wishful thinking. I can be wrong!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment