3 ms·
I think state centric system have been the main metaphor since data is processed through machines. Maybe Hickey and others are living in one side of the univers
by agumonkey 13y ago
I think state centric system have been the main metaphor since data is processed through machines. Maybe Hickey and others are living in one side of the universe, but he did use other systems before creating clojure, and does not reject all state, just accidental/unnecessary state.
Sorts are not a good example here I think. QS correctness is uncoupled from its in-place property[1]. And they're encapsulated processes, nobody is supposed to see intermediate internal state. This black-box state is not the problem addressed[2]. All your examples are "single threaded". Two blind people moving chairs around will be a problem when one will try to sit down where there was one. Mutation and sharing is the problem otherwise nobody cares. That's why temporary variables are nasty in imperative friendly languages, any variable became an opportunity to mess up data needed by someone else.
It's also a logical waste, as in the first Java example, you don't need to compute the uppercase variant of a string unless it's needed down the road, if it is required then you pass it as argument to doSomething, that's what function are for. I tried to, but I'm not sure I understand the point of the second code example, because java references means x and original are the same, if you want an in-place uppercase method then both x and original are now uppercase letters, but you want to keep both values ... (Not really communication friendly)
The "focus" object would be a way to denote a place where all methods would accumulate state change ? I never saw this in the light of stack based language, it's interesting.
[1] the FP expression for quicksort is obscure the first time, but when you click you can't "unsee" it
[2] many lisp books explicitely say that this is acceptable because it doesn't leak out of the functional interface, referentially transparent as far as calling functions are concerned
- taeric 13y agoThe logical waste, to me, is that after I've forced something to uppercase, I probably don't care about the non-transformed version anymore. Making use of it is as likely to be a mistake as otherwise. Consider all of the times you see people modify a list in LISP and accidentally continue to use the previous version. Yeah, the focus object, to me, follows naturally with the way we do imperatives in natural language. Though, I guess there we have prepositions and such, too. (Are there programming languages with prepositions? I've seen creative use of them in testing libraries.) And, ultimately, what I want is a system where a reference essentially tracks the state of what it references? Functions on objects, then, would be tracked not just in terms of input/output, but whether they affect the item the are operated on? (This make sense?) That is, few people would expect the following "program" to work: rocket = new rocket() rocket.launch() rocket.addFuel(fuel) I have seen fancy usage of generics to have it such that launch could not be called on a Rocket<NoFuel> instance. This makes it possible to possibly do chained calls that would work as expected, but chaining quickly gets cumbersome. Especially if you want to do some things unrelated to the state of the rocket in there at some point. Do you know of any such systems? Also, apologies or not addressing the QS stuff. Wrote all of the above and realized I didn't touch it. :( I simply meant that most "cute" QS implementations you see in functional languages (and, hence, readable) are actually not the same algorithm, since they require a ton more memory. And, yes, all of this is a shared state problem. Though, again, I think if objects had ways of indicating what functions change state and what "state" is required of an object, much of that confusion would go away. Consider, if you have a team of cooks working, there is no confusion about when the "onion" that must have been diced is added to the pot. Pretty much any assembly line working area with many workers. A worker can do a spot check that the item they have is in the appropriate state for them to do their job. (Apologies, I would like to clean up this post, but know I will have a hard time getting back to it. Hopefully it is at least mostly intelligible.)
- agumonkey 13y agoThe first paragraph is a non issue, either you care about the original string and thus you have a variable (1) or you don't (2) or compute it from another one (3) (1) String focus = "aaaa" (2) String focus = "BBBB" (3) String focus = oldString.toUpperCase(); I very rarely see list mutation in Lisp, I'd need an example. The issue with a focus object is that it's cool to thread over one "object", but if you deal with more than one, you'll need distinguishable names, back to square one. What kind of prepositions did you see ? is like using 'it' as a generic variable name in closures/macros? The first part of your state tracking idea really reminds me of Ref/Atom constructs in clojure. The generic "subclass" to encode state categories as types is very nice, I toyed with it in college but I then lost interest in OOP (people were too crazy about GoF patterns), I don't know if it's used in production. The smart cook is akin to prolog goal based programming, here we're quite far from state mutation. I wish there was more systems built on this. ps: dont worry, my ideas are often blurry, as is my english.
- taeric 13y agoI've seen many procedures that are essentially: public Blah foo(String in) { in = in.toUpperCase(); In shops where there is an insistence on final parameters, this gets tripped into public Blah foo(String in) { String upperIn = in.toUpperCase() And then the mistake is to accidentally use the "in" variable later on. Or, simply in the first to forget to "reassign" the in to itself. As far as list mutations, I'm mainly referring to intro work. Whenever working with someone that is new to scala/lisp it is common for people to not understand why appending to a list does not "work." I'm embarrassed to admit I can not find the test library I meant. I believe it was "specs" basically. Looked something like: Foo foo = ... lookingAt(foo) it.shouldEqual(bar) it.shouldNotThrow(Exception).onCallofFoo ... Where "it" returns some context style object with basic assertion ideas on it, and some return a "foo" to do calls on it. Thinking of this in terms of a Prolog style machine did occur to me. Basically define your "transformations" and let the system search for the ones that could be used to go from the ingredients given to the outcome desired.
- 13y ago