The general advice is to use Protocols if you need more than one implementation 
of a function (ie. different targets). If there is only one, use a function.

I found myself always starting with a simple function and eventually refactor 
to a protocol if needed (which is quite rare). It is generally good practice to 
write functions in a way that take their "state" as the first argument, which 
would also be the object the protocol would dispatch on. So even if you switch 
to protocols the code using the function does not need to change, if you treat 
the "state" in a somewhat opaque way.

Hope that made sense.

/thomas

On Thursday, March 26, 2015 at 4:18:26 AM UTC+1, Michael McLellan wrote:
> I've recently been reading a lot about core.async and the different ways it 
> can be useful for building interactive/reactive interfaces. I was reading 
> through David Nolen's blog 
> (http://swannodette.github.io/2013/08/17/comparative/) and the corresponding 
> code 
> (https://github.com/swannodette/swannodette.github.com/blob/master/code/blog/src/blog/autocomplete/core.cljs)
>  and was confused by the of protocols here when setting up the DOM 
> modification functions. To me it seems like they could just be helper 
> functions, but I'm likely missing something. What is the advantage of 
> defining the protocols and extending the existing types?
> 
> For a simple example of what I mean, I made a gist:
> https://gist.github.com/jmmk/54857dd919cb7ff70086
> 
> One has simple functions hide! and show! that modify an element, and the 
> other defines the protocol and extends the HTMLElement to include -hide! and 
> -show!. What are the tradeoffs here?

-- 
Note that posts from new members are moderated - please be patient with your 
first post.
--- 
You received this message because you are subscribed to the Google Groups 
"ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Reply via email to