It is not what you expect, but it is what you want: how Data#initialize is designed
A curios core class design decision made for happier coding.
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
A curios core class design decision made for happier coding.
Comments
First thanks for all your great work. May I disagree - you are NOT getting ruby - it is about options and everyone expects Data to work like Struct. Sorry. Even if you write: “This is somewhat unexpected (and was already several times reported as a bug in the official tracker!), but designed this way for a good reason.” Also if I may note and I remember you are not really a fan of rails “magic” and now you are addding some kind of “magic” between new and initialize that no one expects. Anyways, happy new year. Prosit 2023!
It’s very bold to say that Victor is “not getting ruby”, considering all his valuable contributions to the Ruby language; I don’t think there are many people that have such a deep feeling for Ruby’s design as Victor does. What language features did you develop/contribute to? Where was your input when the
Data
class was being designed?For me it was an interesting idea to solve positional vs keyword arguments at the
.new
level, rather than at the#initialize
level, because you’ll only be overriding the latter. If people are usingData
and expecting it to work exactly likeStruct
, then they should’ve been usingStruct
instead. I would useData
because of its differences fromStruct
, I want that more focused design.If I’m overriding
#initialize
, I can imagine that in practice I don’t want to be dealing with positional vs keyword arguments. I want positional arguments to just be an alternative syntax for callers, but I don’t want to have to handle that when I’m overriding#initialize
, I don’t see any benefit in doing so.It’s very bold to say that Victor is “not getting ruby”, – Victor is not getting the ruby philosophy that is the human dimension of offerings / embracing alternate ways in contrast to the supposed python philosophy of “there is only one way” - and forbidding positional argument in initializers is kind of not getting ruby and not what ruby oldies expect (thus, the error reports that get hand-waved and ignored). Read up on here https://bugs.ruby-lang.org/issues/19278, for example.
considering all his valuable contributions to the Ruby language; I don’t think there are many people that have such a deep feeling for Ruby’s design as Victor does
Ask Victor about his choice / recommendations for testing , that is, ruby-esque minitest or rspecs. As far as I can remember Victor is a fanatic of rspec that even wants to kill-off any alternatives such as minitest et al. Anyways, all I am trying to say is that it’s not all black & white and Victor is a functional programming fanatic (and these guys usually are too strict) - yes, an irony if you are coding in ruby and expecting the language to restrict and enforce your thinking …
What language features did you develop/contribute to?
If you compare -> https://rubygems.org/profiles/zverok - 32 gems; my humble self -> https://rubygems.org/profiles/geraldbauer - 239! Draw your own conclusion.
PS: Okkie - you might say that is apples and oranges comparing gems. How about designing a ruby language itself ;-) e.g. Small, Smart, Secure, Safe, Solid & Sound (S6) Ruby see https://github.com/s6ruby
Anyways, let’s focus on core issue - Brooke Kuhlmann writes:
There is one major disadvantage which has to do with overriding the #initialize method in that in only accepts keyword parameters. It’s an odd and surprising design choice. See https://www.alchemists.io/articles/ruby_data/
Let’s repeat odd and surprising design choice for what Victor proudly reports as “a core design decision made for happier coding”.
tenderlovemaking (Aaron Patterson) writes:
Struct seems to behave in the way I would expect, so I will just use that (or write regular POROs).
Sorry, I think you [Victor] misunderstood. I understand your points, I am just out of steam and don’t care to continue the thread anymore [arguing about your bad design decsion that you try to enforce in ruby].
Post a comment