Why are the curly braces required for a minimal Record declaration?
Swaranga Sarma
sarma.swaranga at gmail.com
Sun Apr 26 19:55:11 UTC 2020
Thank you everyone for the insight. Appreciate it.
Regards
Swaranga
On Sun, Apr 26, 2020 at 8:42 AM Brian Goetz <brian.goetz at oracle.com> wrote:
> John and Remi correctly pointed out that some punctuation is necessary,
> and that having a special rule (like allowing a semicolon instead of a pair
> of braces) doesn’t really carry its weight, since it only saves one
> keystroke. Here’s another reason.
>
> We actually did prototype it originally where you could drop the braces,
> and say
>
> record Foo(int x);
>
> But it doesn’t take long before you start asking “can I omit the braces on
> an empty class or interface? what about methods too?” Which brings us to
> a general principle that is in play for a feature like this: minimizing the
> gratuitous differences between records and classes, because we don’t want
> to burden users with keeping a lot of silly rules in their head like “on
> tuesdays, you get two braces for the price of one.”
>
> This principle comes up over and over again; we saw one yesterday on this
> list (“can I please have non-nullable records”), and there are many more,
> ranging from the very reasonable-seeming “can I invoke a record constructor
> by parameter name rather than positionally” to the absurd “can we omit
> semicolons in records, it’s not incompatible” (yes, we actually got this
> one.)
>
> Every one of these differences adds friction:
>
> - Users have to remember that they can (do the new thing) in records, but
> not classes;
> - Users will complain “why can’t classes do this too”, and are quite
> likely to view the glass as being mostly empty rather than partially full;
> - It is harder or less compatible to migrate records to classes, because
> they will have features that can’t be represented in otherwise-equivalent
> classes.
>
> Like all “syntactic sugar”, there is the risk of a sugar high, and the
> resulting glycemic crash. We tried to limit the sugar in records to that
> needed to achieve the semantic goal — nominal tuples.
>
> > On Apr 25, 2020, at 4:39 PM, Swaranga Sarma <sarma.swaranga at gmail.com>
> wrote:
> >
> > Records is a new feature and does not carry the same baggage as classes
> do.
> > Looking at a minimal Record Point declaration:
> >
> > record Point(int x, int y) {}
> >
> > Every part of this declaration makes sense to me expect the curly braces
> > '{}'. Why is that required if I do no intend do override any part of the
> > record?
> >
> > I am probably missing something; appreciate the insight.
> >
> > -Swaranga
>
>
More information about the amber-dev
mailing list