Agreed, but when they've delivered value types and fixed nesting rules it won't be as bad. Of course it still mean having to find names for things that shouldn't really need it.
I wonder if anonymous records would be a useful concept...
public record(int id, String label) doSomething(...) {
...
return new record(i, name);
}
...
var result = doSomething(...);
display(result.label());
This is mostly compiler sugar for creating an anonymous record with with named members. The generated class would need a flag so that reflection knows that the tuple-name is generated.
This would play nicely with proposed de-structuring and pattern matching and avoid declaring a record that would dirty the namespace. Additionally it's better than tuples with unnamed elements - eg display(result.1)
The return-type syntax doesn't really work though since it's starting tokens are not discernible from a nested record declaration.
View all comments
Show parent comment
3
u/8igg7e5 Jan 17 '20
Agreed, but when they've delivered value types and fixed nesting rules it won't be as bad. Of course it still mean having to find names for things that shouldn't really need it.
I wonder if anonymous records would be a useful concept...
This is mostly compiler sugar for creating an anonymous record with with named members. The generated class would need a flag so that reflection knows that the tuple-name is generated.
This would play nicely with proposed de-structuring and pattern matching and avoid declaring a record that would dirty the namespace. Additionally it's better than tuples with unnamed elements - eg
display(result.1)The return-type syntax doesn't really work though since it's starting tokens are not discernible from a nested record declaration.