Hi Bil. On Sat, Jan 2, 2016 at 2:26 AM, William la Forge <laforg...@gmail.com> wrote:
> Hi again Andrey! > > Not to drag this out, but you seem to have missed my main point, which > also means that I failed to make it. :-) > > Understanding how comp works and seeing the function, lens, for defining a > cat's lens, it is not at all obvious how a cat's lens works. On the other > hand, the dewdrop lens constructor simply creates a record. And a quick > review of the code for dewdrop's ladd shows clearly how dewdrop lenses are > composed. Dewdrop then allows a developer to leverage ones own intuition. > So a developer may quickly pick up on how to use cat, but must trust that > any bugs lie in that developer's own code. Or perhaps take time to learn > how a cat lens works at 3 AM when the servers are crashing. Not likely, > I'll grant you. But I prefer not to have to trust in magic when I have a > choice. Too often such magic has a domain that is a bit different than what > I was expecting. Not understanding how something works, I usually lack a > similar understanding as to when I should or should not use it. > Thanks for the explanation. For use dewdrop you should know how to work records and closures for fully understand all operations. With cats you should understand how to work only closures. In fact, with ladd and record you are just doing the same thing that clojure.core can do but you are just re-implementing something that clojure.core offers. I think that you are declaring that comp and closures are not obvious because you don't know how they work and your solution is just re-implement them using familiar components for you, and thinking that understand your code will be more easy that understand how comp works (and justifying that you don't want to learn them when the server crashes at 3 AM (that seems a fallacy instead of argument)) This is not about complicated things with strange and not obvious abstractions, is about to understand the language and the facilities that it already provides instead re-implementing everything that one do not know how it works. We have done cats with the same argument that you are defending now here: bring near the complicated and cryptic (non very obvious) abstractions from haskell in clojure using simple and familiar components making the learning curve more affordable. I agree with your "main argument" that things should not to be complicated and not obvious if them can be simple and obvious... > > Keep in mind also that clojure has a lot more than just functions, and > composition applies to a lot more things than just functions as well. > Indeed, my favorite technique is compositions of bags of properties serving > in place of objects. So learning how to call a method to compose two > records is hardly a stretch and well worth the price for being able to > understand what is going on internally. > > On Friday, January 1, 2016 at 3:35:29 PM UTC-5, Andrey Antukh wrote: > >> >> >> On Fri, Jan 1, 2016 at 9:53 PM, William la Forge <lafo...@gmail.com> >> wrote: >> >>> Andrey, >>> >>> This is where I have a problem. Ii could have implemented dewdrop lenses >>> as functions that could be composed. But the code would be harder to >>> understand and possibly be slower. I just do not see the point. >>> >> >> I agree with your main argument, but I don't know how using records makes >> thinks more easy understandable in this concrete case and how using >> functions over records will make code slower. Transducers has a performance >> improvements over classical transformation compositions, and in this case, >> the cats lenses leverage the same technique. >> >> >>> >>> Implementing dewdrop lenses as records makes it dirt simple for anyone >>> to create more kinds of lenses. And the ladd function to create a new >>> record with the composed getter and setter functions is pretty clean as >>> well. >>> >> >> Yes but it implies more api to know, that is not bad but if you limit the >> set of new api that one should learn/use, will contribute to more familiar >> and easy api. Adding new api also implies more time to understand it and >> remember when it should be used. >> >> >>> >>> Isn't it more important to have code you can analyze easily, and which >>> even a novice clojurist like myself can embrace and enhance a whole lot >>> more important than being able to say that we can use comp to compose these >>> lenses??? >>> >> >> Yes, I agree with you, the code readability is very very important. But >> this concrete case I don't found big differences in code readability: >> >> ;; dewdrop >> (defn key-lens [k] >> (lens. >> (fn [d] (get d k)) >> (fn [d v] (assoc d k v)))) >> >> ;; cats >> (defn key >> [k] >> (lens >> (fn [s] (get s k)) >> (fn [s f] (update s k f)))) >> >> The code is mostly the same... >> >> >>> I see good engineering as leveraging computer science so the programming >>> grunts can make effective use of it. Programming is real grunt work, after >>> all. No matter how much you dress it up, we all needs must get our hands >>> dirty and put our backs into it. >>> >> >> My two cents. >> Andrey >> >>> >>> Bill >>> >>> On Friday, January 1, 2016 at 9:09:08 AM UTC-5, Andrey Antukh wrote: >>>> >>>> Hi! >>>> >>>> I have read the readme and I don't found a big evidence of something >>>> wrong so, nice work! >>>> Furthermore, do you know about https://github.com/funcool/cats ? It >>>> has a lens and traversable implementation for clj/cljs. You can read the >>>> related documentation here: http://funcool.github.io/cats/latest/#lens >>>> . >>>> >>>> You can found that lenses, using cats approach, are working just like >>>> transducers (function composition), you do not need any special function >>>> for combine lenses, just use comp. One of the readme examples (from >>>> your repository) that combines two lenses, in cats can be written in this >>>> way: >>>> >>>> (require '[cats.labs.lens :as l]) >>>> (def xy-lens (comp (l/key :x) (l/key :y)) >>>> ;; Or just use (l/in [:x :y]) >>>> >>>> (l/focus xy-lens {:x {:y 1}}) >>>> ;; => 1 >>>> (l/over xy-lens inc {:x {:y 1}}) >>>> ;; => {:x {:y 2}} >>>> >>>> Happy new year! >>>> Andrey >>>> >>>> On Fri, Jan 1, 2016 at 2:54 PM, William la Forge <lafo...@gmail.com> >>>> wrote: >>>> >>>>> I've been looking at lenses and while it looks pretty simple and very >>>>> useful, I had a hard time getting it. So I came up with my own take on >>>>> lenses. https://github.com/laforge49/dewdrop#readme >>>>> >>>>> So perhaps I still do not understand lenses and what I've done is >>>>> wrong. Or perhaps having been through the exercise I'm now getting it and >>>>> what I've done is no simpler than what everyone else has done. Or perhaps >>>>> I've just described things with fewer technical terms. >>>>> >>>>> So I'd appreciate it if you would review this very short document and >>>>> tell me what I don't understand. Or that I've actually done something >>>>> worthwhile with lenses??? >>>>> >>>>> Thanks! >>>>> Bill >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Clojure" group. >>>>> To post to this group, send email to clo...@googlegroups.com >>>>> Note that posts from new members are moderated - please be patient >>>>> with your first post. >>>>> To unsubscribe from this group, send email to >>>>> clojure+u...@googlegroups.com >>>>> For more options, visit this group at >>>>> http://groups.google.com/group/clojure?hl=en >>>>> --- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Clojure" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to clojure+u...@googlegroups.com. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> >>>> -- >>>> Andrey Antukh - Андрей Антух - <ni...@niwi.nz> >>>> http://www.niwi.nz >>>> https://github.com/niwinz >>>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To post to this group, send email to clo...@googlegroups.com >>> Note that posts from new members are moderated - please be patient with >>> your first post. >>> To unsubscribe from this group, send email to >>> clojure+u...@googlegroups.com >>> For more options, visit this group at >>> http://groups.google.com/group/clojure?hl=en >>> --- >>> You received this message because you are subscribed to the Google >>> Groups "Clojure" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to clojure+u...@googlegroups.com. >>> For more options, visit https://groups.google.com/d/optout. >>> >> >> >> >> -- >> Andrey Antukh - Андрей Антух - <ni...@niwi.nz> >> http://www.niwi.nz >> https://github.com/niwinz >> > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Andrey Antukh - Андрей Антух - <n...@niwi.nz> http://www.niwi.nz https://github.com/niwinz -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.