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!
Hahaha, that's an unexpected outcome from us poking a bit of fun.
Glad to hear it helped you out.
@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!"
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!
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
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>"})
A "create" function that takes a "config" map. Nice and succinct!