-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
[p5.js 2.0 RFC Proposal]: API audit #7460
Comments
Thanks for getting these all together Greg! Generally agreed with everything. Here are a few comments on some of the points:
|
Thanks @davepagurek! I really appreciate your thorough explanations. In case anyone else has comments, we're planning to move discussion of particular API changes to separate issues for each affected section of the API. I'll also make a separate issue for the quality assurance process and link to it from this issue. We'll dedicate discussion in the current issue to the API design criteria and guidelines. P.S. I like your use of a dropdown for extra context. I've been using footnotes, which violate the spatial contiguity principle that we discussed haha |
Increasing access
This proposal would make p5.js 2.0 and later versions more beginner friendly, in three stages:
Which types of changes would be made?
Most appropriate sub-area of p5.js?
What's the problem?
The p5.js API contains quite a few inconsistencies and other forms of complexity. This complexity makes p5.js harder to learn and harder to use, since users experience it directly through its API. While some parts of the API have been simplified for 2.0, such as the API for vertex functions, other complexities remain. This is because identifying and preventing complexities in a large API is difficult without clear guidelines and a practical quality assurance process.
What's the solution?
1. Establish criteria and guidelines
In order to identify and prevent unnecessary complexity in the p5 API, we can develop a list of criteria we want it to satisfy. We can also provide guidelines for common types of features, such as getters and setters. Initial criteria and guidelines are listed below.
Criteria
For a given feature, these design criteria may be considered with respect to naming, syntax, and behavior.
Guidelines
stroke()
andfill()
, should act jointly as a getter (when no argument is passed) and a setter.vertexProperty(name, value)
should act as getters whenvalue
is omitted.stroke()
, joint getters/setters should be used when possible. However, if separate getters and setters are to be used, they should begin with “get” and “set,” except for getters for Booleans, which should have names such asisLooping()
.disableFriendlyErrors
to toggle friendly errors and using functions likefullscreen()
andautoSized()
to toggle other settings.)These guidelines are included as examples. During the second phase, when specific kinds of issues are dealt with, the guidelines can be fleshed out.
References:
2. Perform an audit (a scavenger hunt!) and fix problems
Under ideal circumstances, the community could hold a scavenger hunt for features that don't adhere to p5's API criteria. Beginners could make significant contributions by spotting naming inconsistencies, for example. However, since p5.js 2.0 will be released relatively soon, I performed a rapid audit of the full API, to get the ball rolling.
Methodology
I skimmed through the whole reference and looked for issues that jumped out to me as potential areas of concern (I didn’t systematically apply all criteria to each feature). I also skipped over some things that I didn’t suspect were problematic.
Caveats:
baseColorShader()
.p5.Table
andp5.TableRow
shuffle()
)p5.NumberDict
,p5.StringDict
, andp5.TypedDict
Results
For illustration, only a partial sample of results from the rapid audit are included here. Skimming this section should give a rough sense of what's at stake.
Note: The sample includes examples of potential problems with naming, syntax, and semantics (broadly defined). Each example is tagged with the criteria that fail to be satisfied.
This partial sample of API problems can be replaced with separate GitHub issues, with one issue for each affected section of the reference. Those issues can be linked from here, in a checklist.
Note: The sample only includes issues that may require breaking changes, but the audit did reveal other issues that could be fixed with non-breaking changes after the release of p5.js 2.0.
Naming
color()
stroke()
.color()
withcreateColor()
.getTargetFrameRate()
/frameRate()
getTargetFrameRate()
and turnframeRate()
into a joint getter/setter.setAttributes()
setAttributes(key, value)
only sets a single attribute. Second, the name is ambiguous, since it only sets attributes of the WebGL drawing context, but this isn't advertised in the name.setAttributes()
with, say,canvasProperty(key, value)
.onended()
touchEnded()
.onended()
withplayEnded()
. (However, there is a deeper issue, which is that these functions take a callback function, whereas event handlers likedoubleClicked()
are defined directly by the user. If one of these two behaviors cannot be used in all cases, then they should be distinguished by their names. For example, a name likeonTouchEnd()
could be used for one type of behavior and a name liketouchEnded()
could be used for another.)Syntax
createModel()
,loadModel()
normalize
andfileType
are out of order in one signature,fileType
is out of order in another, andfileType
is missing from one signature).spotLight()
,directionalLight()
andpointLight()
spotLight()
has eight signatures. It accepts three vectors as input, but in some signatures, some of these vectors are specified asp5.Vector
objects whereas others are not. This makes the documentation unnecessarily complicated and leads to code that’s hard to read. The other listed features have the same type of issue.p5.Vector
specifications. The pure componentwise signature ofspotLight()
has 11 parameters and is very hard to read, but keeping both the pure componentwise and purep5.Vector
signatures reduces breaking changes and keeps these features consistent with other functions that take multiple vectors as input, such asquad()
. (Sincequad()
takes up to a whopping 14 parameters, and sincepoint()
already accepts both componentwise andp5.Vector
input, it makes sense to add support toquad()
and all other 2D primitive functions for both types of input.)p5.Shape
class developed for 2.0 has an interface that’s closer to that ofp5.Graphics
, and it may be exposed to users in a future version).Semantics
addClass()
,class()
p5.Element
class hasaddClass()
andclass()
, both of which add a class to the element. The difference is thatclass()
is a joint getter/setter that seems to makeaddClass()
unnecessary. Having both is likely to confuse users.addClass()
.millis()
millis()
returns the time since the sketch started running; all other functions, includingsecond()
, return the current time (e.g. if a sketch is run 32 seconds after noon, then when the sketch starts running,second()
will return 32 whereasmillis()
will return 0). Also, “millis” is an abbreviation, unlike the other function names; that doesn’t seem like enough to convey the difference in behavior.debugMode()
axisHelper()
andgridHelper()
functions should be an improvement. We might also consider functions likeaxesHelperProperty(key, value)
for greater readability and writability (effectively allowing named parameters).quad()
has multiple signatures and can create a shape in 2D or 3D,triangle()
only works in 2D. Other issues include shapes that can be drawn in WebGL mode but only by specifying xy-coordinates rather than xyz-coordinates. Some of these shapes support a detail parameter while others don’t. Some supportp5.Vector
arguments and others don’t. Rounding corners inrect()
andsquare()
adds another complication.3. Implement quality assurance process via issue templates
Bugs can be fixed in any version of p5. API problems cannot be fixed outside of a major version release (if at all), if they're like any of the problems listed above. To avoid introducing such problems in the future, we can implement a basic quality assurance process via the issue templates for new features and existing feature enhancements:
a. Documentation will be required before release (and encouraged before implementation).
b. Review will be required by multiple stakeholders.
Pros (updated based on community comments)
Cons (updated based on community comments)
Proposal status
Under review
The text was updated successfully, but these errors were encountered: