3 ms·
>Positional syntaxes are extensible: you can add new optional arguments at the tail end, such that when those are missing, the old behavior is provided. That's
by Arnavion 4y ago
>Positional syntaxes are extensible: you can add new optional arguments at the tail end, such that when those are missing, the old behavior is provided.
That's just one direction of "extensible". You can't remove existing arguments, which you can with named fields.
- kazinator 4y agoYou cannot remove an argument from a function without checking all the code which calls it, to make sure it's not using that argument. Removal isn't extension; so we are no longer on the topic of extensibility. For instance, it wouldn't be considered a compiler/vendor extension if the "for" statement were removed; it would be a (severe) nonconformance. It may be easier to remove a named argument, if that argument is rarely used, because you can look for uses of that argument by name. If the hits are nonexistent to rare, you have very little work. In a public API, where you don't have access to all the code base which uses the function, you may not have any way of evaluating "rarely used" other than polling the user base. Needless to say, a data format for a patch operation is a public API.You don't even control the software which implements an argument to be able to remove it. You can write some blurbs in the spec which declare something to be deprecated, and 20 years later, maybe everyone will have stopped using it and removed support.
- Arnavion 4y agov1.js: /// Every `{ "type": "foo" }` object must have a `bar` field. function foo(obj) { if (obj.type === "foo") { reticulate(obj.bar); } } v2.js: /// Relax requirement that every `{ "type": "foo" }` object must have a `bar` field. function foo(obj) { if (obj.type === "foo" && typeof obj.bar !== "undefined") { reticulate(obj.bar); } }