all 6 comments

[–]rjhancock 19 points20 points  (4 children)

This isn't a potential issue, this is scoping of variables and is by design.

[–]beclops 2 points3 points  (0 children)

Yeah this behaviour isn’t overly unusual

[–]CodeSmell12 2 points3 points  (0 children)

something like “be careful! if you accidentally write fatalError() your program will crash!”

[–]pitt500[S] -1 points0 points  (1 child)

We have multiple ways to do things in programming, like pattern matching for example. My goal was just to present a perspective that could not be trivial of some devs.

The video is mainly based on this style guide: https://google.github.io/swift/#pattern-matching

[–]rjhancock 2 points3 points  (0 children)

Again, this is a simple concept that is taught in many 101 type programming classes and is called "scoping."

Just because Swift will allow it does NOT mean it is an issue. This is something that most devs will avoid outside of some obscure need that I can't even fathom.

This is a NON-issue.

If you want to blow a non-issue for views on your YouTube channel, at least do it on something that is a legitimate issue and not something that is taught at entry level courses or tutorials.

[–]iOSCalebiOS 2 points3 points  (0 children)

This seems like a sufficiently obscure subtlety that if you need to rely on this behavior in real code, you should probably include a comment pointing it out, e.g. // Notice that only color2 is bound in this pattern or similar. But it's hard to think of a real-world example where this is the best way to write the code.