Skip to content

Lee-WonJun/codedhardcoding

Repository files navigation

codedhardcoding

// comment is not enough

Inspired by the functionality of Clojure's comment macro, CodedHardcoding brings a similar concept to the Kotlin ecosystem, enabling developers to easily manage their code blocks for various purposes.

Comments are useful, but sometimes they fall short. When it comes to temporary code modifications, comments tend to be overlooked and become harder to find as time passes.

Components

hardcode

Use the hardcode function to execute a block of code and return its result:

val hardcodedValue = hardcode {
    "Hardcoded String"
}
println(hardcodedValue) // Output: Hardcoded String

comment

Use the comment function to ignore a block of code and not execute it:

comment {
    println("This code will not be executed.")
}

dev

Use the dev function to execute a block of code and print the result along with the calling class and method information:

class Example {
    fun test() {
        val result = dev {
            "Development String"
        }  // Output: dev: Development String In Example.test
        
        println(result) // Output: Development String
    }
}

Comparison

fun before() {
    // urls is hardcode
    val urls = listOf("https://www.google.com", "https://www.bing.com")

    //  urls.map { it.toInt() }  // temporary comment out

    val googleUrl = urls.first()
    println(googleUrl) // temporary print out
}

fun after() {
    val urls = hardcode { listOf("https://www.google.com", "https://www.bing.com") }
    
    comment { urls.map { it.toInt() } }
    
    val googleUrl = dev { urls.first() }
}

Benefit

  • You can benefit from rich IDE assistance. image

  • You can manage comments in a compilable form. image image

About

/* comment is not enough */

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages