Fork me on GitHub
#clojuredesign-podcast
<
2020-09-22
>
genekim15:09:52

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!

nate16:09:00

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

nate16:09:53

Glad to hear it helped you out.

neumann16:09:39

@U6VPZS1EK 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!"

😂 3
neumann16:09:32

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!

genekim21:09:49

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

neumann21:09:29

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 "")
            (.build)
            (.getService)))
vs something like
(create-service {:credentials creds, :database-uri ""})

neumann21:09:39

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

🎉 3