"The Clean Code Talks -- Inheritance, Polymorphism, & Testing"
Channel:Google TechTalks · Length:38:25 · Published:2008-12-05 · Views:438519
Summary
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.
Why HN recommends it
HN commenters recommend it as a thorough treatment of replacing conditionals with polymorphism and why flags and deep ifs can be code smells.
This talk gives a great overview of why boolean flags (rather, if-statements) can be a code smell — HN, 2022
Software architecture & design · Testing, debugging & developer tools
Subtitles (excerpt)
>> HEVERY: Thank you guys for coming. By the way, these are the new and improved code quality talks. We have Dave Astle who's done a great job revamping them and so these are the new and improved ones. So if you've seen him before, come again and we'll do it again. Is it not--oh, I have to talk over here, huh. So haha. I'm so used to the clip-on microphone that--thanks for reminding me. Okay. So, today we're going to talk about basically conditionals and polymorphism and how that affects testability. So here's the premise and this is a bit of a crazy premise. And that is, back in a day when we went from the basic world, it's not even procedural languages, what are they called? Well, the basics of the world into procedure world were able to get rid of go to's. And I don't think anybody has really missed them. So here's a crazy thought and that is if you go from procedural languages to object-oriented languages, you can get rid of quite a few if statement. I'm not going to go as far as say all of them but for the most part you can get rid of most of them. It's actually kind of fun to see if you can try writing code without an if. It's a very unique way of writing code. As a matter of fact, there's even certain languages out there like Smalltalk were the
On 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: [VIDEO] OP's blogpost advocates for data-oriented design (e.g. Entity Component Systems) as a mechanism for avoiding this, whereas the talk I'… — Mr_P, 2022-05
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. [VIDEO] — VBprogrammer, 2010-06
Google posted a tech talk about this a while ago: [VIDEO] which is more comprehensive than the posted article. — derwiki, 2009-09
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 ty… — tacitusarc, 2023-11
Misko Hevery did a Google Tech Talk about this some years ago, he also use a very similar example with switching on the birds. [VIDEO] — efraim, 2016-06
Related videos
- A Talk Near the Future of Python (a.k.a., Dave live-codes a WebAssembly Interpreter) · David Beazley · 1:01:45
- Treating the Farm as an Ecosystem with Gabe Brown Part 1, The 5 Tenets of Soil Health · Living Web Farms · 2:31:00
- A4 / V2 Rocket in detail: Turbopump · Astronomy and Nature TV · 1:51:13
- Alex Evans at Umbra Ignite 2015: Learning From Failure · Media Molecule · 30:46
- RailsConf 2014 - All the Little Things by Sandi Metz · Confreaks · 38:47
- "Simple Made Easy" - Rich Hickey (2011) · Strange Loop Conference · 1:01:38
- "Making Impossible States Impossible" by Richard Feldman · elm-conf · 25:06
- "Testing Distributed Systems w/ Deterministic Simulation" by Will Wilson · Strange Loop Conference · 40:20
- 🚀 TDD, Where Did It All Go Wrong (Ian Cooper) · DevTernity Conference · 1:03:55
- Bret Victor - Inventing on Principle · Rui Oliveira · 54:20
- How To Design A Good API and Why it Matters · Google TechTalks · 1:00:19
- The Value of Values with Rich Hickey · InfoQ · 31:43
- Overwatch Gameplay Architecture and Netcode · GDC Festival of Gaming · 1:04:03
- Solving Problems the Clojure Way - Rafal Dittwald · Clojure/north · 1:02:26
- Lecture 1A: Overview and Introduction to Lisp · MIT OpenCourseWare · 1:12:55
- Debugging Under Fire: Keep your Head when Systems have Lost their Mind • Bryan Cantrill • GOTO 2017 · GOTO Conferences · 52:34