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:
func shouldNotBeEmpty() { // Noncompliant - method is empty
}
func notImplemented() { // Noncompliant - method is empty
}
func emptyOnPurpose() { // Noncompliant - method is empty
}
func shouldNotBeEmpty() {
doSomething();
}
func notImplemented() {
return "", errors.New("notImplemented() cannot be performed because ...")
}
func emptyOnPurpose() {
// comment explaining why the method is empty
}