<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Feb 21, 2023 at 2:09 AM <<a href="mailto:forax@univ-mlv.fr">forax@univ-mlv.fr</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><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><br></div><div><br></div><hr id="m_7863816392887730248zwchr"><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From: </b>"Brian Goetz" <<a href="mailto:brian.goetz@oracle.com" target="_blank">brian.goetz@oracle.com</a>><br><b>To: </b>"Remi Forax" <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>><br><b>Cc: </b>"Ron Pressler" <<a href="mailto:ron.pressler@oracle.com" target="_blank">ron.pressler@oracle.com</a>>, "Dan Heidinga" <<a href="mailto:heidinga@redhat.com" target="_blank">heidinga@redhat.com</a>>, "amber-spec-experts" <<a href="mailto:amber-spec-experts@openjdk.org" target="_blank">amber-spec-experts@openjdk.org</a>><br><b>Sent: </b>Tuesday, February 21, 2023 12:33:31 AM<br><b>Subject: </b>Re: Implicit Record Was: JEP draft: Implicit Classes and Enhanced Main Methods (Preview)<br></blockquote></div><div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><font size="4"><font face="monospace">You seem to have a very
        strange notion of what "works" means.  These all work just
        fine.  No one is suggesting that local and "shared" variables
        are unified.  If you find it confusing to teach fields early,
        then wait -- that's one of the choices.  <br></font></font><br>
    <blockquote>
      <div>Scope rules are different, being static is different,
        initialization rules are different, inference rules are
        different, even colors in IDEs are different.<br>
      </div>
    </blockquote>
    <br>
    Correct, and well understood.  Your point?  </blockquote><div><br></div><div>Implicit class remove the "class" shell, so you now have two syntactically identical things that are semantically different.</div><div>IMO, introducing dangling fields, a new feature in Java, does not worth the confusion it creates.<br></div></div></div></div></blockquote><div><br></div><div>Remi, I'm slightly confused here.  A local variable is declared inside a scope (the method) and a class variable (aka field) is declared in the implicit class.  There's at least an obvious visible boundary around the local variable which provides the scoping.  Students will by necessity need to understanding scoping fairly early when they deal with loops:</div><div><br></div><div>void main() {</div><div>   for (int i = 0; i < 10; i++) {</div><div>      var double = i * 2;</div><div>      System.out.print("" + i + "..." + double);</div><div>   }</div><div>}</div><div><br></div><div>"dangling fields" is the wrong mental model for this - it's fields in an implicit scope.  The key concept here (IMHO) is scoping which students will face even within a method.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><div></div><div><br></div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
    <br>
    <blockquote>
      <div>You did, by re-using the term "variables" for both local
        variable and fields.<br>
      </div>
    </blockquote>
    <br>
    Sorry, no.  They are both variables, but they are different sorts. 
    Just like "instance vs static" variables, or "final vs mutable"
    variables.  They are all variables (they have a name, and a type,
    and hold a value), and yet they each have different characteristics
    (and the characteristics can be combined; you can have shared final
    static variables, and local mutable variables, and....)<br>
    <br>
    I think you're taking a "I would prefer it work this way" and
    bootstrapping it into "the alternative is broken" (that's what
    "doesn't work" means.)  You should know by now that this is the best
    way to not have your arguments taken seriously!  </blockquote><div><br></div><div>I think you are talking about variable in general, i'm focused on local variable and fields in the context of implicit class, hence the difficulty to understand each other.<br></div><div>Implicit class makes the syntax of fields identical to the syntax of local variables and at the same time, the way to differentiate then is to explain what an implicit class is.</div></div></div></div></blockquote><div><br></div><div>As I said above, the way to differentiate them is to talk about scoping.  A local is scoped to the method it is declared in.  A field is scoped to be shared by all the methods in the file (and eventually refined to be within the class). </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><div><br></div><div>Again, i'm not against the notion of implicit container, i just think that implicit record makes more sense than implicit class, and i would like we discuss about that,<br></div><div>here is example where the container leaks,<br></div><div><br></div><div>  void main() {<br></div><div>    System.out.println(this);<br></div><div>  }<br></div><div><br></div><div>what it should print ?<br></div></div></div></div></blockquote><div><br></div><div>Whatever is typically printed by Object::toString .  I don't think the goal is to **hide** the implicit class - we're not making this.getClass() illegal - but to take the ceremony out of the presentation so that students (and other users) can write simple programs before they need to understand class structure.</div><div><br></div><div>--Dan</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div><div></div><div><br></div><div>regards,<br></div><div>Rémi<br></div><div><br></div><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
    <br>
    <br>
    <br>
    <div>On 2/20/2023 4:38 PM, <a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>
      wrote:<br>
    </div>
    <blockquote>
      
      <div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
        <div><br>
        </div>
        <div><br>
        </div>
        <hr id="m_7863816392887730248zwchr">
        <div>
          <blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><b>From:
            </b>"Brian Goetz" <a href="mailto:brian.goetz@oracle.com" target="_blank"><brian.goetz@oracle.com></a><br>
            <b>To: </b>"Remi Forax" <a href="mailto:forax@univ-mlv.fr" target="_blank"><forax@univ-mlv.fr></a><br>
            <b>Cc: </b>"Ron Pressler" <a href="mailto:ron.pressler@oracle.com" target="_blank"><ron.pressler@oracle.com></a>,
            "Dan Heidinga" <a href="mailto:heidinga@redhat.com" target="_blank"><heidinga@redhat.com></a>,
            "amber-spec-experts" <a href="mailto:amber-spec-experts@openjdk.org" target="_blank"><amber-spec-experts@openjdk.org></a><br>
            <b>Sent: </b>Monday, February 20, 2023 9:33:34 PM<br>
            <b>Subject: </b>Re: Implicit Record Was: JEP draft:
            Implicit Classes and Enhanced Main Methods (Preview)<br>
          </blockquote>
        </div>
        <div>
          <blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
            <blockquote>
              <div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
                <div>
                  <div><br>
                  </div>
                  <div>As i said earlier, it does not work because
                    fields and local variables have different semantics,<br>
                  </div>
                  <div>fields are initialized with a default value while
                    local variables need to be initialized before use.<br>
                  </div>
                  <div>So the curtain is just a veil that will be
                    pierced by any students moving declarations around.</div>
                </div>
              </div>
            </blockquote>
            <br>
            Of course it "works", it just might not work how you would
            prefer it to.</blockquote>
          <div><br>
          </div>
          <div>  var greetings = 0;<br>
          </div>
          <div><br>
          </div>
          <div>does not work,<br>
          </div>
          <div><br>
          </div>
          <div>  void main() {<br>
          </div>
          <div>    int greetings;<br>
          </div>
          <div>    System.out.println(greetings);<br>
          </div>
          <div>  }<br>
          </div>
          <div><br>
          </div>
          <div>does not work,<br>
          </div>
          <div><br>
          </div>
          <div>
            <div>  void main() {</div>
            <div>    static int greetings;</div>
            <div>    System.out.println(greetings);</div>
            <div>  }</div>
            <div><br>
            </div>
            <div>does not work,</div>
          </div>
          <div><br>
          </div>
          <div>  void main() {<br>
          </div>
          <div>    int greetings = 0;<br>
          </div>
          <div>    for(;;) {<br>
          </div>
          <div>      int greetings = 0;<br>
          </div>
          <div>    }<br>
          </div>
          <div>  }<br>
          </div>
          <div><br>
          </div>
          <div>does not work too.<br>
          </div>
          <div><br>
          </div>
          <div>Scope rules are different, being static is different,
            initialization rules are different, inference rules are
            different, even colors in IDEs are different.<br>
          </div>
          <div><br>
          </div>
          <blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"> 
            <br>
            <br>
            Prior to learning about fields, the user can perceive local
            variables (declared in a method) and "shared" variables
            (accessible to all members of the class.)  They can learn
            about their characteristics.  Then, when they learn about
            classes and fields and accessibility, they can learn that
            the variables they were calling "shared" are really fields. 
            The distinction between locals and fields is there from the
            beginning, though for most use cases, they will not notice
            the difference.  When they're ready to learn the fine
            differences, there's not anything to unlearn.  <br>
            <br>
            <blockquote>
              <div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)">
                <div>
                  <div>From my personal experience, unifying local
                    variable and field leads to more pain than gain,
                    mostly because local </div>
                </div>
              </div>
            </blockquote>
            <br>
            Who said anything about unification of fields and locals? 
            Where did you get such an idea that this is what is being
            proposed?  </blockquote>
          <div><br>
          </div>
          <div>You did, by re-using the term "variables" for both local
            variable and fields.<br>
          </div>
          <div><br>
          </div>
          <blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
            <br>
            First students will learn about statements.  Then they will
            probably learn about local variables.  They can be taught
            that they disappear when the method exits, and each
            invocation of the method gets a fresh copy.  Then they can
            learn about multiple methods, and then that there are
            variables that can be shared across methods and retain their
            values across method invocations, and while their
            declaration syntax is the same (they're both variables,
            after all), the _place_ in which they are declared is
            different (which is what makes them shared), and shared
            variables have slightly different characteristics (though
            not so different they have to learn this immediately).  They
            can learn the characteristics of shared variables when it
            makes sense to teach this.  And when the curtain is pulled
            back, they learn all fields have the characteristics of
            these shared variables.  </blockquote>
          <div><br>
          </div>
          <div>Record components behave as you said, they have slightly
            different characteristics than local variables and it's hard
            to not notice the difference syntactically.<br>
          </div>
          <div><br>
          </div>
          <div>record Hello(String name) {<br>
          </div>
          <div>  void hello() {<br>
          </div>
          <div>    System.out.println("hello " + name);<br>
          </div>
          <div>  }<br>
          </div>
          <div><br>
          </div>
          <div>  void bonjour() {<br>
          </div>
          <div>    System.out.println("bonjour " + name);<br>
          </div>
          <div>  }<br>
          </div>
          <div>}<br>
          </div>
          <div><br>
          </div>
          <div>Class fields are far more different than just the
            lifetime but have a very similar syntax.</div>
          <div><br>
          </div>
          <div>Rémi<br>
          </div>
          <div><br>
          </div>
          <blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;color:rgb(0,0,0);font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt"><br>
            <br>
            <br>
            <br>
            <br>
            <br>
          </blockquote>
        </div>
      </div>
    </blockquote>
    <br><br></blockquote></div></div></div></blockquote></div></div>