Re: Structure of complex ex-OOP programs

2010-07-12 Thread Nicolas Oury
1) would be more:
 - define a protocol for each kind of function (render, serialize...)
- define a deftype/defrecord for each type of element, and make them extend
the protocol

It's not that different from 2. (protocol, as far as I understand, are
multimethod whose dispatch function is the type of first arg)

More choice:

3)

(defn render rendering
   [obj context]
  (case (:shape obj)
 :line (render-line obj context)
   .
)

with obj being a PersistentHashMap {:shape :line :begin {:x :y} ...}

The right choice depends somehow of taste.

I would do for 1, but other would do differently I think.
Good thing with a multi-paradigm language.

-- 
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

Re: Structure of complex ex-OOP programs

2010-07-12 Thread Moritz Ulrich
1. would be my favorite too. Multimethods are fine too, but may be a
bit slow. 3. is the same as 2. while avoiding multimethods.

On Mon, Jul 12, 2010 at 10:26 PM, Nicolas Oury nicolas.o...@gmail.com wrote:

 I would do for 1, but other would do differently I think.
 Good thing with a multi-paradigm language.



-- 
Moritz Ulrich
Programmer, Student, Almost normal Guy

http://www.google.com/profiles/ulrich.moritz

-- 
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


Re: Structure of complex ex-OOP programs

2010-07-12 Thread raould
On Jul 12, 1:26 pm, Nicolas Oury nicolas.o...@gmail.com wrote:
 The right choice depends somehow of taste.

chipping in two cents:

try to predict what kinds of change your system needs to support, and
use that to help choose a style.

(a) fp style: easy to add new operations on a fixed set of data types.
(cf. pattern matching styles in ocaml, haskell, etc.)
(b) oo style: easy to add new data types implementing a fixed set of
operations.
(c) in between style: something that purports to cut the gordian knot
in the expression problem? typeclasses? multimethods? whatever crazy
stuff scala does? or something else besides?

sincerely.

-- 
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