Record construction

Remi Forax forax at univ-mlv.fr
Wed Mar 14 23:49:32 UTC 2018



----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Stephen Colebourne" <scolebourne at joda.org>, "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Mercredi 14 Mars 2018 23:09:03
> Objet: Re: Record construction

>> 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.

an implicit textualisation, we have briefly talk about that when looking for serializing lambdas
class MyLibrary {
  interface MyBooleanSupplier extends BooleanSupplier & Textualization {
  }
  
  void require(MyBooleanSupplier supplier) {
     supplier.toString() // get "x < y"
     suuplier.get()      // call () -> x < y with x and y bounded
     ...
  }
}

Rémi


More information about the amber-dev mailing list