-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency between MLGraphBuilder and MLBuffer construction #697
Comments
I think #529 is related. |
Factory methods on "context" objects is the existing, predominant pattern in 2D canvas, WebGL and WebGPU. Buffers, textures, bind groups, bind group layouts, shader modules, gradients, image data, and many more are all factory methods on the created context. At the same time, the official W3C design principles document advises that objects should have constructors when possible unless the object is a base class of other objects or requires special privileges, neither of which really applies in our case. For synchronous buffer creation, the same object is created whether the web developer types For objects which are synchronously created, using a constructor seems preferable as it's a guaranteed way to get a valid object. If we later decide to add async buffer creation, we can add a promise returning |
Just for the record, a long time ago, in a similar discussion, I got the following advice from @domenic (well documented in the design principles spec). It's in line with @RafaelCintron's comment above. Some of these could be applicable here, whether we move relevant stuff towards constructors, or towards factories representations.
So if But before deciding that, as @bbernhar pointed out, we should clarify timelines (#529), and capture their relationship vs. object creation. If creating |
+1. While |
From the web developer's perspective, when they create an However, as I said previously, there's prior art in other web APIs to have factory methods for context-y objects. |
To address this issue, I propose we have createBuffer() return a promise. It would:
Any objections? 👍== OK with change. |
As I mentioned on this comment thread I'm not opposed to making ...this isn't necessarily a blocking concern, though. And in the meantime (while we don't yet have #477) it is nice to know whether |
It's worth pointing out that since
|
An
MLGraphBuilder
and anMLBuffer
are both associated with anMLContext
howeverMLGraphBuilder
is created with a normal constructor whileMLBuffer
is created by thecreateBuffer()
method onMLContext
.We should consider removing
createBuffer()
and defining a normal constructor forMLBuffer
with the same semantics asMLGraphBuilder
(or add acreateBuilder()
method, but I'd prefer the former option).The text was updated successfully, but these errors were encountered: