3 ms·
I've seen many procedures that are essentially: public Blah foo(String in) { in = in.toUpperCase(); In shops where there is an insistence on final
by taeric 13y ago
I'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?
- agumonkey 13y agoI'm selling my frustration. I experienced generic uncoupled UI for lazy reactive dataflow around the time I entered college, where I then suffered through C, Java where things quickly become dark magic. The clean thinking process of dataflow looked like a long forgotten dream that was weirdly close to what your code ends up doing, streaming data through transformations. But in imperative code it's obscured. Sure some people have the right view and the right brain (I believe more people before the 80s had this skill on average) and they can compile the idea into algorithmically clean imperative code where things don't step on each others (just like algorithms in Cormen), but I didn't met them often. Graphics and other domains (sound, ..) had easier time finding an algebra to combine atoms and filters in arbitrary fashion to create complex results. I'm betting all high end (meaning hollywood) graphic software are lazy dataflow systems. But if you look at Photoshop, it's still imperative, and people are required to get skilled at managing dozens of layers to store intermediate results in case they wanna change something. This is pure madness. Find tutorials about Houdini where the artist builds its dependency graph as it fits, and if he something needs to be modified he just tweak the right upstream node and everything recomputes on demand. Software is different ? not so much, Brett Victor demonstrated how you could develop a platform game in such fashion, lazy reactive source code with different dimensions/views. You can see the output of a trajectory function, change the code and observe the computed difference on the fly.. A lot of projects are trying to reduce the loop between idea / source / result. DevOps with testing/deploy vms (even storage systems are approaching functional idioms like btrfs, zfs, logfs), js client frameworks with databinding .. all the same. It's not everything though; a friend pointed to me that sometimes you need to research an algorithm, it won't be large so this won't help you understanding the problem faster. The type encoded state is not imperative programming anymore, as I said, to me it's akin to prolog.