Code Smells - 'Switches' in Unity3d / C# Architecture
Video Statistics and Information
Channel: Jason Weimann
Views: 58,836
Rating: undefined out of 5
Keywords: code refactoring, code smells, clean code, switch statements, code smell, code quality, technical debt, tech debt, unity3d, unity tutorial, unity, design patterns, unity3d college, game programming patterns, unity solid, c# programming, unity clean code, unity architecture, architecture, tips and tricks, unity c#, c# code review, unity3d architecture, code review, unity project, unity tips and tricks, refactoring, unity3d solid, unity design patterns, #unitytips, unity3d c#
Id: nqAHJmpWLBg
Channel Id: undefined
Length: 25min 20sec (1520 seconds)
Published: Mon Aug 05 2019
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
If only you'd put your argument forward in a written form.
Switch statements can be abused just like anything, but I personally find them to be an excellent companion to enums like you're using here. The problem here isn't the switch though: the IsValidTargetForSpellType method would have returned a false result for the new spell with or without switch. When you add a new value to your enum you have to fix the checks on that enum wherever they may be. It's just part of being a programmer. If the code had been written using if states or a mapping or any other method it still would have failed when you didn't edit the validity check.
Not gonna watch a video about this, honestly, because it's slower for me. There are a lot of resources out there about switches and code smells. Here's a good one against switch statements in certain cases https://stackoverflow.com/questions/126409/ways-to-eliminate-switch-in-code#126455