
Introduction
Some days ago I found a course about computer science called Structure and Interpretation of Computer Programs, and I've be...
For further actions, you may consider blocking this person and/or reporting abuse
Data-driven programming can probably have different meanings, but here is the one I use it for: it is a style of programming in which specialization is done through data structures and not boilerplate code.
You can learn many programming languages here: hackr.io/
Examples are probably a better way to understand the concept.
Instead of writing (pseudocode):
DoSomething(a,b)
DoSomething(c,d)
DoSomething(e,f)[
You write:
things_to_do = [ [a,b], [c,d], [e,f] ]
for each thing in things_to_do
DoSomething(thing)
If you have first-class functions, instead of writing:
switch x
case a
f(y)
case b
g(y)
You write:
switch = { a: f, b: g}
switchx
Now, more realistic examples. This one is extracted from a Ruby library I wrote, and it makes some methods defined on Arrays work on Strings. I think it illustrates the power of data-driven programming coupled with metaprogramming quite well.
methods = %w{first first= head head= init last last= tail}
methods.each{|n| define_method(n){|*a,&b| chars.to_a.send(n,*a,&b).join}}
Actually, the examples seem to be similar to the issue we're solving in the article. If I try to adapt your solution to the issue of having two different representations, it could look like this: data = {"polar": function realPart(){...}, "rectagular": function realPart(){}}, and then somehow you give that data to the switch =D.
It's great to see that data driven programming can also be implemented in contexts!
Great post! Thanks
Cool post. Does the fact that polar coordinates can be the same ([1, π] = [1, 3π] = [1, 5π], etc.) complicate matters at all or is that simply handled by the trig functions?
Great question! Actually I haven't thought about that before.
In fact, that could be an issue because some users could want to represent angles with degrees and others using radians. So once again, we could try to tag the angle with the type ('radians 'degrees) and handle that internally using the technique that we saw before!
Thanks for this! 😄