An empty method is generally considered bad practice and can lead to confusion, readability, and maintenance issues. Empty methods bring no functionality and are misleading to others as they might think the method implementation fulfills a specific and identified requirement.
There are several reasons for a method not to have a body:
def shouldNotBeEmpty() = { // Noncompliant - method is empty
}
def notImplementedYet() = { // Noncompliant - method is empty
}
def willNeverBeImplemented() = { // Noncompliant - method is empty
}
def emptyOnPurpose() = { // Noncompliant - method is empty
}
def shouldNotBeEmpty() = {
doSomething()
}
def notImplementedYet() = {
throw new NotImplementedError()
}
def willNeverBeImplemented() = {
throw new UnsupportedOperationException()
}
def emptyOnPurpose() = {
// comment explaining why the method is empty
}