"The Clean Code Talks -- Inheritance, Polymorphism, & Testing"
Google TechTalks3 HN recommenders · recommended in 3 months, 2009–2023
talk · intermediate · 2009–2023 on HN
Misko Hevery's Clean Code Talk shows how to use object-oriented techniques such as polymorphism to remove repeated if and switch statements. The result is code that is easier to test, understand and maintain.
HN commenters recommend it as a thorough treatment of replacing conditionals with polymorphism and why flags and deep ifs can be code smells.
Up next
7 mo on HNA Talk Near the Future of Python (a.k.a., Dave live-codes a WebAssembly Interpreter)
David Beazley
7 HN recommender · 2019–2025
11 mo on HNTreating the Farm as an Ecosystem with Gabe Brown Part 1, The 5 Tenets of Soil Health
Living Web Farms
12 HN recommender · 2019–2025
3 mo on HNA4 / V2 Rocket in detail: Turbopump
Astronomy and Nature TV
3 HN recommender · 2019–2022
6 mo on HNAlex Evans at Umbra Ignite 2015: Learning From Failure
Media Molecule
7 HN recommender · 2017–2026
15 mo on HNRailsConf 2014 - All the Little Things by Sandi Metz
Confreaks
15 HN recommender · 2015–2025
14 mo on HN"Simple Made Easy" - Rich Hickey (2011)
Strange Loop Conference
14 HN recommender · 2022–2026
13 mo on HN"Making Impossible States Impossible" by Richard Feldman
elm-conf
9 HN recommender · 2017–2026
12 mo on HNHow To Design A Good API and Why it Matters
Google TechTalks
12 HN recommender · 2011–2025
11 mo on HNThe Value of Values with Rich Hickey
InfoQ
10 HN recommender · 2014–2023
10 mo on HNOverwatch Gameplay Architecture and Netcode
GDC Festival of Gaming
16 HN recommender · 2019–2025
11 mo on HNSolving Problems the Clojure Way - Rafal Dittwald
Clojure/north
10 HN recommender · 2019–2025
10 mo on HNLecture 1A: Overview and Introduction to Lisp
MIT OpenCourseWare
10 HN recommender · 2019–2026
6 comments from Hacker News
It's not so much the existence of the flag, itself, but rather using an if-statement at the deepest-level of the call stack to conditionally modify behavior. This talk gives a great overview of why boolean flags (rather, if-statements) can be a code smell: ▶ this video OP's blogpost advocates for data-oriented design (e.g. Entity Component Systems) as a mechanism for avoiding this, whereas the talk I've linked advocates for OOP. Both mechanisms are equally valid (imho) and are inline with widely-adopted industry practices for software architecture.
I completely disagree with the example given in this blog. I don't have time to give a full explaination but I believe the google clean code talks gives a far better arguement than I ever could. On the general principle I agree that overengineering is to be avoided, but I actually think the example shows a clear disregard for Object Orientated principles. ▶ this video
Google posted a tech talk about this a while ago: ▶ this video which is more comprehensive than the posted article.
I think this is actually a great example of why `if` should be "pushed up." The objective of the code is to perform an particular operation on the walrus, given a condition. The is actually ifs being instead of polymorphism and a type system. Why does the walrus have these two functions, which must be called in different scenarios? Why not have a single function, and two types, and the correct type is passed in? Even given the current structure, we could accomplish this: // There are better ways to accomplish this, depending on the language func frobnicate(walrus) { return walrus.frobnicate(); } func transmogrify(walrus) { return walrus.transmogrify(); } // Somewhere high in the code if condition { processing_function = frobnicate } else { processing_function = transmogrify } // Somewhere else in the code for walrus in walruses { processing_function() } If the decisions are made as early as possible, they do not need to be littered throughout the code. The guts of the code can run without branches, performing the same operations every time, the output only modified through the construction graph. Of course, this is not a new idea: ▶ this video It was old 15 years ago.
Misko Hevery did a Google Tech Talk about this some years ago, he also use a very similar example with switching on the birds. ▶ this video
This google tech talk is basically about the same thing, eliminating conditionals with polymorphism: ▶ this video