5 ms·
Of course... how many programs do you have running right now? Do they do anything to guarantee they can each use the main processor in isolation to the others?
by taeric 13y ago
Of course... how many programs do you have running right now? Do they do anything to guarantee they can each use the main processor in isolation to the others? What about the ram? The keyboard?
That is, the recipe for a single dish could be seen as a subroutine in the entire process pool for preparing a meal. Considered this way, what is the largest dining establishment you have seen? What is a menu, but a declarative listing of the strategies that an establishment can use to satisfy a customer's desire for dinner?
More directly, all of the metaphors of programming have almost direct analogies into the real world. "Worker" threads. "Queues" of "tasks."
As I've said elsewhere, I don't think I'm being particularly grand here. Just find it curious that, though we commonly have recipes and other directions that are mixes of declarative and imperative, the current trend in programming is to be purely declarative/functional. I wish I understood why that was.
- agumonkey 13y agoSimplicity of recipes (they're blurry, they're not chemistry) , and constant human oversight (your brain takes care of many things not written down) makes imperative instructions feasible for small tasks like a meal. It won't scale, but since it doesn't have to it survives.
- taeric 13y agoBut why won't it scale up? This is essentially my question. And, it is not like there are not explorations of cooking in non imperative forms. When your metaphor is "with these ingredients and devices, perform these transformations on them" an imperative form works really well. This is just as true for any algorithm you will want to write. Consider, write down any algorithm for how to do something. I challenge that key to your algorithm will be the idea of transforming something. Often in a "destructive" way. An example, with the concept of a browser that has state, the following algorithm will get you logged in to your bank. browser = new browser browser.location = "www.yourbank.com" browser.focusFieldLabeled("username") browser.type("your name") browser.focusFieldLabeled("password") browser.type("your password") browser.focusButtonLabeled("login").or("submit") browser.click() Implementing something that does this would be trivial, all things told. Now, do so without the metaphor of a "stateful" browser. Just trying to come up with "pure functional" implementations of each of these is not something that sounds pleasant to me. (I look forward to being surprised. :) )
- agumonkey 13y agoAbout the scaling, my take is implicit dependencies expressed by order of statements. It's fragile, not composable, not abstractable. Your browser example is completely imperative, it's a sequence of mutations. You just don't think that way in FP, you describe the new. (def url "http...") ;; url -> (html,session) (get url) ;; (url, form, session) -> (html, session) (let ((form {username ... password ...})) (post url form)) You can thread these calls to pass the http state for you.
- taeric 13y agoRight, my argument is that the imperative form is much more easily reasoned about in this example. It is not as easily decomposed, but the question comes down to how much it needs to be. To wit, I don't know how I would actually fill out the implementations of what you described such that it really worked. Without actually just manipulating the state of some browser thing.
- agumonkey 13y agoHave you seen Rich Hickey talks ? he mentions the notion of ease in one, and the notion of mutation in many others. An html browser right now is a large stateful tree, imperative programming so it is easy to think about and write code this way, while FP orientation would need to rethink things, less easy, but probably simpler. In clojure data structure are immutable, you "only" compute new, I think that's how they designed a web app in http://pedestal.io/ http://pedestal.io/ (clojure[script] based system). If you really care about accepting small grained input you'd probably write some read eval/validate print loop on the client side before then sending a main request for a http json patch.
- taeric 13y agoRight, but my assertion here is that this really only works because Hickey has basically put forth "mathematics" as the core metaphor for the things he is building. That is, he effectively wants an identity equation for every moment of time in the application. This idea that "state" is somehow hard to reason about is one that I am growing to reject. Sure, if it is not part of the metaphor that one has built, it can be tough. But this is also true for what many of us mean when we say "mathematics." What is the equation for how you get home every day? How do you calculate what represents you yesterday? Look at some of the classic algorithms. Is quicksort really that tough to reason about because it is in place (and thus relies on mutation)? Bubble sort? (Any sort...) Is cleaning your room or office truly difficult to reason about because it involves modifying the room? Fixing dinner, since it involves modifying the ingredients? This is what I loved about that paper linked up thread. When you build your abstractions around the ways in which things interact by mutations, then the code gets much clearer. This is not because we wall off the mutations, but because they are given names and reasoned about. It is not that we constantly have new instances of a list or collection with the old one hanging around, as that can be just as problematic as otherwise. Consider, sure this is an obvious error to a casual programmer in Java: String x = ... x.toLowerCase(); doSomething(x); But, why is this a mistake? Wouldn't it be MUCH more intuitive if you wanted to keep both values the code would look like: String x = ... String original = x; x.toUpperCase(); doSomething(x); Just from a communication perspective. That there really isn't a "focused" object in languages often strikes me as something that could be addressed. (And, I believe this is the key of stack based languages, where they actually would read like I indicated.)
- Dewie 13y ago> As I've said elsewhere, I don't think I'm being particularly grand here. Just find it curious that, though we commonly have recipes and other directions that are mixes of declarative and imperative, the current trend in programming is to be purely declarative/functional. I wish I understood why that was. Ever read a recipe designed for concurrency and/or parallelism? Functional idioms are becoming in vogue at the same time as people are meeting walls when it comes to single threaded applications.
- agumonkey 13y agoOften reference books end up suggesting practices that amount to what function based programming is. (thread safe C or Java)
- taeric 13y agoAre you kidding me? Of course I have. Hell, the example I gave was. It begins with "begin heating oven..." This is not a task you do and wait for it to finish before you do the next step. Then there is the entire concept of fixing not just a dish, but an entire meal. If you have ever seen a recipe with "while the onions are cooking..." you have seen a recipe with parallelism. Seriously, sometimes the blindness of our field to just how much we share with other fields is very troublesome.