However, I have to do my due diligence here. For most (all?) cases, using OpenStruct is a terrible anti-pattern. Any OpenStruct object will respond to any method you call on it and if it doesn’t exist, returns nil. This causes uncertainty within the system and makes testing a nightmare.
As I recommend to most people, you’re better off using a PORO (plain old ruby object)!
Thanks for sharing your precious experience with OpenStruct :-)
Anyway, the goal of my articles is just to describe a notion as deeply as possible.
I prefer to keep a neutral point-of-view because each notion that I describe can be useful in many cases.
Implementing the notion in real use cases is just a matter of sensitivity for each developer.
That’s why I’m glad that you share your opinion and your experience with the OpenStruct class here.
Why do you want that neutral position? One of the things I really love in articles is seeing how people evaluate the benefits and risks of tools like OpenStruct. I get to understand when to use or not use something, learn general strategies useful for other tools. Let the documentation be non-judgemental description, I want experienced opinions. :)
Actually my articles are made to demystify a misunderstood or opaque notion.
By doing so, developers can take the decision to apply the notion or not by knowing all the aspects of it.
Also, this enhances their general culture about the language.
After, your point of view is also correct. Maybe, in a near future I’ll start to share my experience with the notions that I treat in my articles.
Thanks for the feedback. It’s really appreciated :-)
Nice write up on the
OpenStructobject in ruby!However, I have to do my due diligence here. For most (all?) cases, using
OpenStructis a terrible anti-pattern. AnyOpenStructobject will respond to any method you call on it and if it doesn’t exist, returnsnil. This causes uncertainty within the system and makes testing a nightmare.As I recommend to most people, you’re better off using a PORO (plain old ruby object)!
And anima makes it very easy to avoid OpenStruct/Struct.
Nice! TIL!
Using OpenStruct can also kill your performance due to effects it has on the global method cache.
I thought so too, until a friend corrected me: That was fixed several years ago and isn’t still the case.
Thanks for sharing your precious experience with
OpenStruct:-)Anyway, the goal of my articles is just to describe a notion as deeply as possible. I prefer to keep a neutral point-of-view because each notion that I describe can be useful in many cases.
Implementing the notion in real use cases is just a matter of sensitivity for each developer.
That’s why I’m glad that you share your opinion and your experience with the
OpenStructclass here.I like reading about all the nooks and crannies about Ruby so your articles are very interesting to me! Thanks for sharing.
Why do you want that neutral position? One of the things I really love in articles is seeing how people evaluate the benefits and risks of tools like OpenStruct. I get to understand when to use or not use something, learn general strategies useful for other tools. Let the documentation be non-judgemental description, I want experienced opinions. :)
Actually my articles are made to demystify a misunderstood or opaque notion. By doing so, developers can take the decision to apply the notion or not by knowing all the aspects of it.
Also, this enhances their general culture about the language.
After, your point of view is also correct. Maybe, in a near future I’ll start to share my experience with the notions that I treat in my articles.
Thanks for the feedback. It’s really appreciated :-)