An empty function is generally considered bad practice and can lead to confusion, readability, and maintenance issues. Empty functions bring no functionality and are misleading to others as they might think the function implementation fulfills a specific and identified requirement.
There are several reasons for a function not to have a body:
fun shouldNotBeEmpty() { // Noncompliant - method is empty
}
fun notImplemented() { // Noncompliant - method is empty
}
fun emptyOnPurpose() { // Noncompliant - method is empty
}
fun shouldNotBeEmpty() {
doSomething()
}
fun notImplemented() {
throw UnsupportedOperationException("notImplemented() cannot be performed because ...")
}
fun emptyOnPurpose() {
// comment explaining why the method is empty
}