To be accurate, the title should be — don’t use NotImplementedError unless you write platform-specific low-level code.

Have you ever seen something similar to the following code?

class SomeAbstractClass
def some_method
raise“method should be implemented in concrete class”)

This code looks good and it even works most of the time, but using NotImplementedError here may be harmful.

The name of the exception can be so confusing that developers often misuse it and recommend this misinterpreted use to others online:

According to the Ruby documentation, a NotImplementedError is:

Ruby hashes are simple yet powerful data structures every Ruby-developer uses about ten times a day. Setting default values with the constructor feels intuitive and makes developers’ lives even easier. But overusing this language feature can lead to some surprises down the line — lots of fun debugging.

My journey into Ruby hashes and their default values started with the following code (this is the simplified version):

values_by_type ={[]}
some_values_list = [1, 2, 1, 2, 3]
some_values_list.each do |value|
type = 1
# some logic is omitted
if !values_by_type[type].include?(value) …

Oleg Potapov

Backend developer, interested in Ruby, Elixir, Postgres, Domain-Driven Development

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store