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.

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 
> <javascript:>> 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 
>> <javascript:>
>> 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 <javascript:>
>> 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 <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> -- 
> Andrey Antukh - Андрей Антух - <ni...@niwi.nz <javascript:>>
> 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.

Reply via email to