|
|
|
|
|
by danabramov
4208 days ago
|
|
Clojure(Script) reads Rubyish to me in the sense that I can't read the code until I understand every primitive. Contrast this with Python which almost reads like a natural language (which I don't say is better, but more explicit IMO). (defn widget-c [data owner]
(reify
om/InitState
(init-state [_]
{:message nil})
om/IDidMount
(did-mount [_]
(let [events (sub (:notif-chan (om/get-shared owner)) :hello (chan))]
(go
(loop [e (<! events)]
(om/set-state! owner :message (:data e))
(recur (<! events)))))))
om/IRenderState
(render-state [_ {:keys [message]}]
(if message
(dom/p nil message)
(dom/p nil "Waiting ... waiting ... waiting ..."))))
|
|
Compare this to something like a Django Rest Framework:
reify doesn't require any special knowledge that class doesn't. The Python code here is subclassing a single abstract class (APIView) instead of 3, but it has the same "problem" in that you have to know what methods to override. Again this is user code so you probably looked up what APIView needs to work just like you looked up with InitState, IDidMount, and IRenderState.reify vs class in Clojure vs Python is a matter of idioms. You can definitely create an actual class instead of reifying in clojure, it just isn't necessary. Likewise, you could create an anonymous type in python via type(), but you'd probably get fired and/or shot in most circles for doing so.