clojuredesign-podcast

Discussions around the Functional Design in Clojure podcast - https://clojuredesign.club/
genekim 2020-09-22T15:24:52.004700Z

Thanks @nate @neumann — I think I finally understand the Builder GoF pattern after hearing your funny hypothetical sorting example! I never really got GoF book when I read it decades ago, and always struggle with all the Google Cloud Java libraries which extensively use the pattern. Starting to get it now, finally!

nate 2020-09-22T16:05:00.004800Z

Hahaha, that's an unexpected outcome from us poking a bit of fun.

nate 2020-09-22T16:05:53.005Z

Glad to hear it helped you out.

neumann 2020-09-22T16:47:39.005800Z

@genekim I'm happy we could help! The builder "pattern" always makes me a bit crazy. At best it's overcoming a lack of literals in a language. (You can't just write out the contents of a "map", you have to "build" one.) At worst, it's a big mutable mess of something that goes through nonsensical states on its way to actually being something. eg.

SentenceBuilder b = new SentenceBuilder();
b.appendWord("are");
b.prependWord("Builders");
b.appendWord("nuts!")
b.render();
> "Builders are nuts!"

😂 1
neumann 2020-09-22T16:49:32.006100Z

Of course, no one would ever make a "SentenceBuilder" because you'd just use a string literal to write out a sentence. That brings me back to the first point!

genekim 2020-09-22T21:35:49.006400Z

This is so great to hear that some of my struggles were legitimate. Honestly, I need to read about the Builder and other GoF patterns more, because it would help me use these Google libraries, who adhere to them so well. I could have saved myself a bunch of time if I realized that. You can see how I struggled for days to get a Firebase instance working here, mostly because I had no idea what I was doing: 😂https://gist.github.com/realgenekim/2d9b14da54e71bb14ffe69afc7947bc8

neumann 2020-09-22T21:40:29.006600Z

Yeah, if you do need to deal with OO, I think it does help to understand the GoF patterns. I checked out your gist. I'm always struck by how verbose builders are vs a literal:

(def db (-> (new FirebaseOptions$Builder)
            (.setCredentials creds)
            (.setDatabaseUrl "<https://test1-xxx.firebaseio.com>")
            (.build)
            (.getService)))
vs something like
(create-service {:credentials creds, :database-uri "<https://test1-xxx.firebaseio.com>"})

neumann 2020-09-22T21:42:39.006900Z

A "create" function that takes a "config" map. Nice and succinct!

🎉 1