In first snippet, i didn't get the second if. cond1 is true anyway.
Second snippet is equivalent to
if (cond1) {
do_stuff()
do_other_stuff()
} else if cond2 {
do_other_stuff()
}
which is more straightforward than using fallthrough imo.
On Wednesday, August 2, 2017 at 9:03:35 AM UTC+2, Konstantin Khomoutov
wrote:
>
> On Tue, Aug 01, 2017 at 05:54:28AM -0700, [email protected]
> <javascript:> 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.