Image for post
Image for post

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 NotImplementedError.new(“method should be implemented in concrete class”)
end
end

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:

https://stackoverflow.com/questions/13668068/how-to-signal-not-implemented-yet

https://github.com/rubocop-hq/ruby-style-guide/issues/458

According to the Ruby documentation, a NotImplementedError is:

Raised when a feature is not implemented on…


Image for post
Image for post

Ruby hashes are simple yet powerful data structures every Ruby-developer uses about ten times a day. Setting default values with the Hash.new 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 = Hash.new(){[]}
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