pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <david.rowley@2ndquadrant.com>
Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>
Cc: pgsql-committers@lists.postgresql.org
Subject: Re: pgsql: Remove useless default clause in switch
Date: Mon, 23 Apr 2018 21:17:05 -0400
Message-ID: <9587.1524532625@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKJS1f9vS7W0MDp-DJ0ixg3bMhJo0vdU-vzjZR3CumvtaTP9cg@mail.gmail.com>
References: <E1fAd8s-0003wZ-AV@gemulon.postgresql.org>
	<CAKJS1f9vS7W0MDp-DJ0ixg3bMhJo0vdU-vzjZR3CumvtaTP9cg@mail.gmail.com>

David Rowley <david.rowley@2ndquadrant.com> writes:
> On 24 April 2018 at 03:12, Alvaro Herrera <alvherre@alvh.no-ip.org> wrote:
>> Remove useless default clause in switch

> I always thought that when all options were covered that we generally
> kept a default just in case someone added another enum and forgot to
> update the code.

Actually, there's an advantage to omitting the default for enum-based
switches, which is that many compilers will give you a compile-time
warning that you forgot a case.  That beats an elog(ERROR) that you
might or might not hit in testing.

> There are other examples in that file with the switch
> (part_scheme->strategy), these are not using enums.

If it's not based on an enum then the compiler isn't going to understand
that you missed a value, so having the elog is better than having nothing.

			regards, tom lane




view thread (8+ messages)  latest in thread

Message-ID: <9587.1524532625@sss.pgh.pa.us>
Permalink:  ../9587.1524532625@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/9587.1524532625@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, david.rowley@2ndquadrant.com, alvherre@alvh.no-ip.org
  Subject: Re: pgsql: Remove useless default clause in switch
  In-Reply-To: <9587.1524532625@sss.pgh.pa.us>
  References: <E1fAd8s-0003wZ-AV@gemulon.postgresql.org> <CAKJS1f9vS7W0MDp-DJ0ixg3bMhJo0vdU-vzjZR3CumvtaTP9cg@mail.gmail.com> <9587.1524532625@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox