<div dir="ltr">Since first responding I've now done considerable brushing up on the various amber archives, and have gained a better understanding of the resistance to anything that looks like by-name abuse of derived record creation.<br><br>I look forward to being able to use 'with' with other patterns, and agree, that, given the transformation that Java will undertake in the coming years with the various plans for pattern matching, that this will probably fit in fine as "Java-like".<div><br></div><div>Would still prefer to have 'new', but alas, I'm just one small opinion amongst many, and don't have anything further to add discussion wise that Remi hasn't covered in the expert group, and would not have replied if I hadn't managed to accidentally drop amber-dev as a cc.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Nov 22, 2024 at 10:47 AM Brian Goetz <<a href="mailto:brian.goetz@oracle.com">brian.goetz@oracle.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u>
<div>
<font size="4" face="monospace">Let's set aside the syntax; suffice
it to say there are probably several million who like and several
million who don't, for basically any option, so one more vote
yea/nay does not move the needle.<br>
<br>
But I do want to take exception to "not powerful enough" (and
also, to some degree, "not Java-like"); it is actually far more
powerful than what other languages do in this space, but not in an
obvious way.<br>
<br>
Most languages that have a feature like this are fairly
constrained. Either you can only do property assignments, or
there is some "DSL" subset of the language that you can use. The
block on the RHS, on the other hand, can contain any Java
statement -- loops, conditionals, whatever. It is not a
constrained subset. <br>
<br>
You can consider a `with` block `x with { STATEMENTS }` to be
largely equivalent to:<br>
<br>
x = switch (x) { <br>
case TypeOfX(COMPONENTS) -> { STATEMENTS; yield new
TypeOfX(COMPONENTS); }<br>
}<br>
<br>
The `with` syntax is largely sugar for this.<br>
<br>
When you can declare patterns in arbitrary classes, `with` will
work with them as well.<br>
<br>
<br>
<br>
</font><br>
<br>
<div>On 11/21/2024 1:25 AM, Ryan Leach
wrote:<br>
</div>
<blockquote type="cite">
<div dir="auto">That's fair Brian.
<div dir="auto"><br>
</div>
<div dir="auto">In truth when I was writing this post, the stuff
about object initializers was tacked on as I was thinking
through potential pitfalls and potential benefits of
alternative syntax then that proposed by the JEP.</div>
<div dir="auto"><br>
</div>
<div dir="auto">I still think my original point has strength in
'new' being used for readability and teachability. </div>
<div dir="auto"><br>
</div>
<div dir="auto">If it seems wordy, I agree, but I'm not in love
with the 'with' keyword, reviewing other languages, it seems
there's a vast variety of uses for the 'with' keyword already
existing, and independently, various ways of tackling the
copy-with-changes problem.</div>
<div dir="auto"><br>
</div>
<div dir="auto">The ambiguous use of 'with' does mean it's kinda
free real estate, especially since some uses coincide with
record / struct copying.</div>
<div dir="auto"><br>
</div>
<div dir="auto">The only benefit I can see from the current
preview, where `with` can only be used with records (which
seems a little restrictive) is the ability to treat them like
left hand side values, and thus able to use stuff like ` =* 2`
which seems a little niche, but I think, innovative. </div>
<div dir="auto"><br>
</div>
<div dir="auto">But it just doesn't feel "Java-like" and doesn't
provide enough power to justify its own keyword in its current
form (in my opinion).</div>
<div dir="auto"><br>
</div>
<div dir="auto">(If there's loose ideation level plans for
future directions to take it, that's probably why.)</div>
<div dir="auto"><br>
</div>
<div dir="auto">A review of how other languages do
record/struct/object copying looks like it's a choice of
either </div>
<div dir="auto"><br>
</div>
<div dir="auto">1. object destructuring syntax.</div>
<div dir="auto">2. 'with'-like copying (even if it uses other
symbols or keywords)</div>
<div dir="auto">3. Copy methods with by-name optional
parameters.</div>
<div dir="auto"><br>
</div>
<div dir="auto">So I'm kinda at a loss on whether this is even
the best way to approach this solution now after looking into
it more. </div>
<div dir="auto"><br>
</div>
<div dir="auto">---</div>
<div dir="auto"><br>
</div>
<div dir="auto">Where can I find reading on how this feature was
developed? I feel like I'm probably retreading old ground,
perhaps needlessly.</div>
<div dir="auto"><br>
</div>
<div dir="auto">---</div>
<div dir="auto"><br>
</div>
<div dir="auto">As a brief aside for context, I've had
professional work as a C# programmer in the past, and I've
experienced friction to the amount of 'needless' language
additions they've made vs languages like Scala, especially in
regards to stuff like all the different property syntax that
exists, because of the amount of "fiddling" required as a
class evolves as the syntax doesn't always lead itself well to
being edited between one form and another.</div>
<div dir="auto"><br>
</div>
<div dir="auto">For this reason, I'm a little against changes
that don't feel orthogonal or language-native being bolted on
to fix specific problems.</div>
</div>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Thu, 21 Nov 2024, 3:23 am
Brian Goetz, <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div> <font face="monospace" size="4">While I would not say
that the `x with B` syntax is written in stone, I don't
think just stapling `new` to it is helpful. I will point
out (as I have several times before) that I think trying
to coerce the `with` syntax into a way to get by-name
invocation of constructors is a very bad move. I totally
get why people keep reaching for it, but it's the wrong
way to get there. Maybe we'll get there some other way,
maybe we won't, but we definitely won't get there this
way.</font><br>
<br>
<br>
<div>On 11/20/2024 11:46 AM, Olexandr Rotan wrote:<br>
</div>
<blockquote type="cite">
<p dir="ltr">Yea, Brian, I agree with you. I wasn't even
proposing that as argument against proposal, more like a
nasty little detail, hence this is a "side note".
Moreover, if (or, I hope, when) more record features
expanded to all classes, compiler will still be required
to clone non-value objects since they can be mutable,
and with implies making a copy (although not always
actually has to do it as in my example).</p>
<p dir="ltr">But I gave more thought to this today, and
what I have concluded is that I would rather vote
against it. The reason is that only value that "new"
brings to the table here is better "human readability".
But, for me it seems more like a mumbling. I am, I
guess, more of a writablity guy than most people here,
so I don't really like mumbling. Also it is some noise
for reader. "New" here does not help resolve some
ambiguity nor for compiler nor for reader, at least as
it seems for me. That's why I would say I am not a fan
of this syntax</p>
<br>
<div class="gmail_quote">
<div dir="ltr" class="gmail_attr">On Wed, Nov 20, 2024,
15:18 Brian Goetz <<a href="mailto:brian.goetz@oracle.com" rel="noreferrer" target="_blank">brian.goetz@oracle.com</a>>
wrote:<br>
</div>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
> Hello. Just a side note: AFAIK "new", by spec,
guarantees that new <br>
> instance of object is returned<br>
><br>
<br>
Historically this is true. However, when Valhalla
gives us value types, <br>
the "new"-ness of a new value object will be
indistinguishable from an <br>
old object. So I would advise against taking this
"new means new" <br>
dictum too literally.<br>
<br>
> , so it can potentially affect implementation
requirements for <br>
> compilers, forcing them to copy records even if
with expression block <br>
> is empty, i.e.<br>
><br>
> var b = new a with {}<br>
><br>
> Unless there is a exception for such syntax, new
will mandate that b <br>
> != a (by reference)<br>
><br>
<br>
... unless a and b are value objects, in which case ==
compares their <br>
state, not their identity (because they have none.)<br>
<br>
<br>
</blockquote>
</div>
</blockquote>
<br>
</div>
</blockquote>
</div>
</blockquote>
<br>
</div>
</blockquote></div>