4 ms·
The 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 (
by agumonkey 13y ago
The 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.
- taeric 13y agoI have heard claims that if you start people with the "functional style" they are less confused by these tracks. My scepticism goes back to just how many imperative "mutable" instructions people will have learned outside of programming. (That is to say, I'm curious how much research is into this question. Most of the people claiming one way or the other seem to have something to sell.) Even the example you give, graphics, is somewhat interesting to me. It goes back to my thought where the "metaphor" of what you are doing is more math based already. In those cases, I fully expect a more rigorous "functional" approach to make sense. And yeah, I actually thought this was sort of like the "with" syntax as I wrote my example. Couldn't remember the actual drawbacks of the with syntax right off. Similarly, I've seen a few times where you can use an import in scala to similar effect. Looks like: def foo(x:Bar) { import x._ ... } I thought this could make reading some code a little less cluttered. Haven't seen it in wide use, though. (And... I would expect it should be used with care.) I can't help but lingering on the thought that this is dynamic typing where the "type" of a variable encodes the state. Seems if the compiler could track the state and provide indications to whether or not the desired state could be achieved, then the code could be clearer. Consider the directions for driving cross country. The required "actor" of the system is a vehicle with enough gas. If at any time the vehicle does not have enough gas, the system performs the steps to return the vehicle back to the state of having enough gas, then continues the trip. That make sense?