On Friday, April 20, 2012 1:15:11 PM UTC-5, kurtharriger wrote: > > > Game state does not have to be a map, it could be any datastructure > you want, perhaps a protocol that is implemented by a concrete class > in another JVM language. However, I avoid encapsulation unless there > is a compelling reason reason to add it. More often then not the > result of encapsulation is that the entire library of useful functions > like map, reduce, get-in, update-in, etc... are no longer useable with > this custom data structure. > > It is also not strictly required that all your functions be pure, you > could load or save game state to a database or external service as > necessary. There are very few applications that are strictly pure. > However, it is recommended that you make as much of your program pure > as possible. If each time you made a game move the state was written > to a database then you might have difficulty trying to run multiple > solver strategies in parallel as these side-effects would continuously > clobber the others database state. > > The general idea is that pure functions are easily composed and easy > to test, so use them whenever possible. Impure functions that write > to external services are often much more difficult to compose and > test, so keep them as small as possible. Think twice about calling an > impure function from a pure function as this makes it impure... main > will almost certainly be impure, but that does not mean that > everything else also needs to be impure. >
I think that gives me a lot to ruminate on. Thanks, I appreciate the detailed advice. -- 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