Record construction
Brian Goetz
brian.goetz at oracle.com
Wed Mar 14 22:09:03 UTC 2018
> Minor tweak, but class names can get quite long. A keyword would be preferable:
Yes, that's also a realistic option, and reminiscent of instance
initializers (but has the advantage of _not_ being an instance
initializer, which already means something.) From a readability
perspective, I have a subjective preference for something that looks
like a constructor, but I'd not rule this out. (Remember, reading code
is more important than writing code, so I don't think the length of the
name is really the primary consideration.)
> Wild idea - is there a way for the library method to obtain the
> variable name and type used at the call site?:
>
> public static void isTrue(CallsiteBooleanExpression expr) {
> if (expr.isFalse()) {
> throw new IllegalArgumentExpression(expr.expressionString() + "
> must be true");
> }
> }
>
Putting it in terms of a variable name and type doesn't make sense,
because there might be multiple variable names and types:
Preconditions.require(x < y);
Doing so would require something like expression trees, a major project.
A less intrusive path (but still not trivial) would be to factor out the
dual "evaluate and textify" behavior of assert into a language feature,
so that assert()-style methods could be written as ordinary library
methods, and the method could receive, somehow, both the value and the
text of a condition:
MyLibrary.require( x < y )
Not crazy, but you've got to go a long way for it, so "wild" sounds
about right.
More information about the amber-dev
mailing list