Don't Roll Your Own …

79 points by susam


chrismorgan

Don't roll your own page scrolling.

Correct. You cannot make it work as well as native. The closest I will grant to an exception is for things like maps, where it is customary for scrolling to map to zoom.


Don't roll your own link navigation.

Strongly disagree with this being a rule. I would instead say: reconsider using client-side routing (CSR). For general content sites, I would strongly discourage it, but for some sorts of apps I would strongly encourage it; and things like GitHub sit somewhere in the middle.

The one part I would insist upon is that you must always use real <a href> elements, so that native browser functionality works. But for some sorts of apps it’s perfectly reasonable to intercept plain clicks and handle the routing on the client side.

Things like webmail clients should definitely do CSR (unless they want to go all in on frames preferably combined with a service worker providing the responses; this honestly is an option, though I’ve never seen it done).

Things like GitHub should be improved by it, and when it was done lightly in the past it was generally improved by it. But it’s been degrading significantly with their new approach to frontend.

The trouble is that far too often it’s not done well, and it’s almost never made robust to bad network conditions, whereas the browser is robust in that way. There are also other details that the browser can do that client-side routing can’t, such as showing that a tab as loading. Also client-side routing gets in the way of some browser optimisations like the bfcache.


Don't roll your own text selection.

Minor exceptions for very specific types of web apps mostly on mobile—some kind of annotation thing where you want to let your finger act as a highlighter; on desktop you’d just use the mouse, but native selection may be too clumsy on mobile.

But other than that, I’d actually go further, and add “never use ::selection”. That feature was just a bad idea, and it’s awful how adding ::selection{} to a page’s stylesheets makes selection invisible. I don’t think any other selector breaks things merely by being mentioned?


Don't roll your own context menu.

Disagree. For various sorts of apps, you definitely want your own context menu items; email client, file manager, even word processor. If the browser provided a way of doing that, it’d be great, but no one else wanted to so Firefox eventually ripped its implementation out, and a fully custom context menu is now your only option, and the pragmatic choice.

Again, context menus that people add are not always appropriate, but there are plenty that are.

In Firefox, Shift+RightClick opens the native context menu forcibly, which is good to still have.


Don't roll your own copy and paste.

I wish for clarification before judging this. I can think of interpretations I would agree with and interpretations I would disagree with.


Don't roll your own password field.

… I honestly can’t remember ever coming across that outside of a technical demo. Well, and ones that add a show/hide button that switches the <input type> from password to text. But I don’t feel that counts.


Don't roll your own date picker.

Disagree. For a couple of reasons, actually. I want to encourage people to use the native one, but it has some distressingly large caveats and we’ve seen very little interest in the last decade in fixing them.

The native control is very limited and inconsistent. You can’t augment the picker with information (which is an extremely common desire). Picking a time long ago (e.g. date of birth) can be abominable on some platforms (e.g. Safari's date-picker is the cause of 1/3 of our customer support issues).

Custom-rolled date pickers tend to be problematic for accessibility, but frequently better for normal people. And a lot of the time you really just can’t use the native control because you need functionality it doesn’t include.

For a simple date picker, I prefer the native one to most of what people will replace it with, because I use a browser where that will let me type in the date, and their replacement may well not. But for a lot of these cases, most people aren’t so well served by the native one, unfortunately.

Definitely a date range will be significantly worse for most people if you use two <input type=date> fields, even if I might actually like it.

Loup-Vaillant

Good points on web forms. Leaning on the browser there is the simplest, fastest, and almost always the most consistent thing to do.

On the cryptography side though… Granted, writing correct cryptographic code isn’t trivial. But it’s not impossible either, and in some circumstances the available options are few enough that writing your own is actually the best you can do.

My problem with the security orthodoxy here is it’s tendency to assert that writing new cryptographic code requires being in their in-group. If you can’t show your PhD in cryptography or your internship with DJB or Dan Boneh, then you shouldn’t be allowed to write cryptographic code. Oh sure it’s okay if it’s "just for learning", but God forbid if you try to apply that new knowledge for real. Some of them even have serious difficulty recognising actual competence from the out-group. (Interestingly, the overlap between the security orthodoxy and actual cryptographers (the ones who write papers), seem to be very small.)

And they’re expanding. Now we should not write anything in memory unsafe languages. 70% of critical vulnerabilities, sure, but what was actually at fault there? I bet most problems happen when using malloc() (or explicit new) for every little object that’s not on the stack, or dealing with null terminated strings. Had we used arenas and slices instead, we’d have much fewer such problems. (I do reckon some high-stakes scenarios require eliminating some classes of bugs altogether. In those cases memory safety is king.)

What’s next, don’t write anything that’s processing untrusted input? Don’t reinvent the wheel, even if the current ones are all square? Though I believe you wouldn’t take much issue with people rolling their own web framework, as long as they avoid JavaScript bloat and use the forms provided by the browser.