3 real-world visitor design pattern examples in Rust, JS, & C++
Channel: strager
Date: 2022-02-06

Why would we ever want to use the visitor design pattern? Aren't design patterns a waste of time? Let's look at how programmers in the industry use the visitor design pattern to solve real problems.

0:00 why design patterns?
0:11 Chromium's visitors
1:36 why visitor for Chromium?
2:27 quick-lint-js.com's visitors
3:25 why visitor for quick-lint-js.com?
4:02 fd's visitors
4:50 why visitor for fd?

== Code samples ==

Chromium's RenderViewZoomer: https://chromium.googlesource.com/chromium/+/07ca5b139b967f62b03f08fca5d6f37a373ed20f/content/renderer/render_thread_impl.cc#138
Chromium's OnSetZoomLevelForCurrentURL: https://chromium.googlesource.com/chromium/+/07ca5b139b967f62b03f08fca5d6f37a373ed20f/content/renderer/render_thread_impl.cc#969
Chromium's ForEach: https://chromium.googlesource.com/chromium/+/07ca5b139b967f62b03f08fca5d6f37a373ed20f/content/renderer/render_view_impl.cc#810
Chromium's GetExtensionViews: https://chromium.googlesource.com/chromium/+/07ca5b139b967f62b03f08fca5d6f37a373ed20f/chrome/renderer/extensions/extension_helper.cc#123

quick-lint-js.com's visitor: https://github.com/quick-lint/quick-lint-js/blob/1214a0f8cc969543e61fcaf7723d831467451f14/website/src/error-documentation.mjs#L33
quick-lint-js.com's orchestrator: https://github.com/quick-lint/quick-lint-js/blob/1214a0f8cc969543e61fcaf7723d831467451f14/website/src/error-documentation.mjs#L238

fd's code: https://github.com/sharkdp/fd/blob/eb111aa83501ac68bc2844890904c34c18a52b89/src/walk.rs#L474
ignore's WalkParallel: https://docs.rs/ignore/0.4.18/ignore/struct.WalkParallel.html

== Attribution ==

Brick pattern photo created by rawpixel.com - www.freepik.com
Chromium logo by The Chromium Project; CC-BY 2.5
Dusty mascot by quick-lint-js; CC-BY-ND 4.0
JavaScript logo by Christopher Williams under MIT license https://github.com/voodootikigod/logo.js/blob/1544bdeed6d618a6cfe4f0650d04ab8d9cfa76d9/COPYING
Rust logo by Mozilla; CC-BY 4.0

#designpatterns