3 ms·
I've occasionally mused about the possible value of introspectable and serializable closures. Rather than being memory-only, it would be nice if the weight of k
by barrkel 12y ago
I've occasionally mused about the possible value of introspectable and serializable closures. Rather than being memory-only, it would be nice if the weight of keeping them around could be palmed off to the browser using cookies or hidden fields.
To be practical, it would require that the activation record chain kept alive by the closure is reasonably short, that the number of live variables in the chain is fairly small, and there be a reliable way of mapping code references in and out. But I think it can be done.
One of these days, I'm going to implement a toy language with this feature combined with my other favourite, automatically recalculated data flow variables (think: "variables" that work like spreadsheet cells). These guys are highly applicable to data binding, and making them a first-order language concept makes them much more elegant to use.
- brudgers 12y agoStoring closures on the browser creates a dependencies on JavaScript, user browser settings. and implementation details of various browsers. At the time HN was written, IE was common and Google Chrome did not exist. Doing arbitrary work on an arbitrary client increases application complexity significantly. Sometimes there's a big payoff. Sometimes there isn't.
- barrkel 12y agoI meant closures (or rather, continuations) serialized, encrypted and stored as a string. They wouldn't be callable in the browser.
- webXL 12y agoThat's what ASP.net ViewState does more or less. There's a lot of overhead and little gain IMO. I think it's best to transfer as little state as possible across the wire for simplicity.
- barrkel 12y agoIt is not. ASP.net viewstate includes a serialization of a set of controls that, server-side, represent the state of the page. That's not what I'm talking about. This is why I think I need to write a toy language example - most people, given a brief outline of what I'm talking about, think I'm talking about something else they're more familiar with, and misunderstand.
- krapp 12y agoAm I simply not awake yet this morning or are you more or less describing sessions?
- brudgers 12y agoI understood what you were suggesting. What does serialization, encryption, transmission, requesting, retransmission, decryption, and deserialization gain? + A few bytes of memory - Network latency - Server side IO latency - CPU load for encryption/decryption - Maintaining client side code base for diverse client capabilities undergoing rapid change - Server-side code complexity - More complex debugging due to more points of failure. The string is a stark data structure and everywhere it is passed there is much duplication of process. It is a perfect vehicle for hiding information. -- Alan J. Perlis, Epigram 34.
- barrkel 12y ago+ Statelessness This is key.
- brudgers 12y agoTANSTAAFL As soon as you have user names with an associated history, you're dealing with state. Functional programming is a style of managing state transitions, not avoiding them.
- barrkel 12y agoI'm not suggesting I can get a free lunch. I wasn't talking about avoiding state transitions. I wasn't even talking about pure functional programming. By talking about variables captured by closures, I'm implicitly not doing so. In the context of server programming, by using the word 'statelessness', I meant that the request (from clicking the link) doesn't need to go back to the same server that created the link. Having an in-memory hash-table containing closures or continuations keyed by an ID in the request implies that request needs to ultimately reach back to the same machine, one way or another. I'm talking about programming the Lisp-style multi-request process using continuations (as described by pg in his essays), except making them work in a stateless way - without the requirement for hash tables full of continuations that need periodic collecting, with the consequence that the links go stale. A request handler generating such continuations would, of course, need to be simple and lightweight, not deep or complex. Code artifacts and stateful resources would need to be serialized using keys that contain enough information to find or recreate them. Imagine having server-side URLs for every function, for every resource, where doing a request for a function pointer or a resource could potentially open a database connection or load a library. The keys would be analogous to such URLs. Consider an activation record. It is the storage for local variables, parameters and the function return location (aka continuation, when you twist your mind around it). The activation record for any given function has a particular signature. Let's say one of these local variables is a Customer object, mapped by an ORM from the database. That is something that can be reduced to an ID; if you know that this activation record only ever has a Customer in that slot, you can potentially serialize that object as a single number. Keep the chain of activation records short, and they act mostly as a path through a tree to the current state of a process or interaction. Function a calls function b calls function c, which returns a result to the client, along with a continuation (or more interestingly, multiple continuations). A serialized continuation would be little more than a record of the current step in the overall process, everything needed to pick up where one left off. I think, with the right level of language abstraction, this can be made very slim. (PS: I detect a certain amount of exasperation in your tone. I'm not sure what I did to trigger it.)
- JoachimSchipper 12y agoTake a look at Termite for Gambit Scheme; its focus is different from yours, but it seems to be very good at serializing stuff (including continuations) and automatically proxying the rest (e.g. file descriptors). (I don't think this is actually a good idea - intra-datacenter traffic is much faster, upgrading becomes hard in this scheme, and your security model needs to be quite complicated - but I'd be interested in learning what you find.)
- barrkel 12y agoI will take a look. Thanks for the suggestion. Upgrading is hard, yes, but I have some ideas. A lot depends on the level of the language, and I'm thinking of something fairly high-level.
- ufmace 12y ago> automatically recalculated data flow variables (think: "variables" that work like spreadsheet cells) That sounds kinda like C# Properties, which can be calculated with arbitrarily complex code at get and set time. Is that what you had in mind? It's commonly used with WPF data binding.
- frou_dh 12y agoBog-standard getter/setter methods can also run arbitrary code. I guess where data-flow comes in is if GetterA involves calling GetterB then does the system know to automatically call GetterA after SetterB?