# Code Smell 217 - Empty Implementation

*You create empty methods instead of failing*

> TL;DR: Don't fill in methods to comply

# Problems

- Fail Fast Principle Violation

# Solutions

1.  Throw an error indicating implementation is not complete

# Context

Creating an empty implementation might seem fine to jump to more interesting problems. 

The code left won't fail fast so debugging it will be a bigger problem

# Sample Code

## Wrong

[Gist Url]: # (https://gist.github.com/mcsee/56e55a0fdee9d223fc050652b298f699)
```javascript
class MerchantProcessor {
  processPayment(amount) {
    // no default implementation
  }
}

class MockMerchantProcessor extends MerchantProcessor {
  processPayment(amount) {
     // Empty implementation to comply with the compiler
     // Won't do anything
  }
}
```

## Right

[Gist Url]: # (https://gist.github.com/mcsee/77dcf4848f489f7011aefbe4971d4b0a)
```javascript
class MerchantProcessor {
  processPayment(amount) {
    throw new Error('Should be overridden');
  }
}

class MockMerchantProcessor extends MerchantProcessor {
  processPayment(amount) {
     throw new Error('Will be implemented when needed');
  }
}

// or better...

class MockMerchantProcessor extends MerchantProcessor {
  processPayment(amount) {
    console.log('Mock payment processed: $${amount}');
  }
}

```

# Detection

[X] Manual

Since empty code is valid sometimes only a good peer review will find these problems.

# Tags

- Hierarchies

# Conclusion

Being lazy and deferring certain decisions is acceptable, but it's crucial to be explicit about it.

# Relations

%[https://maximilianocontieri.com/code-smell-30-mocking-business]

%[https://maximilianocontieri.com/code-smell-114-empty-class]

# More Info

%[https://maximilianocontieri.com/fail-fast]

# Disclaimer

Code Smells are my [opinion](https://maximilianocontieri.com/i-wrote-more-than-90-articles-on-2021-here-is-what-i-learned).

# Credits

Photo by [Joey Kyber](https://unsplash.com/@jtkyber1) on [Unsplash](https://unsplash.com/photos/45FJgZMXCK8)
    
* * *

> There is an art to knowing where things should be checked and making sure that the program fails fast if you make a mistake. That kind of choosing is part of the art of simplification.

_Ward Cunningham_

%[https://maximilianocontieri.com/software-engineering-great-quotes]

* * *

This article is part of the CodeSmell Series.

%[https://maximilianocontieri.com/how-to-find-the-stinky-parts-of-your-code]
