3 ms·
The 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 i
by taeric 13y ago
The 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.
- agumonkey 13y agoYou do realize that these mistakes are made by people learning the immutable approach ? For people having started with functional programming or other systems (the first computational systems I used were lazy reactive computer graphics) you have close to zero confusion from beginning. Beside if you want to thread modification in a cuter way, Clojure ->> macro allows (upperCase (first-three-letters string)) to be written (->> string first-three-letters upperCase) More here http://clojuredocs.org/clojure_core/clojure.core/-%3E%3E http://clojuredocs.org/clojure_core/clojure.core/-%3E%3E. There was experimentation for the 'it' style, but it's fragile in most code, thinking of with statements: - http://stackoverflow.com/questions/1931186/with-keyword-in-javascript - http://msdn.microsoft.com/en-us/library/wc500chb.aspx They had non-intuitive side-effects hard to notice, so nobody use them anymore. They're present in so-called anaphoric macros (which were popularized by Paul Graham OnLisp, also Doug Hoyte Let Over Lambda), see: https://github.com/magnars/dash.el#-map-fn-list https://github.com/rolandwalker/anaphora Here the context is limited to single argument pure functions so a 'it' pronoun won't cause much weirdness.