On Tue, Aug 01, 2017 at 05:54:28AM -0700, [email protected] wrote:
> i believe you should avoid fallthrough statement except for auto-generated
> code.
>
> it's obscure what you are trying to accomplish with that piece of code, but
> surely you can do it in a better way.
They have its valid use to avoid situations like this:
| if cond1 && cond2 {
| if cond1 {
| do_stuff()
| }
| do_other_stuff()
| }
which can be rewritten like
| switch {
| case cond1:
| do_stuff()
| fallthrough
| case cond2:
| do_other_stuff()
| }
It's not quite visible due to cond* being short, but not so when they
involve comparisons against longish symbols exported from packages.
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.