<div dir="ltr"><div>John answered already to most of the points, but I want to give my own insights as well.</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"><p class="MsoNormal"><span style="color:rgb(33,33,33);font-family:"Iosevka Fixed SS16"">Even though the syntax is ugly, the current implementation of the static getClassCssMetaData() is<span> </span><i>nearly perfect</i>, considering the lack of some kind of a 'lazy' keyword in java.</span></p></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="color:rgb(211,207,202);font-family:"Iosevka Fixed SS16"">I don't buy Nir's argument about "questionable API".  The API is codified by Node.getCssMetaData() and the current implementation will be perfect with the proposed utility method</span><span style="color:rgb(211,207,202);font-family:"Iosevka Fixed SS16""> </span> </blockquote><div><br></div><div>Let's look at what implementation is required from a user who wants to write their own styleable control:</div><div><br></div><div>1. Create styleable properties.</div><div>2. Create a list of these properties to be passed on.</div><div>3. Create a public static method that returns the concatenation of this list with the one of its parent. (This method happens to be poorly documented, as mstr said.)</div><div>4. Create a public non-static method that calls the static method in a forced-override pattern because otherwise you will be calling the wrong static method. (This method's docs seem to be just wrong because you don't always want to delegate to Node's list.)</div><div><br></div><div>This is mostly redundant work with copy-paste and pitfalls, especially the need to manually specify the parent. I would say that this is a very cumbersome implementation that would not pass code review.</div><div><br></div><div>I'm not sure if users even need access to those styleable lists themselves, maybe for GUI builders/analyzers? Surely you don't need 2 methods that do the same thing, and both of those codify the API.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p class="MsoNormal"><span style="color:rgb(33,33,33);font-family:"Iosevka Fixed SS16"">What the current code does is two things - a lazy initialization, meaning the code will get executed only when needed, and it has zero per-instance overhead.  I don't think anyone can suggest a better way of doing it.</span></p></blockquote><div><br></div><div>I'm confused by the notion that this is important. We're talking about static data, that is, per class, not per instance. How many styleable classes do we intend to use in an application? 100? Are we talking about saving 1KB of memory or 1 millisecond of runtime? *Per instance* is important, *per class* is negligible.</div><div>And why is the need for laziness? John also mentioned that any displayed instance of a class will initialize these anyway (on first use). A benefit can only arise if we create an instance but don't show it, in which case why did we create it?</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><p class="MsoNormal"><span style="color:rgb(33,33,33);font-family:"Iosevka Fixed SS16"">And I would be very much interested to hear from Nir his idea of an API that is not questionable.  I think we'll all benefit from learning how to make javafx better.</span></p></blockquote><div><br></div><div>Are we stuck with the current behavior of steps 2 to 4 above, or can we circumvent it for future cases? Do we only deal with controls here, or skins also because (as mentioned by John and Michael) they can also add styleable properties?</div><div><br></div><div>If I had to touch the least amount of code, I would at least make the concatenating method auto-resolve the parent of the current class by calling `MethodHandles.lookup().lookupClass().getSuperclass()`, eliminating that pitfall. Then we don't need the static method as far as I can see since its whole purpose was to allow this recursive concatenation (except in cases like ContextMenuContext that do something weird).</div><div><br></div><div>I think that a better overall approach could be with annotations on styleable properties and an annotation processor. It can have the following benefits:</div><div>* Automatic access to the declared styleable properties.</div><div>* Usable both in controls and in skins (or other classes).</div><div>* Auto-generation of the css reference that is coupled with these.</div><div>* Mention of the corresponding css attribute in their documentation (like I wanted previously <a href="https://mail.openjdk.org/pipermail/openjfx-dev/2022-February/033482.html">https://mail.openjdk.org/pipermail/openjfx-dev/2022-February/033482.html</a>).<br></div><div><br></div><div>It will depend on what exactly we need to do with these properties.</div><div><br></div><div><br></div><div><br></div><div>By the way, John</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Lazy initialization in many places that IMHO is not needed</blockquote><div><br></div><div>I noticed this for the first time in classes like Box, Sphere and Cylinder. Their dimension properties are lazily initialized, but are also initialized on construction, so I never understood what the point was.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 1, 2023 at 5:57 AM John Hendrikx <<a href="mailto:john.hendrikx@gmail.com" target="_blank">john.hendrikx@gmail.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>
    <p>Hi Andy,<br>
    </p>
    <p>Let me start to say that I had no problem with this PR being
      merged as I already agreed with one of the first versions.</p>
    <p>Sometimes then on the same PR there can be some discussions on
      what else can be done in this area, potentially maybe even
      alleviating the need for the change (X/Y problem, ie. why do you
      need this method? Because you need to concatenate lists, but the
      underlying reason is that the CSS property initialization is
      somewhat clumsy).<br>
    </p>
    <div>On 01/12/2023 01:11, Andy Goryachev
      wrote:<br>
    </div>
    <blockquote type="cite">
      
      
      
      <div>
        <p class="MsoNormal"><span>Dear colleagues:</span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span>there were a couple of comments
            after I withdrew<span> </span><a href="https://github.com/openjdk/jfx/pull/1296" title="https://github.com/openjdk/jfx/pull/1296" target="_blank"><span style="font-family:Calibri,sans-serif;color:rgb(0,120,215)">https://github.com/openjdk/jfx/pull/1296</span></a>for
            reasons of frustration, so I wanted to respond to those in
            the openjfx list.</span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="margin-left:0.5in;font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span>><span> </span></span><span style="font-size:12pt;color:rgb(33,33,33)">I pondered that back
            when I was working on replacing these static initializers
            with the<span> </span></span><code><span style="font-size:12pt;color:rgb(33,33,33)">.of</span></code><span><span style="font-size:12pt;color:rgb(33,33,33)"> </span></span><span style="font-size:12pt;color:rgb(33,33,33)">collection variants.
            It doesn't work here for problem stated above - we need to
            modify an unmodifiable list, which is why I didn't touch
            them in that pass. While the proposed method is useful for
            eliminating some ugly syntax, cementing a questionable API
            with more a public API doesn't seem to me like the right
            direction. If the method is made internal only, then that's
            fine. Alternatively, if the method is made useful outside of
            this specific context, then even if it won't be used here,
            it could be used in other places, and that's also fine.</span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span style="font-size:12pt;color:rgb(33,33,33)"> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span>Even though the syntax is ugly,
            the current implementation of the static
            getClassCssMetaData() is<span> </span><i>nearly
              perfect</i>, considering the lack of some kind of a 'lazy'
            keyword in java.</span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
      </div>
    </blockquote>
    It may be "nearly perfect" from an optimization viewpoint, but it is
    clumsy and unwieldy for anyone wanting to implement CSS properties.<br>
    <blockquote type="cite">
      <div>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span>What the current code does is two
            things - a lazy initialization, meaning the code will get
            executed only when needed, and it has zero per-instance
            overhead.  I don't think anyone can suggest a better way of
            doing it.</span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
      </div>
    </blockquote>
    <p>This was already mentioned on the PR, but I'll repeat it here:
      what is the lazy initialization for?  As soon as these Nodes need
      to be shown, all the metadata will have been queried already. I
      don't see any benefit making them lazy so you can create Nodes
      faster, as long as they are never shown.<br>
    </p>
    <blockquote type="cite">
      <div>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span>I don't buy Nir's argument about
            "questionable API".  The API is codified by
            Node.getCssMetaData() and the current implementation will be
            perfect with the proposed utility method (and maybe we can
            address some other comments from<span> </span><a href="https://git.openjdk.org/jfx/pull/1293#discussion_r1411406802" title="https://git.openjdk.org/jfx/pull/1293#discussion_r1411406802" target="_blank"><span style="font-family:Calibri,sans-serif;color:rgb(0,120,215)">https://git.openjdk.org/jfx/pull/1293#discussion_r1411406802</span></a><span> </span>).</span></p>
      </div>
    </blockquote>
    <p>How can there be any doubt that this API is questionable?  It
      ignores a core feature of Java (inheritance) and moves this burden
      to the user by calling static methods of its direct parent... in
      order to implement CSS property **inheritance** -- it also burdens
      any subclass with the caching of these properties (because
      "performance"), and to make those properties publicly (and
      statically) available so another subclass might "inherit" them.</p>
    <p>The API is clumsy enough that I loathe creating stylable
      properties for the sheer amount of boilerplate that surrounds
      them.<br>
    </p>
    <p>Some alternatives have been suggested, but are shot down without
      thinking along to see if there might be something better possible
      here.  Solutions where some of the common logic is moved to either
      Node or the CSS subsystem are certainly worth considering.<br>
    </p>
    <blockquote type="cite">
      <div>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px"><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span> </span><span style="color:rgb(33,33,33)"><u></u><u></u></span></p>
        <p class="MsoNormal" style="font-variant-caps:normal;text-align:start;word-spacing:0px">
          <span>... a few bytes and cpu cycles
            would get saved ...<br>
          </span></p>
      </div>
    </blockquote>
    <p>This is not for you specifically, but JavaFX has a lot of
      "optimizations", some resulting in really questionable patterns
      that have/are hurting us:</p>
    - Reimplementing core collection classes for some benefit, but then
    only partially implementing them (and often buggy), and/or
    completely breaking the collection contract [BitSet]<br>
    <p>- Lazy initialization in many places that IMHO is not needed
      (benchmark should be time to show window, anything accessed before
      that need not be lazy, and is likely counterproductive)<br>
    </p>
    <p>- Using plain arrays in many places, with a lot of custom code
      that's already available in some standard collection class or as a
      standard pattern; the custom code often has untested edge cases
      that contain bugs [ExpressionHelper]<br>
    </p>
    <p>- Making things mutable; surely mutating something must always be
      faster than having to create a new object? Except that if there's
      a lot of duplication going on because these objects are
      unshareable (because mutable), the cost/benefit is no longer so
      clear (but try to prove that with a micro benchmark)
      [PseudoClassState / StyleClassSet]<br>
    </p>
    <p>- Also see many usages of LinkedList, a class that if you'd never
      use it, you'd be better off 99.999% of the time; use of that class
      should always be explained in a comment, and proven to be better
      with a benchmark [too many places to list]<br>
    </p>
    <p>The list goes on; many of the optimizations I've seen would make
      sense for C/C++, but not for Java.  Now I don't mind some
      optimizations, but practically none of them are documented
      (deviating from the standard path always deserves an explanation
      for the next developer) and I suspect they were never verified
      either.  I've done extensive "optimization" before, with
      benchmarks, and you'd be surprised what is actually faster, and
      what makes no difference whatsoever -- even then, after
      benchmarking, if the difference is small, it's best to use
      established patterns, as that's what the JDK optimizes for.  What
      is marginally faster now, may not be faster on the next JDK, with
      a different GC, when run in a real application (caches will be
      used differently), or on a completely different architecture.</p>
    --John
  </div>

</blockquote></div>