"Constants are "leaky abstractions" they expose to the outside world internal workings of a class that are not intended to be used as such." #Ruby
@nihilipster Meh I disagree with that entirely. If you use a member variable of a class marked as private (usually denoted by being prefixed by _ in languages where you can't enforce it) you deserve every breakage that comes to you. That method has worked just fine in many languages.
@nihilipster I don’t agree with this. Nothing is private/hidden in Ruby anyway. With that being the case, a constant shows the intent of the data.
You can change constants for testing, as well. This is shown with stub_const or any class mocks. Class names are constants too, and are able to be changed/mocked at test time.
String init isn’t the only issue, hash init still exists here. You can do away with that with memoization, but then lose the advantage of being collected.
Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.