Skip to content

Commit 1a842fa

Browse files
committed
Add consistency section, rel #285
1 parent 8427932 commit 1a842fa

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

index.bs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,53 @@ Naming APIs well makes it much easier for authors to use them correctly.
289289
See the more detailed <a href="#naming-is-hard">Naming principles</a> section
290290
for specific guidance on naming.
291291

292+
<h3 id="consistency">Consistency</h3>
293+
294+
It is good practice to consider precedent in the design of your API
295+
and to try to be consistent with it.
296+
297+
There is often a tension between API ergonomics and consistency,
298+
when existing precedent is of poor usability.
299+
In some cases it makes sense to break consistency to improve usability,
300+
but the improvement should be very significant to justify this.
301+
302+
<!-- TODO: example? -->
303+
304+
Since the Web Platform has gradually evolved over time,
305+
there are often multiple conflicting precedents
306+
which are mutually exclusive.
307+
You can weigh which precdent to follow by taking into account
308+
prevalence (all else being equal, follow the more popular precedent),
309+
API ergonomics (all else being equal, follow the more usable precedent),
310+
and API age (all else being equal, follow the newer precedent).
311+
312+
<!-- TODO: example? -->
313+
314+
There is often a tension between internal and external consistency.
315+
<em>Internal consistency</em> is consistency with the rest of the system,
316+
whereas <em>external consistency</em> is consistency with the rest of the world.
317+
In the Web Platform, that might materialize in three layers:
318+
consistency within the technology the API belongs to (e.g. CSS),
319+
consistency with the rest of the Web Platform,
320+
and in some cases external precedent,
321+
when the API relates to a particular specialized outside domain.
322+
In those cases, it is useful to consider what the majority of users will be.
323+
Since for most APIs the target user is someone who is familiar with the
324+
technology they are defined in,
325+
err on the side of favoring consistency with that.
326+
327+
<div class="example">
328+
One example is
329+
<a href="https://www.w3.org/TR/css-color-4/#funcdef-lab">Lab colors</a>:
330+
It would be more consistent with the rest of CSS to use percentages for L (0%-100%),
331+
but more consistent with the rest of Color Science to use a unitless number (0-100).
332+
There was a lot of heated debate,
333+
which resolved in favor of percentages,
334+
i.e. consistency within CSS.
335+
</div>
336+
337+
There is also a separate section on <a href="#naming-consistency">naming consistency</a>.
338+
292339
<h3 id="feature-detect">New features should be detectable</h3>
293340

294341
Provide a way for authors to programmatically detect

0 commit comments

Comments
 (0)