Yeah, I think that’s a better way to describe this - I don’t really understand what is “transparent” about this, as it requires some custom machinery to implement plus cognitive overhead to use.
I think the idea is that it’s transparent because the get_feed api somehow passes these lambdas through to customize behavior, rather than having the method itself apply the customizations.
I’m not entirely sold by the example, since there’s only two places to be tweaked, and they could be a pass-through fetch_options dictionary and split-into-two-methods-in-the-first-place respectively.
From what I understand it’s “just” dependency injection with first class functions at the end of the day (not to discredit it, it’s a powerful idea — as Greenspun would call: half of Common Lisp). So you could create a function which accepts other functions and substitute those functions when appropriate.
But I’d say that’s probably not the most Go-like way of doing it. You eventually need to add function constructors (functions that return other functions) and it’s starts to become harder to read/understand. The language doesn’t really want you to write that kind of code. Interfaces or the functional options pattern would look more at home with Go.
This is not obvious to me.
Looking at the example code
How does the caller know that fetch__encoding is an option?
isn’t this a form of dependency injection? Also, I’d love to see how is that decorator implemented
Yeah, I think that’s a better way to describe this - I don’t really understand what is “transparent” about this, as it requires some custom machinery to implement plus cognitive overhead to use.
The decorator is defined here: https://github.com/iommirocks/iommi/blob/master/iommi/declarative/dispatch.py
The parsing of the
<name1>__<name2>-style arguments is done in a customNamespaceclass defined here: https://github.com/iommirocks/iommi/blob/master/iommi/declarative/namespace.pyTheir project has a section on using underscores to traverse namespaces. I can’t say that I’m personally a fan of this, but can see where they’re coming from.
I think the idea is that it’s transparent because the get_feed api somehow passes these lambdas through to customize behavior, rather than having the method itself apply the customizations.
I’m not entirely sold by the example, since there’s only two places to be tweaked, and they could be a pass-through
fetch_optionsdictionary and split-into-two-methods-in-the-first-place respectively.how would something like this look like when writing go?
From what I understand it’s “just” dependency injection with first class functions at the end of the day (not to discredit it, it’s a powerful idea — as Greenspun would call: half of Common Lisp). So you could create a function which accepts other functions and substitute those functions when appropriate.
But I’d say that’s probably not the most Go-like way of doing it. You eventually need to add function constructors (functions that return other functions) and it’s starts to become harder to read/understand. The language doesn’t really want you to write that kind of code. Interfaces or the functional options pattern would look more at home with Go.
Am I alone in thinking they reinvented Ruby methods in Python