For the inline call caches in the interpreter loop, they are monomorphic, so if you call the same codepath with the decorator and the actual object, they will indeed flip flop.
The second layer of cache is class based, so after the inline cache is defeated you will end up doing a single hash-table lookup on the class.
As for YJIT, IIRC it does handle polymorphic call caches, so it won't mind such situation at all unless you have more than a handful of different implementations of that method being called at a given callsite.
I found Decorators just obscured display logic away in an inconvenient way.
(I'm personally so-so on VCs; I think the core idea is pretty good but I'm not super sold on some of the implementation details - too OOP, not enough `yield`)
<td class="<%= teacher.colour_coded_availability %>">
there would be <td class="<%= colour_coded_availability(teacher) %>">
but no metaprogramming, no decorators/ directory, no new concepts, only standard plain Rails. As a bonus it's even an instance of functional programming. (maximum_number_of_students <=> students.size).clamp(0..)
Holy... Is this better or worse than write-once perl regexes?Needlessly ugly way to write it imo though
I think they tried to be a bit too clever, basically.
But then I realized that's nonsensical, and not what the code is supposed to do given the usage in the template. I assume something got mangled there when changing the code for the blog post.
Or I'm just understanding the ruby code wrong despite checking just now in irb, in that case that's a point for the intention of your comment, and a vote for "worse".
[maximum_number_of_students - students.size, 0].max
IMHO, the whole idea of "design patterns" is that they are a standardized way of doing stuff. So that when someone, regardless of language, says "use an abstract factory" we know what it does, how it can be used, what it doesn't do, it's pitfalls etc.
What ruby calls "decorators" aren't "decorators". That's for this DIY implementation, but even more so for "Draper".
It's not only that an actual Decorator should not introduce new methods, but also how it's set-up and used. And therefore, what it's pitfalls and downsides are.
In the case of Draper or this DIY: the views now rely on a concrete and specific subclass - losing both LSP and DIP. Worse: the layer using it -views- aren't the one setting it up or controlling it - the controllers. So it introduces very hard dependencies between different domains - the views/partials/serializers now depend on whether or not you've remembered to actually decorate the model. Something that in my experience will go wrong and will crash in production - or if you're lucky and have lots of E2E tests, in CI.
The same "imprecise use of design patterns" happen with MVC, Models, ActiveRecord, "interfaces" and so forth. Often because of limitations of Ruby, but rather often because the Ruby community just uses the term "wrong".
wat.
If anything I think Rubys lack of limitations could be the issue. There's a thousand different ways to do anything, and people do.
So any design pattern, architecture or concept that relies on types, or interfaces, are "limited" in that sense. Ports, Adapters, Strategy, for example " require" interfaces in their definition. Their benefits rely on interfaces, so if a language lacks this, you really only get the downsides. Factory, Observer, Decorators, etc mention them, and use them, but can be implemented without them.
Maybe "limitations" isn't the best word, because e.g. "an interface" is a deliberate limitation, imposed and designed by the developer.
Maybe I'm misreading you, but I've never seen a definition of the Decorator pattern that doesn't involve new methods on the Decorator. If that's what you mean, can you say more? If not, what do you mean?
To disagree - Design patterns are a communication language. You use them to talk about code; if you use them as strict recipes they become dogma, with all the problems that entails.
Beyond that - most of the canonical design patterns are coping mechanisms for the limitations of pre-modern Java / strict OOP. You just plain don’t need them in a language like Ruby - IMO, mostly because of ‘yeild’.
The “imprecise use” is a consequence of either trying to use an unnecessary design pattern, or trying too dogmatically to adhere to one.
> Decorator subclasses are free to add operations for specific functionality. For example, ScrollDecorator’s ScrollTo operation lets other objects scroll the interface if they know there happens to be a ScrollDecorator object in the interface.
It should be:
def method_missing(name, *args, **kwargs, &block)
Starting from 3.1 it can be: def method_missing(name, ...)
<td class="<%= @teacher.available_places> 0 ? 'bg-colour-green' : 'bg-colour-red' %>">
inopinatus•1d ago
1. spend 30 minutes beating around the bush, reinventing the wheel etc for your own education and interest; then
2. throw that away and use SimpleDelegator from the standard library
and to be clear, I don’t mean this negatively at all.
pantulis•1d ago
byroot•21h ago
Mystery-Machine•20h ago