This is a sort of DSL, but it doesn't really give us any more clarity than traditional allow/disallow arrays, does it?
It's this:
+ url("your-url-here")
versus this: allowed << url("your-url-here")
Why is the former more attractive?This is a sort of DSL, but it doesn't really give us any more clarity than traditional allow/disallow arrays, does it?
It's this:
+ url("your-url-here")
versus this: allowed << url("your-url-here")
Why is the former more attractive?As a configuration language, it might be.
Building up an object system like this for simple configuration seems excessive to me.
I would do something like this:
c = YAML.load_file 'config.yml'
allowed, disallowed = c['allowed'], c['disallowed']Data is code is data, avoids having to write a parser (or even reuse an existing one), avoids having to resolve the impedance mismatch between the programming language and the configuration language, scales up infinitely in case the user needs more power (which is not that rare, especially for a rules system which is the use case here)
> I would do something like this:
> c = YAML.load_file 'config.yml' > allowed, disallowed = c['allowed'], c['disallowed']
Now you have two superfluous lines in your code and you have not gained anything of value.
> Data is code is data.
This is hardly a case of homoiconicity, is it?
You need that code to load/create rules in any case, but for you it's done from a config file which the user writes. For TFAA, the user loads his data directly into the running system. Therefore the layer you have to setup between the config file and the actual running code (parsing the config file then interpreting its values to translate them into a running ruleset) is superfluous: you can do without it.
Because you know, your "example" YAML parsing is useless in and of itself, it doesn't result in a working ruleset, you skipped the whole part where you feed that data to your code and setup the stuff that actually does work.
TFAA removes the parsing and interpretation from the chain and instead lets the user feed data directly to the running code without layers inbetween.
Because you know, your "example" YAML parsing is
useless in and of itself, it doesn't result in a
working ruleset, you skipped the whole part where you
feed that data to your code and setup the stuff
that actually does work.
Sorry, but that's not actually the case, is it? There is no "business logic" in his example. To actually use the config system he's set up, you need to evaluate Rule#charge for every rule you want to evaluate. In my example, all you could run allowed.include? or simply iterate over the allowed array.____
Church: you can represent data using functions/function application.
Historic example: Church encoding of the natural numbers.
Day to day example: The hash table and the array are in fact pure functions.
____Turing: the input of a machine (data) can be used to carry computations.
Historic example: the Turing machine (duh :-)
Day to day example: from machine language to Coffeescript.Why? And why would you draw that distinction for unary operators but not binary ones? Could it be just out of habit, because you've seen binary operators overloaded to mutate operands before but have never seen that with unary ones?
If the language implements unary operators as regular methods/messages (rather than special forms) why couldn't they be overloaded in the same way binary operators are, as long as it makes sense and reads correctly? (and in this case it certainly does)
I wouldn't -- I think it's wrong for binary operators too.
allow url("your-url-here")
(with reject or something similar for the opposite).You could even drop the url method and simply write
allow "your-url-here"
if you only need to allow/disallow based on URLs.